QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskTickmarks.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskTickmarks.h"
7#include <algorithm>
8
9static void qskRegisterTickmarks()
10{
11 qRegisterMetaType< QskTickmarks >();
12
13#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
14 QMetaType::registerEqualsComparator< QskTickmarks >();
15#endif
16}
17
18Q_CONSTRUCTOR_FUNCTION( qskRegisterTickmarks )
19
20QskTickmarks::QskTickmarks()
21{
22}
23
24QskTickmarks::QskTickmarks( const QVector< qreal >& minorTicks,
25 const QVector< qreal >& mediumTicks, const QVector< qreal >& majorTicks )
26 : m_ticks{ minorTicks, mediumTicks, majorTicks }
27{
28}
29
30QskTickmarks::~QskTickmarks()
31{
32}
33
34int QskTickmarks::tickCount() const noexcept
35{
36 const auto count = m_ticks[ MajorTick ].count()
37 + m_ticks[ MediumTick ].count()
38 + m_ticks[ MinorTick ].count();
39
40 return static_cast< int >( count );
41}
42
43
44int QskTickmarks::tickCount( TickType type ) const noexcept
45{
46 return static_cast< int >( m_ticks[ type ].count() );
47}
48
49QVector< qreal > QskTickmarks::ticks( TickType type ) const noexcept
50{
51 return m_ticks[ type ];
52}
53
54void QskTickmarks::setTicks(TickType type, const QVector< qreal >& ticks )
55{
56 m_ticks[ type ] = ticks;
57}
58
59qreal QskTickmarks::tickAt( TickType type, int index ) const
60{
61 return m_ticks[ type ].at( index );
62}
63
64void QskTickmarks::reset()
65{
66 m_ticks[ 0 ].clear();
67 m_ticks[ 1 ].clear();
68 m_ticks[ 2 ].clear();
69}
70
71void QskTickmarks::invert()
72{
73 std::reverse( m_ticks[ 0 ].begin(), m_ticks[ 0 ].end() );
74 std::reverse( m_ticks[ 1 ].begin(), m_ticks[ 1 ].end() );
75 std::reverse( m_ticks[ 2 ].begin(), m_ticks[ 2 ].end() );
76}
77
78QskHashValue QskTickmarks::hash( QskHashValue seed ) const noexcept
79{
80 seed = qHash( m_ticks[0], seed );
81 seed = qHash( m_ticks[1], seed );
82 seed = qHash( m_ticks[2], seed );
83
84 return seed;
85}
86
87bool QskTickmarks::operator==( const QskTickmarks& other ) const noexcept
88{
89 return ( m_ticks[ 0 ] == other.m_ticks[ 0 ] )
90 && ( m_ticks[ 1 ] == other.m_ticks[ 1 ] )
91 && ( m_ticks[ 2 ] == other.m_ticks[ 2 ] );
92}
93
94#ifndef QT_NO_DEBUG_STREAM
95
96#include <qdebug.h>
97
98QDebug operator<<( QDebug debug, const QskTickmarks& tickmarks )
99{
100 debug << tickmarks.majorTicks()
101 << tickmarks.mediumTicks() << tickmarks.minorTicks();
102
103 return debug;
104}
105
106#endif
107
108#include "moc_QskTickmarks.cpp"