6#include "QskGraduationNode.h"
7#include "QskTickmarks.h"
8#include "QskIntervalF.h"
9#include "QskGraduationMetrics.h"
15 using Points = QSGGeometry::Point2D;
20 inline Renderer(
bool isHorizontal )
21 : m_isHorizontal( isHorizontal )
25 inline Points* addBackbone( Points* points,
26 qreal pos, qreal v1, qreal v2 )
const
29 setLine( points, v1, pos, v2, pos );
31 setLine( points, pos, v1, pos, v2 );
36 inline Points* addTickLine( Points* points,
37 qreal pos, qreal tick, qreal tickLength )
const
40 setLine( points, tick, pos, tick, pos + tickLength );
42 setLine( points, pos, tick, pos + tickLength, tick );
49 inline void setLine( Points* points,
50 qreal x1, qreal y1, qreal x2, qreal y2 )
const
52 points[ 0 ].set( x1, y1 );
53 points[ 1 ].set( x2, y2 );
56 const bool m_isHorizontal;
60class QskGraduationNode::PrivateData
63 inline qreal map( qreal v )
const
66 return transform.dx() + transform.m11() * v;
68 return transform.dy() + transform.m22() * v;
71 inline qreal origin( qreal length )
const
75 case QskGraduationNode::Leading:
78 case QskGraduationNode::Centered:
79 return pos - 0.5 * length;
86 bool isHorizontal =
true;
92 QskGraduationNode::Alignment alignment = QskGraduationNode::Centered;
95 QskHashValue hash = 0;
100QskGraduationNode::QskGraduationNode()
101 : m_data( new PrivateData() )
105QskGraduationNode::~QskGraduationNode()
109void QskGraduationNode::setAxis( Qt::Orientation orientation,
110 qreal pos,
const QTransform& transform )
112 const bool isHorizontal = ( orientation == Qt::Horizontal );
114 if( isHorizontal != m_data->isHorizontal
115 || pos != m_data->pos || transform != m_data->transform )
117 m_data->isHorizontal = isHorizontal;
119 m_data->transform = transform;
121 m_data->dirty =
true;
125void QskGraduationNode::setTickMetrics(
129 if( metrics != m_data->graduationMetrics || alignment != m_data->alignment )
131 setLineWidth( metrics.tickWidth() );
133 m_data->graduationMetrics = metrics;
134 m_data->alignment = alignment;
136 m_data->dirty =
true;
140void QskGraduationNode::update(
const QskTickmarks& tickmarks,
143 const auto hash = tickmarks.hash( 17435 );
144 if ( m_data->hash != hash || m_data->backbone != backbone )
147 m_data->backbone = backbone;
148 m_data->dirty =
true;
154 QSGGeometry::Point2D* points;
157 auto lineCount = tickmarks.tickCount();
158 if ( !backbone.isEmpty() )
161 geometry()->allocate( lineCount * 2 );
162 points = geometry()->vertexDataAsPoint2D();
165 const Renderer renderer( m_data->isHorizontal );
167 if ( !m_data->backbone.isEmpty() )
169 const auto v1 = m_data->map( backbone.lowerBound() );
170 const auto v2 = m_data->map( backbone.upperBound() );
172 points = renderer.addBackbone( points, m_data->pos, v1, v2 );
175 for(
int i = QskTickmarks::MinorTick;
176 i <= QskTickmarks::MajorTick; i++ )
178 const auto tickType =
static_cast< QskTickmarks::TickType
>( i );
180 const auto len = m_data->graduationMetrics.tickLength( tickType );
181 const auto origin = m_data->origin( len );
183 const auto ticks = tickmarks.ticks( tickType );
184 for(
auto tick : ticks )
186 tick = m_data->map( tick );
187 points = renderer.addTickLine( points, origin, tick, len );
191 geometry()->markVertexDataDirty();
192 markDirty( QSGNode::DirtyGeometry );
193 m_data->dirty =
false;