QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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
6  email : [email protected]
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 #include <QRectF>
23 #include <QList>
24 
25 class QgsRenderContext;
27 
38 class CORE_EXPORT QgsScaleBarRenderer
39 {
40  public:
41 
46  enum class Flag
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 
71  {
72 
77  double segmentWidth { 0.0 };
78 
84  QSizeF size;
85 
87  double scale { 1.0 };
88 
90  Flags flags;
91 
92  };
93 
97  QgsScaleBarRenderer() = default;
98  virtual ~QgsScaleBarRenderer() = default;
99 
104  Q_DECL_DEPRECATED QString name() const SIP_DEPRECATED { return id(); }
105 
110  virtual QString id() const = 0;
111 
116  virtual QString visibleName() const = 0;
117 
123  virtual Flags flags() const;
124 
130  virtual int sortKey() const;
131 
135  virtual QgsScaleBarRenderer *clone() const = 0 SIP_FACTORY;
136 
140  virtual void draw( QgsRenderContext &context,
141  const QgsScaleBarSettings &settings,
142  const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const = 0;
143 
148  Q_DECL_DEPRECATED virtual QSizeF calculateBoxSize( const QgsScaleBarSettings &settings,
149  const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const SIP_DEPRECATED;
150 
156  virtual QSizeF calculateBoxSize( QgsRenderContext &context,
157  const QgsScaleBarSettings &settings,
158  const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;
159 
167  virtual bool applyDefaultSettings( QgsScaleBarSettings &settings ) const;
168 
169  protected:
170 
174  void drawDefaultLabels( QgsRenderContext &context,
175  const QgsScaleBarSettings &settings,
176  const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;
177 
181  QString firstLabelString( const QgsScaleBarSettings &settings ) const;
182 
187  Q_DECL_DEPRECATED double firstLabelXOffset( const QgsScaleBarSettings &settings ) const SIP_DEPRECATED;
188 
193  double firstLabelXOffset( const QgsScaleBarSettings &settings, const QgsRenderContext &context, const ScaleBarContext &scaleContext ) const;
194 
199  Q_DECL_DEPRECATED QList<double> segmentPositions( const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const SIP_DEPRECATED;
200 
205  QList<double> segmentPositions( QgsRenderContext &context, const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const;
206 
210  QList<double> segmentWidths( const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const;
211 
212 };
213 
214 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsScaleBarRenderer::Flags )
215 
216 #endif //QGSSCALEBARRENDERER_H
QgsScaleBarRenderer::draw
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.
QgsScaleBarRenderer::id
virtual QString id() const =0
Returns the unique ID for this renderer.
QgsScaleBarRenderer::ScaleBarContext
Contains parameters regarding scalebar calculations.
Definition: qgsscalebarrenderer.h:71
QgsScaleBarRenderer::clone
virtual QgsScaleBarRenderer * clone() const =0
Returns a clone of the renderer.
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsScaleBarRenderer::name
Q_DECL_DEPRECATED QString name() const
Returns the unique name for this style.
Definition: qgsscalebarrenderer.h:104
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsScaleBarRenderer::ScaleBarContext::size
QSizeF size
Destination size for scalebar.
Definition: qgsscalebarrenderer.h:84
QgsScaleBarSettings
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
Definition: qgsscalebarsettings.h:41
qgis_sip.h
Q_DECLARE_OPERATORS_FOR_FLAGS
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QgsScaleBarRenderer
Abstract base class for scale bar renderers.
Definition: qgsscalebarrenderer.h:39
QgsScaleBarRenderer::Flag
Flag
Flags which control scalebar renderer behavior.
Definition: qgsscalebarrenderer.h:47
QgsScaleBarRenderer::visibleName
virtual QString visibleName() const =0
Returns the user friendly, translated name for the renderer.
QgsScaleBarRenderer::QgsScaleBarRenderer
QgsScaleBarRenderer()=default
Constructor for QgsScaleBarRenderer.
QgsScaleBarRenderer::~QgsScaleBarRenderer
virtual ~QgsScaleBarRenderer()=default
QgsScaleBarRenderer::ScaleBarContext::flags
Flags flags
Scalebar renderer flags.
Definition: qgsscalebarrenderer.h:90