99 QPainter *painter = context.
painter();
107 const double scaledMaxHeight = ( ( settings.
numberOfSubdivisions() > 1 ) && ( scaledSubdivisionsHeight > scaledHeight ) ) ? scaledSubdivisionsHeight : scaledHeight;
108 const double middlePosition = barTopPosition + scaledMaxHeight / 2.0;
109 const double bottomPosition = barTopPosition + scaledMaxHeight;
116 std::unique_ptr< QgsLineSymbol > symbol( settings.
lineSymbol()->
clone() );
117 symbol->startRender( context );
120 divisionSymbol->startRender( context );
123 subdivisionSymbol->startRender( context );
125 const QList<double> positions =
segmentPositions( context, scaleContext, settings );
128 double verticalPos = 0.0;
129 QList<double> subTickPositionsY;
130 QList<double> tickPositionsY;
131 switch ( mTickPosition )
134 verticalPos = barTopPosition;
135 subTickPositionsY << verticalPos;
136 subTickPositionsY << verticalPos + scaledSubdivisionsHeight;
137 tickPositionsY << verticalPos;
138 tickPositionsY << verticalPos + scaledHeight;
141 verticalPos = middlePosition;
142 subTickPositionsY << verticalPos + scaledSubdivisionsHeight / 2.0;
143 subTickPositionsY << verticalPos - scaledSubdivisionsHeight / 2.0;
144 tickPositionsY << verticalPos + scaledHeight / 2.0;
145 tickPositionsY << verticalPos - scaledHeight / 2.0;
148 verticalPos = bottomPosition;
149 subTickPositionsY << verticalPos;
150 subTickPositionsY << verticalPos - scaledSubdivisionsHeight;
151 tickPositionsY << verticalPos;
152 tickPositionsY << verticalPos - scaledHeight;
156 int symbolLayerCount = symbol->symbolLayerCount();
157 symbolLayerCount = std::max( symbolLayerCount, divisionSymbol->symbolLayerCount() );
158 symbolLayerCount = std::max( symbolLayerCount, subdivisionSymbol->symbolLayerCount() );
161 for (
int layer = 0; layer < symbolLayerCount; ++ layer )
163 const bool drawDivisionsForThisSymbolLayer = layer < divisionSymbol->symbolLayerCount();
164 const bool drawSubdivisionsForThisSymbolLayer = layer < subdivisionSymbol->symbolLayerCount();
165 const bool drawLineForThisSymbolLayer = layer < symbol->symbolLayerCount();
167 if ( drawDivisionsForThisSymbolLayer )
170 for (
int i = 0; i < positions.size(); ++i )
173 divisionSymbol->renderPolyline( QPolygonF() << QPointF( thisX, tickPositionsY.at( 0 ) )
174 << QPointF( thisX, tickPositionsY.at( 1 ) ),
nullptr, context, layer );
179 if ( drawSubdivisionsForThisSymbolLayer )
186 subdivisionSymbol->renderPolyline( QPolygonF() << QPointF( thisSubX, subTickPositionsY.at( 0 ) )
187 << QPointF( thisSubX, subTickPositionsY.at( 1 ) ),
nullptr, context, layer );
193 if ( !positions.isEmpty() )
198 if ( drawDivisionsForThisSymbolLayer )
200 divisionSymbol->renderPolyline( QPolygonF() << QPointF( lastTickPositionX, tickPositionsY.at( 0 ) )
201 << QPointF( lastTickPositionX, tickPositionsY.at( 1 ) ),
202 nullptr, context, layer );
206 if ( drawLineForThisSymbolLayer )
209 << QPointF( lastTickPositionX, verticalPos ),
nullptr, context, layer );
214 symbol->stopRender( context );
215 divisionSymbol->stopRender( context );
216 subdivisionSymbol->stopRender( context );
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
static QFontMetricsF fontMetrics(QgsRenderContext &context, const QgsTextFormat &format, double scaleFactor=1.0)
Returns the font metrics for the given text format, when rendered in the specified render context.
Contains parameters regarding scalebar calculations.
double segmentWidth
The width, in millimeters, of each individual segment drawn.