29 QPainter *painter = context.
painter();
34 double barTopPosition = fontMetrics.ascent() + scaledLabelBarSpace + scaledBoxContentSpace;
39 painter->setRenderHint( QPainter::Antialiasing,
true );
41 QPen pen = settings.
pen();
43 painter->setPen( pen );
50 QList<double> widths =
segmentWidths( scaleContext, settings );
52 for (
int i = 0; i < positions.size(); ++i )
57 painter->setBrush( settings.
brush() );
61 painter->setBrush( settings.
brush2() );
67 painter->drawRect( segmentRectTop );
73 painter->setBrush( settings.
brush2() );
77 painter->setBrush( settings.
brush() );
81 barTopPosition + segmentHeight,
83 painter->drawRect( segmentRectBottom );
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
Use antialiasing while drawing.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QList< double > segmentPositions(const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings) const
Returns a list of positions for each segment within the scalebar.
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...
static QFontMetricsF fontMetrics(QgsRenderContext &context, const QgsTextFormat &format)
Returns the font metrics for the given text format, when rendered in the specified render context...
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. ...
Contains information about the context of a rendering operation.
double height() const
Returns the scalebar height (in millimeters).
QPainter * painter()
Returns the destination QPainter for the render operation.
QBrush brush() const
Returns the primary brush used for filling the scalebar.
QBrush brush2() const
Returns the secondary brush for the scalebar.
QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
Flags flags() const
Returns combination of flags used for rendering.
Q_DECL_DEPRECATED double firstLabelXOffset(const QgsScaleBarSettings &settings) const
Returns the x-offset (in millimeters) used for the first label in 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...
QList< double > segmentWidths(const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings) const
Returns a list of widths of each segment of the scalebar.
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
Contains parameters regarding scalebar calculations.