qskinny/src/common/QskTickmarks.cpp

109 lines
2.5 KiB
C++
Raw Normal View History

2020-11-13 14:34:02 +00:00
/******************************************************************************
2024-01-17 13:31:45 +00:00
* QSkinny - Copyright (C) The authors
2023-04-06 07:23:37 +00:00
* SPDX-License-Identifier: BSD-3-Clause
2020-11-13 14:34:02 +00:00
*****************************************************************************/
2023-11-28 09:46:03 +00:00
#include "QskTickmarks.h"
2020-11-13 14:34:02 +00:00
#include <algorithm>
2021-02-14 11:36:15 +00:00
static void qskRegisterTickmarks()
2020-11-13 14:34:02 +00:00
{
2023-11-28 09:46:03 +00:00
qRegisterMetaType< QskTickmarks >();
2022-03-30 16:30:22 +00:00
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
2023-11-28 09:46:03 +00:00
QMetaType::registerEqualsComparator< QskTickmarks >();
2022-03-30 16:30:22 +00:00
#endif
2020-11-13 14:34:02 +00:00
}
2021-02-14 11:36:15 +00:00
Q_CONSTRUCTOR_FUNCTION( qskRegisterTickmarks )
2023-11-28 09:46:03 +00:00
QskTickmarks::QskTickmarks()
2020-11-13 14:34:02 +00:00
{
}
2023-11-28 12:07:21 +00:00
QskTickmarks::QskTickmarks( const QVector< qreal >& minorTicks,
const QVector< qreal >& mediumTicks, const QVector< qreal >& majorTicks )
: m_ticks{ minorTicks, mediumTicks, majorTicks }
{
}
2023-11-28 09:46:03 +00:00
QskTickmarks::~QskTickmarks()
2020-11-13 14:34:02 +00:00
{
}
2023-11-28 09:46:03 +00:00
int QskTickmarks::tickCount() const noexcept
2021-02-14 11:36:15 +00:00
{
2023-04-04 07:05:16 +00:00
const auto count = m_ticks[ MajorTick ].count()
2021-02-14 11:36:15 +00:00
+ m_ticks[ MediumTick ].count()
+ m_ticks[ MinorTick ].count();
2023-04-04 07:05:16 +00:00
return static_cast< int >( count );
2021-02-14 11:36:15 +00:00
}
2023-11-28 09:46:03 +00:00
int QskTickmarks::tickCount( TickType type ) const noexcept
2020-11-13 14:34:02 +00:00
{
2023-04-04 07:05:16 +00:00
return static_cast< int >( m_ticks[ type ].count() );
2020-11-13 14:34:02 +00:00
}
2023-11-28 09:46:03 +00:00
QVector< qreal > QskTickmarks::ticks( TickType type ) const noexcept
2020-11-13 14:34:02 +00:00
{
return m_ticks[ type ];
}
2023-11-28 09:46:03 +00:00
void QskTickmarks::setTicks(TickType type, const QVector< qreal >& ticks )
2020-11-13 14:34:02 +00:00
{
m_ticks[ type ] = ticks;
}
2023-11-28 09:46:03 +00:00
qreal QskTickmarks::tickAt( TickType type, int index ) const
{
return m_ticks[ type ].at( index );
}
2023-11-28 09:46:03 +00:00
void QskTickmarks::reset()
2020-11-13 14:34:02 +00:00
{
m_ticks[ 0 ].clear();
m_ticks[ 1 ].clear();
m_ticks[ 2 ].clear();
}
2023-11-28 09:46:03 +00:00
void QskTickmarks::invert()
2020-12-05 14:09:31 +00:00
{
2020-11-13 14:34:02 +00:00
std::reverse( m_ticks[ 0 ].begin(), m_ticks[ 0 ].end() );
std::reverse( m_ticks[ 1 ].begin(), m_ticks[ 1 ].end() );
std::reverse( m_ticks[ 2 ].begin(), m_ticks[ 2 ].end() );
}
2023-11-28 09:46:03 +00:00
QskHashValue QskTickmarks::hash( QskHashValue seed ) const noexcept
2020-11-13 14:34:02 +00:00
{
seed = qHash( m_ticks[0], seed );
seed = qHash( m_ticks[1], seed );
seed = qHash( m_ticks[2], seed );
return seed;
}
2023-11-28 09:46:03 +00:00
bool QskTickmarks::operator==( const QskTickmarks& other ) const noexcept
2020-11-13 14:34:02 +00:00
{
return ( m_ticks[ 0 ] == other.m_ticks[ 0 ] )
&& ( m_ticks[ 1 ] == other.m_ticks[ 1 ] )
&& ( m_ticks[ 2 ] == other.m_ticks[ 2 ] );
}
2021-02-14 11:36:15 +00:00
#ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h>
2023-11-28 09:46:03 +00:00
QDebug operator<<( QDebug debug, const QskTickmarks& tickmarks )
2021-02-14 11:36:15 +00:00
{
debug << tickmarks.majorTicks()
<< tickmarks.mediumTicks() << tickmarks.minorTicks();
return debug;
}
#endif
2023-11-28 09:46:03 +00:00
#include "moc_QskTickmarks.cpp"