QgsScaleBarRenderer class

Abstract base class for scale bar renderers.

Scalebar renderer subclasses implement custom drawing logic, with the possibility to implement custom labeling.

Derived classes

class QgsDoubleBoxScaleBarRenderer
Double box with alternating colors.
class QgsNumericScaleBarRenderer
A scale bar style that draws text in the form of '1:XXXXX'.
class QgsSingleBoxScaleBarRenderer
Scalebar style that draws a single box with alternating color for the segments.
class QgsTicksScaleBarRenderer
A scale bar that draws segments using short ticks.

Public types

struct ScaleBarContext
Contains parameters regarding scalebar calculations.

Constructors, destructors, conversion operators

QgsScaleBarRenderer() defaulted
Constructor for QgsScaleBarRenderer.

Public functions

auto calculateBoxSize(const QgsScaleBarSettings& settings, const QgsScaleBarRenderer::ScaleBarContext& scaleContext) const -> QSizeF virtual
Calculates the required box size (in millimeters) for a scalebar using the specified settings and scaleContext.
void draw(QgsRenderContext& context, const QgsScaleBarSettings& settings, const QgsScaleBarRenderer::ScaleBarContext& scaleContext) const pure virtual
Draws the scalebar using the specified settings and scaleContext to a destination render context.
auto name() const -> QString pure virtual
Returns the unique name for this style.

Protected functions

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 context.
auto firstLabelString(const QgsScaleBarSettings& settings) const -> QString
Returns the text used for the first label in the scalebar.
auto firstLabelXOffset(const QgsScaleBarSettings& settings) const -> Q_DECL_DEPRECATED double deprecated
Returns the x-offset (in millimeters) used for the first label in the scalebar.
auto firstLabelXOffset(const QgsScaleBarSettings& settings, const QgsRenderContext& context) const -> double
Returns the x-offset (in render context painter units) used for the first label in the scalebar.
auto segmentPositions(const QgsScaleBarRenderer::ScaleBarContext& scaleContext, const QgsScaleBarSettings& settings) const -> QList<double>
Returns a list of positions for each segment within the scalebar.
auto segmentWidths(const QgsScaleBarRenderer::ScaleBarContext& scaleContext, const QgsScaleBarSettings& settings) const -> QList<double>
Returns a list of widths of each segment of the scalebar.

Function documentation

Q_DECL_DEPRECATED double QgsScaleBarRenderer::firstLabelXOffset(const QgsScaleBarSettings& settings) const protected

Returns the x-offset (in millimeters) used for the first label in the scalebar.

double QgsScaleBarRenderer::firstLabelXOffset(const QgsScaleBarSettings& settings, const QgsRenderContext& context) const protected

Returns the x-offset (in render context painter units) used for the first label in the scalebar.