QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
26 : mTickPosition( position )
33 switch ( mTickPosition )
36 return QStringLiteral(
"Line Ticks Up" );
38 return QStringLiteral(
"Line Ticks Down" );
40 return QStringLiteral(
"Line Ticks Middle" );
47 switch ( mTickPosition )
50 return QObject::tr(
"Line Ticks Up" );
52 return QObject::tr(
"Line Ticks Down" );
54 return QObject::tr(
"Line Ticks Middle" );
62 switch ( mTickPosition )
100 QPainter *painter = context.
painter();
108 const double scaledMaxHeight = ( ( settings.
numberOfSubdivisions() > 1 ) && ( scaledSubdivisionsHeight > scaledHeight ) ) ? scaledSubdivisionsHeight : scaledHeight;
109 const double middlePosition = barTopPosition + scaledMaxHeight / 2.0;
110 const double bottomPosition = barTopPosition + scaledMaxHeight;
117 std::unique_ptr< QgsLineSymbol > symbol( settings.
lineSymbol()->
clone() );
118 symbol->startRender( context );
121 divisionSymbol->startRender( context );
124 subdivisionSymbol->startRender( context );
126 const QList<double> positions =
segmentPositions( context, scaleContext, settings );
129 double verticalPos = 0.0;
130 QList<double> subTickPositionsY;
131 QList<double> tickPositionsY;
132 switch ( mTickPosition )
135 verticalPos = barTopPosition;
136 subTickPositionsY << verticalPos;
137 subTickPositionsY << verticalPos + scaledSubdivisionsHeight;
138 tickPositionsY << verticalPos;
139 tickPositionsY << verticalPos + scaledHeight;
142 verticalPos = middlePosition;
143 subTickPositionsY << verticalPos + scaledSubdivisionsHeight / 2.0;
144 subTickPositionsY << verticalPos - scaledSubdivisionsHeight / 2.0;
145 tickPositionsY << verticalPos + scaledHeight / 2.0;
146 tickPositionsY << verticalPos - scaledHeight / 2.0;
149 verticalPos = bottomPosition;
150 subTickPositionsY << verticalPos;
151 subTickPositionsY << verticalPos - scaledSubdivisionsHeight;
152 tickPositionsY << verticalPos;
153 tickPositionsY << verticalPos - scaledHeight;
157 int symbolLayerCount = symbol->symbolLayerCount();
158 symbolLayerCount = std::max( symbolLayerCount, divisionSymbol->symbolLayerCount() );
159 symbolLayerCount = std::max( symbolLayerCount, subdivisionSymbol->symbolLayerCount() );
162 for (
int layer = 0; layer < symbolLayerCount; ++ layer )
164 const bool drawDivisionsForThisSymbolLayer = layer < divisionSymbol->symbolLayerCount();
165 const bool drawSubdivisionsForThisSymbolLayer = layer < subdivisionSymbol->symbolLayerCount();
166 const bool drawLineForThisSymbolLayer = layer < symbol->symbolLayerCount();
168 if ( drawDivisionsForThisSymbolLayer )
171 for (
int i = 0; i < positions.size(); ++i )
174 divisionSymbol->renderPolyline( QPolygonF() << QPointF( thisX, tickPositionsY.at( 0 ) )
175 << QPointF( thisX, tickPositionsY.at( 1 ) ),
nullptr, context, layer );
180 if ( drawSubdivisionsForThisSymbolLayer )
187 subdivisionSymbol->renderPolyline( QPolygonF() << QPointF( thisSubX, subTickPositionsY.at( 0 ) )
188 << QPointF( thisSubX, subTickPositionsY.at( 1 ) ),
nullptr, context, layer );
194 if ( !positions.isEmpty() )
199 if ( drawDivisionsForThisSymbolLayer )
201 divisionSymbol->renderPolyline( QPolygonF() << QPointF( lastTickPositionX, tickPositionsY.at( 0 ) )
202 << QPointF( lastTickPositionX, tickPositionsY.at( 1 ) ),
203 nullptr, context, layer );
207 if ( drawLineForThisSymbolLayer )
210 << QPointF( lastTickPositionX, verticalPos ),
nullptr, context, layer );
215 symbol->stopRender( context );
216 divisionSymbol->stopRender( context );
217 subdivisionSymbol->stopRender( context );
double height() const
Returns the scalebar height (in millimeters).
@ TicksUp
Render ticks above line.
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
Contains parameters regarding scalebar calculations.
@ FlagUsesUnitLabel
Renderer uses the QgsScaleBarSettings::unitLabel() setting.
Flags flags() const override
Returns the scalebar rendering flags, which dictates the renderer's behavior.
QgsTicksScaleBarRenderer * clone() const override
Returns a clone of the renderer.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
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.
QgsTicksScaleBarRenderer(TickPosition position=TicksMiddle)
Constructor for QgsTicksScaleBarRenderer.
Contains information about the context of a rendering operation.
@ RenderMillimeters
Millimeters.
@ TicksMiddle
Render ticks crossing line.
@ FlagUsesLabelHorizontalPlacement
Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting.
@ TicksDown
Render ticks below line.
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
QString visibleName() const override
Returns the user friendly, translated name for the renderer.
@ FlagUsesLabelVerticalPlacement
Renderer uses the QgsScaleBarSettings::labelVerticalPlacement() setting.
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
LabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
QgsTextFormat & textFormat()
Returns the text format used for drawing text in the scalebar.
@ FlagUsesLineSymbol
Renderer utilizes the scalebar line symbol (see QgsScaleBarSettings::lineSymbol() )
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
@ FlagRespectsMapUnitsPerScaleBarUnit
Renderer respects the QgsScaleBarSettings::mapUnitsPerScaleBarUnit() setting.
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of 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.
TickPosition
Tick positions.
double segmentWidth
The width, in millimeters, of each individual segment drawn.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
@ LabelAboveSegment
Labels are drawn above the scalebar.
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...
@ FlagUsesSubdivisions
Renderer uses the scalebar subdivisions (see QgsScaleBarSettings::numberOfSubdivisions() )
QgsLineSymbol * divisionLineSymbol() const
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
@ FlagRespectsUnits
Renderer respects the QgsScaleBarSettings::units() setting.
QgsLineSymbol * subdivisionLineSymbol() const
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
int numberOfSubdivisions() const
Returns the number of subdivisions for segments included in the right part of the scalebar (only used...
@ FlagUsesSubdivisionsHeight
Renderer uses the scalebar subdivisions height (see QgsScaleBarSettings::subdivisionsHeight() )
A scale bar that draws segments using short ticks.
@ FlagUsesLabelBarSpace
Renderer uses the QgsScaleBarSettings::labelBarSpace() setting.
@ FlagUsesSegments
Renderer uses the scalebar segments.
QPainter * painter()
Returns the destination QPainter for the render operation.
@ FlagUsesDivisionSymbol
Renderer utilizes the scalebar division symbol (see QgsScaleBarSettings::divisionLineSymbol() )
@ FlagUsesSubdivisionSymbol
Renderer utilizes the scalebar subdivision symbol (see QgsScaleBarSettings::subdivisionLineSymbol() )
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.
int sortKey() const override
Returns a sorting key value, where renderers with a lower sort key will be shown earlier in lists.
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.