6#ifndef QSK_GRADUATION_METRICS_H
7#define QSK_GRADUATION_METRICS_H
9#include "QskTickmarks.h"
10#include "QskFunctions.h"
17 Q_PROPERTY( qreal majorTickLength READ majorTickLength WRITE setMajorTickLength )
18 Q_PROPERTY( qreal mediumTickLength READ mediumTickLength WRITE setMediumTickLength )
19 Q_PROPERTY( qreal minorTickLength READ minorTickLength WRITE setMinorTickLength )
20 Q_PROPERTY( qreal tickWidth READ tickWidth WRITE setTickWidth )
23 using TickType = QskTickmarks::TickType;
28 qreal mediumTickLength, qreal majorTickLength,
29 qreal tickWidth = 1.0 )
noexcept;
34 constexpr void setTickWidth( qreal )
noexcept;
35 [[nodiscard]]
constexpr qreal tickWidth()
const noexcept;
37 constexpr void setTickLength( TickType, qreal )
noexcept;
38 [[nodiscard]]
constexpr qreal tickLength( TickType )
const noexcept;
40 constexpr void setMinorTickLength( qreal )
noexcept;
41 [[nodiscard]]
constexpr qreal minorTickLength()
const noexcept;
43 constexpr void setMediumTickLength( qreal )
noexcept;
44 [[nodiscard]]
constexpr qreal mediumTickLength()
const noexcept;
46 constexpr void setMajorTickLength( qreal )
noexcept;
47 [[nodiscard]]
constexpr qreal majorTickLength()
const noexcept;
52 [[nodiscard]]
static QVariant interpolate(
55 [[nodiscard]] QskHashValue hash( QskHashValue seed = 0 )
const noexcept;
57 [[nodiscard]]
constexpr qreal maxLength()
const noexcept;
60 static inline constexpr qreal validated( qreal value )
62 return std::max( 0.0, value );
65 qreal m_tickLengths[3] = {};
66 qreal m_tickWidth = 1.0;
69inline constexpr QskGraduationMetrics::QskGraduationMetrics(
70 qreal minorTickLength, qreal mediumTickLength, qreal majorTickLength,
71 qreal tickWidth ) noexcept
72 : m_tickLengths{ validated( minorTickLength ),
73 validated( mediumTickLength ), validated( majorTickLength ) }
74 , m_tickWidth( tickWidth )
78inline constexpr void QskGraduationMetrics::setMajorTickLength( qreal length )
noexcept
80 setTickLength( QskTickmarks::MajorTick, length );
83inline constexpr qreal QskGraduationMetrics::majorTickLength() const noexcept
85 return tickLength( QskTickmarks::MajorTick );
88inline constexpr void QskGraduationMetrics::setMediumTickLength( qreal length )
noexcept
90 setTickLength( QskTickmarks::MediumTick, length );
93inline constexpr qreal QskGraduationMetrics::mediumTickLength() const noexcept
95 return tickLength( QskTickmarks::MediumTick );
98inline constexpr void QskGraduationMetrics::setMinorTickLength( qreal length )
noexcept
100 setTickLength( QskTickmarks::MinorTick, length );
103inline constexpr qreal QskGraduationMetrics::minorTickLength() const noexcept
105 return tickLength( QskTickmarks::MinorTick );
108inline constexpr bool QskGraduationMetrics::operator==(
111 return qskFuzzyCompare( m_tickLengths[0], other.m_tickLengths[0] ) &&
112 qskFuzzyCompare( m_tickLengths[1], other.m_tickLengths[1] ) &&
113 qskFuzzyCompare( m_tickLengths[2], other.m_tickLengths[2] &&
114 qskFuzzyCompare( m_tickWidth, other.m_tickWidth ) );
117inline constexpr bool QskGraduationMetrics::operator!=(
120 return !( *
this == rhs );
123inline constexpr void QskGraduationMetrics::setTickWidth( qreal width )
noexcept
125 m_tickWidth = validated( width );
128inline constexpr qreal QskGraduationMetrics::tickWidth() const noexcept
133inline constexpr void QskGraduationMetrics::setTickLength(
134 TickType type, qreal length )
noexcept
136 m_tickLengths[ type ] = validated( length );
139inline constexpr qreal QskGraduationMetrics::tickLength(
140 const QskTickmarks::TickType type )
const noexcept
142 return m_tickLengths[ type ];
145inline constexpr qreal QskGraduationMetrics::maxLength() const noexcept
148 return max( max( m_tickLengths[0], m_tickLengths[1] ), m_tickLengths[2] );
151inline QskHashValue QskGraduationMetrics::hash(
const QskHashValue seed )
const noexcept
153 auto hash = qHash( m_tickLengths[0], seed );
154 hash = qHash( m_tickLengths[1], hash );
155 hash = qHash( m_tickLengths[2], hash );
156 hash = qHash( m_tickWidth, hash );
160#ifndef QT_NO_DEBUG_STREAM