27using namespace Qt::StringLiterals;
30 : mTickPosition( position )
35 switch ( mTickPosition )
38 return u
"Line Ticks Up"_s;
40 return u
"Line Ticks Down"_s;
42 return u
"Line Ticks Middle"_s;
49 switch ( mTickPosition )
52 return QObject::tr(
"Line Ticks Up" );
54 return QObject::tr(
"Line Ticks Down" );
56 return QObject::tr(
"Line Ticks Middle" );
63 switch ( mTickPosition )
101 QPainter *painter = context.
painter();
106 const double barTopPosition = scaledBoxContentSpace
110 const double scaledMaxHeight = ( ( settings.
numberOfSubdivisions() > 1 ) && ( scaledSubdivisionsHeight > scaledHeight ) ) ? scaledSubdivisionsHeight : scaledHeight;
111 const double middlePosition = barTopPosition + scaledMaxHeight / 2.0;
112 const double bottomPosition = barTopPosition + scaledMaxHeight;
119 std::unique_ptr< QgsLineSymbol > symbol( settings.
lineSymbol()->
clone() );
120 symbol->startRender( context );
123 divisionSymbol->startRender( context );
126 subdivisionSymbol->startRender( context );
128 const QList<double> positions =
segmentPositions( context, scaleContext, settings );
131 double verticalPos = 0.0;
132 QList<double> subTickPositionsY;
133 QList<double> tickPositionsY;
134 switch ( mTickPosition )
137 verticalPos = barTopPosition;
138 subTickPositionsY << verticalPos;
139 subTickPositionsY << verticalPos + scaledSubdivisionsHeight;
140 tickPositionsY << verticalPos;
141 tickPositionsY << verticalPos + scaledHeight;
144 verticalPos = middlePosition;
145 subTickPositionsY << verticalPos + scaledSubdivisionsHeight / 2.0;
146 subTickPositionsY << verticalPos - scaledSubdivisionsHeight / 2.0;
147 tickPositionsY << verticalPos + scaledHeight / 2.0;
148 tickPositionsY << verticalPos - scaledHeight / 2.0;
151 verticalPos = bottomPosition;
152 subTickPositionsY << verticalPos;
153 subTickPositionsY << verticalPos - scaledSubdivisionsHeight;
154 tickPositionsY << verticalPos;
155 tickPositionsY << verticalPos - scaledHeight;
159 int symbolLayerCount = symbol->symbolLayerCount();
160 symbolLayerCount = std::max( symbolLayerCount, divisionSymbol->symbolLayerCount() );
161 symbolLayerCount = std::max( symbolLayerCount, subdivisionSymbol->symbolLayerCount() );
164 for (
int layer = 0; layer < symbolLayerCount; ++layer )
166 const bool drawDivisionsForThisSymbolLayer = layer < divisionSymbol->symbolLayerCount();
167 const bool drawSubdivisionsForThisSymbolLayer = layer < subdivisionSymbol->symbolLayerCount();
168 const bool drawLineForThisSymbolLayer = layer < symbol->symbolLayerCount();
170 if ( drawDivisionsForThisSymbolLayer )
173 for (
int i = 0; i < positions.size(); ++i )
176 divisionSymbol->renderPolyline( QPolygonF() << QPointF( thisX, tickPositionsY.at( 0 ) ) << QPointF( thisX, tickPositionsY.at( 1 ) ),
nullptr, context, layer );
181 if ( drawSubdivisionsForThisSymbolLayer )
188 subdivisionSymbol->renderPolyline( QPolygonF() << QPointF( thisSubX, subTickPositionsY.at( 0 ) ) << QPointF( thisSubX, subTickPositionsY.at( 1 ) ),
nullptr, context, layer );
194 if ( !positions.isEmpty() )
199 if ( drawDivisionsForThisSymbolLayer )
201 divisionSymbol->renderPolyline( QPolygonF() << QPointF( lastTickPositionX, tickPositionsY.at( 0 ) ) << QPointF( lastTickPositionX, tickPositionsY.at( 1 ) ),
nullptr, context, layer );
205 if ( drawLineForThisSymbolLayer )
212 symbol->stopRender( context );
213 divisionSymbol->stopRender( context );
214 subdivisionSymbol->stopRender( context );
@ AboveSegment
Labels are drawn above the scalebar.
@ Millimeters
Millimeters.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
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 ...
void drawDefaultLabels(QgsRenderContext &context, const QgsScaleBarSettings &settings, const QgsScaleBarRenderer::ScaleBarContext &scaleContext) const
Draws default scalebar labels using the specified settings and scaleContext to a destination render c...
Q_DECL_DEPRECATED QList< double > segmentPositions(const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings) const
Returns a list of positions for each segment within the scalebar.
Q_DECL_DEPRECATED double firstLabelXOffset(const QgsScaleBarSettings &settings) const
Returns the x-offset (in millimeters) used for the first label in the scalebar.
@ FlagUsesLabelVerticalPlacement
Renderer uses the QgsScaleBarSettings::labelVerticalPlacement() setting.
@ FlagUsesLabelHorizontalPlacement
Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting.
@ FlagUsesLineSymbol
Renderer utilizes the scalebar line symbol (see QgsScaleBarSettings::lineSymbol() ).
@ FlagUsesUnitLabel
Renderer uses the QgsScaleBarSettings::unitLabel() setting.
@ FlagUsesSubdivisionsHeight
Renderer uses the scalebar subdivisions height (see QgsScaleBarSettings::subdivisionsHeight() ).
@ FlagUsesSubdivisionSymbol
Renderer utilizes the scalebar subdivision symbol (see QgsScaleBarSettings::subdivisionLineSymbol() )...
@ FlagUsesSegments
Renderer uses the scalebar segments.
@ FlagUsesLabelBarSpace
Renderer uses the QgsScaleBarSettings::labelBarSpace() setting.
@ FlagRespectsMapUnitsPerScaleBarUnit
Renderer respects the QgsScaleBarSettings::mapUnitsPerScaleBarUnit() setting.
@ FlagRespectsUnits
Renderer respects the QgsScaleBarSettings::units() setting.
@ FlagUsesSubdivisions
Renderer uses the scalebar subdivisions (see QgsScaleBarSettings::numberOfSubdivisions() ).
@ FlagUsesDivisionSymbol
Renderer utilizes the scalebar division symbol (see QgsScaleBarSettings::divisionLineSymbol() ).
Stores the appearance and layout settings for scalebar drawing with QgsScaleBarRenderer.
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
QgsLineSymbol * subdivisionLineSymbol() const
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Qgis::ScaleBarDistanceLabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
QgsTextFormat & textFormat()
Returns the text format used for drawing text in the scalebar.
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
int numberOfSubdivisions() const
Returns the number of subdivisions for segments included in the right part of the scalebar (only used...
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
double height() const
Returns the scalebar height (in millimeters).
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
QgsLineSymbol * divisionLineSymbol() const
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
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.
TickPosition
Tick positions.
@ TicksUp
Render ticks above line.
@ TicksMiddle
Render ticks crossing line.
@ TicksDown
Render ticks below line.
Flags flags() const override
Returns the scalebar rendering flags, which dictates the renderer's behavior.
QString visibleName() const override
Returns the user friendly, translated name for the renderer.
int sortKey() const override
Returns a sorting key value, where renderers with a lower sort key will be shown earlier in lists.
QgsTicksScaleBarRenderer(TickPosition position=TicksMiddle)
Constructor for QgsTicksScaleBarRenderer.
void draw(QgsRenderContext &context, const QgsScaleBarSettings &settings, const QgsScaleBarRenderer::ScaleBarContext &scaleContext) const override
Draws the scalebar using the specified settings and scaleContext to a destination render context.
QString id() const override
Returns the unique ID for this renderer.
QgsTicksScaleBarRenderer * clone() const override
Returns a clone of the renderer.
Contains parameters regarding scalebar calculations.
double segmentWidth
The width, in millimeters, of each individual segment drawn.