QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsscalebarrenderer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsscalebarrenderer.h
3 ---------------------
4 begin : June 2008
5 copyright : (C) 2008 by Marco Hugentobler
7 ***************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGSSCALEBARRENDERER_H
18#define QGSSCALEBARRENDERER_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QList>
24#include <QRectF>
25
28
38class CORE_EXPORT QgsScaleBarRenderer
39{
40 public:
41
46 enum class Flag : int SIP_ENUM_BASETYPE( IntFlag )
47 {
48 FlagUsesLineSymbol = 1 << 0,
49 FlagUsesFillSymbol = 1 << 1,
50 FlagUsesAlternateFillSymbol = 1 << 2,
51 FlagRespectsUnits = 1 << 3,
52 FlagRespectsMapUnitsPerScaleBarUnit = 1 << 4,
53 FlagUsesUnitLabel = 1 << 5,
54 FlagUsesSegments = 1 << 6,
55 FlagUsesLabelBarSpace = 1 << 7,
56 FlagUsesLabelVerticalPlacement = 1 << 8,
57 FlagUsesLabelHorizontalPlacement = 1 << 8,
58 FlagUsesAlignment = 1 << 9,
59 FlagUsesSubdivisions = 1 << 10,
60 FlagUsesDivisionSymbol = 1 << 11,
61 FlagUsesSubdivisionSymbol = 1 << 12,
62 FlagUsesSubdivisionsHeight = 1 << 13,
63 };
64 Q_DECLARE_FLAGS( Flags, Flag )
65
66
70 struct CORE_EXPORT ScaleBarContext
71 {
72
77 double segmentWidth { 0.0 };
78
84 QSizeF size;
85
87 double scale { 1.0 };
88
91
97 bool isValid() const;
98
99 };
100
102 virtual ~QgsScaleBarRenderer() = default;
103
108 Q_DECL_DEPRECATED QString name() const SIP_DEPRECATED { return id(); }
109
114 virtual QString id() const = 0;
115
120 virtual QString visibleName() const = 0;
121
127 virtual Flags flags() const;
128
134 virtual int sortKey() const;
135
140
144 virtual void draw( QgsRenderContext &context,
145 const QgsScaleBarSettings &settings,
146 const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const = 0;
147
152 Q_DECL_DEPRECATED virtual QSizeF calculateBoxSize( const QgsScaleBarSettings &settings,
153 const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const SIP_DEPRECATED;
154
160 virtual QSizeF calculateBoxSize( QgsRenderContext &context,
161 const QgsScaleBarSettings &settings,
162 const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;
163
171 virtual bool applyDefaultSettings( QgsScaleBarSettings &settings ) const;
172
173 protected:
174
178 void drawDefaultLabels( QgsRenderContext &context,
179 const QgsScaleBarSettings &settings,
180 const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;
181
185 QString firstLabelString( const QgsScaleBarSettings &settings ) const;
186
191 Q_DECL_DEPRECATED double firstLabelXOffset( const QgsScaleBarSettings &settings ) const SIP_DEPRECATED;
192
197 double firstLabelXOffset( const QgsScaleBarSettings &settings, const QgsRenderContext &context, const ScaleBarContext &scaleContext ) const;
198
203 Q_DECL_DEPRECATED QList<double> segmentPositions( const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const SIP_DEPRECATED;
204
209 QList<double> segmentPositions( QgsRenderContext &context, const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const;
210
214 QList<double> segmentWidths( const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const;
215
216};
217
219
220#endif //QGSSCALEBARRENDERER_H
Contains information about the context of a rendering operation.
virtual void draw(QgsRenderContext &context, const QgsScaleBarSettings &settings, const QgsScaleBarRenderer::ScaleBarContext &scaleContext) const =0
Draws the scalebar using the specified settings and scaleContext to a destination render context.
virtual Flags flags() const
Returns the scalebar rendering flags, which dictates the renderer's behavior.
Q_DECL_DEPRECATED QString name() const
Returns the unique name for this style.
virtual ~QgsScaleBarRenderer()=default
virtual bool applyDefaultSettings(QgsScaleBarSettings &settings) const
Applies any default settings relating to the scalebar to the passed settings object.
virtual int sortKey() const
Returns a sorting key value, where renderers with a lower sort key will be shown earlier in lists.
virtual QString visibleName() const =0
Returns the user friendly, translated name for the renderer.
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...
virtual Q_DECL_DEPRECATED QSizeF calculateBoxSize(const QgsScaleBarSettings &settings, const QgsScaleBarRenderer::ScaleBarContext &scaleContext) const
Calculates the required box size (in millimeters) for a scalebar using the specified settings and sca...
QString firstLabelString(const QgsScaleBarSettings &settings) const
Returns the text used for the first label in the scalebar.
QgsScaleBarRenderer()=default
QList< double > segmentWidths(const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings) const
Returns a list of widths of each segment of the scalebar.
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.
virtual QgsScaleBarRenderer * clone() const =0
Returns a clone of the renderer.
Q_DECL_DEPRECATED double firstLabelXOffset(const QgsScaleBarSettings &settings) const
Returns the x-offset (in millimeters) used for the first label in the scalebar.
Flag
Flags which control scalebar renderer behavior.
virtual QString id() const =0
Returns the unique ID for this renderer.
Stores the appearance and layout settings for scalebar drawing with QgsScaleBarRenderer.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_FACTORY
Definition qgis_sip.h:84
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)
Contains parameters regarding scalebar calculations.
QSizeF size
Destination size for scalebar.
bool isValid() const
Returns true if the context has valid settings.
QgsScaleBarRenderer::Flags flags
Scalebar renderer flags.
double segmentWidth
The width, in millimeters, of each individual segment drawn.