QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsscalebarrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsscalebarrenderer.cpp
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 #include "qgsscalebarrenderer.h"
18 #include "qgsscalebarsettings.h"
19 #include "qgslayoututils.h"
20 #include "qgstextrenderer.h"
22 #include "qgsnumericformat.h"
23 #include "qgssymbol.h"
24 #include "qgssymbollayerutils.h"
25 #include <QFontMetricsF>
26 #include <QPainter>
27 
28 void QgsScaleBarRenderer::drawDefaultLabels( QgsRenderContext &context, const QgsScaleBarSettings &settings, const ScaleBarContext &scaleContext ) const
29 {
30  if ( !context.painter() )
31  {
32  return;
33  }
34 
35  QPainter *painter = context.painter();
36 
37  painter->save();
38 
39  QgsTextFormat format = settings.textFormat();
40 
41  QgsExpressionContextScope *scaleScope = new QgsExpressionContextScope( QStringLiteral( "scalebar_text" ) );
42  QgsExpressionContextScopePopper scopePopper( context.expressionContext(), scaleScope );
43 
44  QString firstLabel = firstLabelString( settings );
45  QFontMetricsF fontMetrics = QgsTextRenderer::fontMetrics( context, format );
46  double xOffset = fontMetrics.width( firstLabel ) / 2.0;
47 
48  double scaledBoxContentSpace = context.convertToPainterUnits( settings.boxContentSpace(), QgsUnitTypes::RenderMillimeters );
49  double scaledLabelBarSpace = context.convertToPainterUnits( settings.labelBarSpace(), QgsUnitTypes::RenderMillimeters );
50  double scaledHeight;
51  if ( ( scaleContext.flags & Flag::FlagUsesSubdivisionsHeight ) && ( settings.numberOfSubdivisions() > 1 ) && ( settings.subdivisionsHeight() > settings.height() ) )
52  {
53  scaledHeight = context.convertToPainterUnits( settings.subdivisionsHeight(), QgsUnitTypes::RenderMillimeters );
54  }
55  else
56  {
57  scaledHeight = context.convertToPainterUnits( settings.height(), QgsUnitTypes::RenderMillimeters );
58  }
59 
60  double currentLabelNumber = 0.0;
61 
62  int nSegmentsLeft = settings.numberOfSegmentsLeft();
63  int segmentCounter = 0;
64 
65  QString currentNumericLabel;
66  QList<double> positions = segmentPositions( context, scaleContext, settings );
67 
68  bool drawZero = true;
69  switch ( settings.labelHorizontalPlacement() )
70  {
72  drawZero = false;
73  break;
75  drawZero = true;
76  break;
77  }
78 
79  QgsNumericFormatContext numericContext;
80 
81  for ( int i = 0; i < positions.size(); ++i )
82  {
83  if ( segmentCounter == 0 && nSegmentsLeft > 0 )
84  {
85  //label first left segment
86  currentNumericLabel = firstLabel;
87  }
88  else if ( segmentCounter != 0 && segmentCounter == nSegmentsLeft ) //reset label number to 0 if there are left segments
89  {
90  currentLabelNumber = 0.0;
91  }
92 
93  if ( segmentCounter >= nSegmentsLeft )
94  {
95  currentNumericLabel = settings.numericFormat()->formatDouble( currentLabelNumber / settings.mapUnitsPerScaleBarUnit(), numericContext );
96  }
97 
98  //don't draw label for intermediate left segments or the zero label when it needs to be skipped
99  if ( ( segmentCounter == 0 || segmentCounter >= nSegmentsLeft ) && ( currentNumericLabel != QStringLiteral( "0" ) || drawZero ) )
100  {
101  scaleScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "scale_value" ), currentNumericLabel, true, false ) );
102  QPointF pos;
104  {
105  if ( segmentCounter == 0 )
106  {
107  // if the segment counter is zero with a non zero label, this is the left-of-zero label
108  pos.setX( context.convertToPainterUnits( positions.at( i ) + ( scaleContext.segmentWidth / 2 ), QgsUnitTypes::RenderMillimeters ) );
109  }
110  else
111  {
112  pos.setX( context.convertToPainterUnits( positions.at( i ) - ( scaleContext.segmentWidth / 2 ), QgsUnitTypes::RenderMillimeters ) );
113  }
114  }
115  else
116  {
117  pos.setX( context.convertToPainterUnits( positions.at( i ), QgsUnitTypes::RenderMillimeters ) + xOffset );
118  }
119  pos.setY( fontMetrics.ascent() + scaledBoxContentSpace + ( settings.labelVerticalPlacement() == QgsScaleBarSettings::LabelBelowSegment ? scaledHeight + scaledLabelBarSpace : 0 ) );
120  QgsTextRenderer::drawText( pos, 0, QgsTextRenderer::AlignCenter, QStringList() << currentNumericLabel, context, format );
121  }
122 
123  if ( segmentCounter >= nSegmentsLeft )
124  {
125  currentLabelNumber += settings.unitsPerSegment();
126  }
127  ++segmentCounter;
128  }
129 
130  //also draw the last label
131  if ( !positions.isEmpty() )
132  {
133  // note: this label is NOT centered over the end of the bar - rather the numeric portion
134  // of it is, without considering the unit label suffix. That's drawn at the end after
135  // horizontally centering just the numeric portion.
136  currentNumericLabel = settings.numericFormat()->formatDouble( currentLabelNumber / settings.mapUnitsPerScaleBarUnit(), numericContext );
137  scaleScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "scale_value" ), currentNumericLabel, true, false ) );
138  QPointF pos;
139  pos.setY( fontMetrics.ascent() + scaledBoxContentSpace + ( settings.labelVerticalPlacement() == QgsScaleBarSettings::LabelBelowSegment ? scaledHeight + scaledLabelBarSpace : 0 ) );
141  {
142  pos.setX( context.convertToPainterUnits( positions.at( positions.size() - 1 ) + ( scaleContext.segmentWidth / 2 ), QgsUnitTypes::RenderMillimeters ) + xOffset );
143  QgsTextRenderer::drawText( pos, 0, QgsTextRenderer::AlignCenter, QStringList() << ( currentNumericLabel + ' ' + settings.unitLabel() ), context, format );
144  }
145  else
146  {
147  pos.setX( context.convertToPainterUnits( positions.at( positions.size() - 1 ) + scaleContext.segmentWidth, QgsUnitTypes::RenderMillimeters ) + xOffset
148  - fontMetrics.width( currentNumericLabel ) / 2.0 );
149  QgsTextRenderer::drawText( pos, 0, QgsTextRenderer::AlignLeft, QStringList() << ( currentNumericLabel + ' ' + settings.unitLabel() ), context, format );
150  }
151  }
152 
153  painter->restore();
154 }
155 
156 QgsScaleBarRenderer::Flags QgsScaleBarRenderer::flags() const
157 {
158  return nullptr;
159 }
160 
162 {
163  return 100;
164 }
165 
167  const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const
168 {
169  QFont font = settings.textFormat().toQFont();
170 
171  //consider centered first label
172  double firstLabelWidth = QgsLayoutUtils::textWidthMM( font, firstLabelString( settings ) );
174  {
175  if ( firstLabelWidth > scaleContext.segmentWidth )
176  {
177  firstLabelWidth = ( firstLabelWidth - scaleContext.segmentWidth ) / 2;
178  }
179  else
180  {
181  firstLabelWidth = 0.0;
182  }
183  }
184  else
185  {
186  firstLabelWidth = firstLabelWidth / 2;
187  }
188 
189  //consider last number and label
190  double largestLabelNumber = settings.numberOfSegments() * settings.unitsPerSegment() / settings.mapUnitsPerScaleBarUnit();
191  QString largestNumberLabel = settings.numericFormat()->formatDouble( largestLabelNumber, QgsNumericFormatContext() );
192  QString largestLabel = largestNumberLabel + ' ' + settings.unitLabel();
193  double largestLabelWidth;
195  {
196  largestLabelWidth = QgsLayoutUtils::textWidthMM( font, largestLabel );
197  if ( largestLabelWidth > scaleContext.segmentWidth )
198  {
199  largestLabelWidth = ( largestLabelWidth - scaleContext.segmentWidth ) / 2;
200  }
201  else
202  {
203  largestLabelWidth = 0.0;
204  }
205  }
206  else
207  {
208  largestLabelWidth = QgsLayoutUtils::textWidthMM( font, largestLabel ) - QgsLayoutUtils::textWidthMM( font, largestNumberLabel ) / 2;
209  }
210 
211  double totalBarLength = scaleContext.segmentWidth * ( settings.numberOfSegments() + ( settings.numberOfSegmentsLeft() > 0 ? 1 : 0 ) );
212 
213  // this whole method is deprecated, so we can still call the deprecated settings.pen() getter
215  double width = firstLabelWidth + totalBarLength + 2 * settings.pen().widthF() + largestLabelWidth + 2 * settings.boxContentSpace();
217 
218  double height = settings.height() + settings.labelBarSpace() + 2 * settings.boxContentSpace() + QgsLayoutUtils::fontAscentMM( font );
219 
220  return QSizeF( width, height );
221 }
222 
224 {
225  const double painterToMm = 1.0 / context.convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters );
226  //consider centered first label
227  double firstLabelWidth = QgsTextRenderer::textWidth( context, settings.textFormat(), QStringList() << firstLabelString( settings ) ) * painterToMm;
228 
230  {
231  if ( firstLabelWidth > scaleContext.segmentWidth )
232  {
233  firstLabelWidth = ( firstLabelWidth - scaleContext.segmentWidth ) / 2;
234  }
235  else
236  {
237  firstLabelWidth = 0.0;
238  }
239  }
240  else
241  {
242  firstLabelWidth = firstLabelWidth / 2;
243  }
244 
245  //consider last number and label
246  double largestLabelNumber = settings.numberOfSegments() * settings.unitsPerSegment() / settings.mapUnitsPerScaleBarUnit();
247  QString largestNumberLabel = settings.numericFormat()->formatDouble( largestLabelNumber, QgsNumericFormatContext() );
248  QString largestLabel = largestNumberLabel + ' ' + settings.unitLabel();
249  double largestLabelWidth;
251  {
252  largestLabelWidth = QgsTextRenderer::textWidth( context, settings.textFormat(), QStringList() << largestLabel ) * painterToMm;
253 
254  if ( largestLabelWidth > scaleContext.segmentWidth )
255  {
256  largestLabelWidth = ( largestLabelWidth - scaleContext.segmentWidth ) / 2;
257  }
258  else
259  {
260  largestLabelWidth = 0.0;
261  }
262  }
263  else
264  {
265  largestLabelWidth = QgsTextRenderer::textWidth( context, settings.textFormat(), QStringList() << largestLabel ) * painterToMm
266  - QgsTextRenderer::textWidth( context, settings.textFormat(), QStringList() << largestNumberLabel ) * painterToMm / 2;
267  }
268 
269  double totalBarLength = scaleContext.segmentWidth * ( settings.numberOfSegments() + ( settings.numberOfSegmentsLeft() > 0 ? 1 : 0 ) );
270 
271  double lineWidth = QgsSymbolLayerUtils::estimateMaxSymbolBleed( settings.lineSymbol(), context ) * 2;
272  // need to convert to mm
273  lineWidth /= context.convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters );
274 
275  double width = firstLabelWidth + totalBarLength + 2 * lineWidth + largestLabelWidth + 2 * settings.boxContentSpace();
276  double height;
277  if ( ( scaleContext.flags & Flag::FlagUsesSubdivisionsHeight ) && ( settings.numberOfSubdivisions() > 1 ) && ( settings.subdivisionsHeight() > settings.height() ) )
278  {
279  height = settings.subdivisionsHeight();
280  }
281  else
282  {
283  height = settings.height();
284  }
285 
286  // TODO -- we technically should check the height of ALL labels here and take the maximum
287  height += settings.labelBarSpace() + 2 * settings.boxContentSpace() + QgsTextRenderer::textHeight( context, settings.textFormat(), QStringList() << largestLabel ) * painterToMm;
288 
289  return QSizeF( width, height );
290 }
291 
293 {
294  return false;
295 }
296 
298 {
299  if ( settings.numberOfSegmentsLeft() > 0 )
300  {
301  return settings.numericFormat()->formatDouble( settings.unitsPerSegment() / settings.mapUnitsPerScaleBarUnit(), QgsNumericFormatContext() );
302  }
303  else
304  {
305  return settings.numericFormat()->formatDouble( 0, QgsNumericFormatContext() );
306  }
307 }
308 
310 {
311  QString firstLabel = firstLabelString( settings );
313  return QgsLayoutUtils::textWidthMM( settings.font(), firstLabel ) / 2.0;
315 }
316 
317 double QgsScaleBarRenderer::firstLabelXOffset( const QgsScaleBarSettings &settings, const QgsRenderContext &context, const ScaleBarContext &scaleContext ) const
318 {
319  QString firstLabel = firstLabelString( settings );
320  double firstLabelWidth = QgsTextRenderer::textWidth( context, settings.textFormat(), QStringList() << firstLabel );
322  {
323  if ( firstLabelWidth > scaleContext.segmentWidth )
324  {
325  firstLabelWidth = ( firstLabelWidth - scaleContext.segmentWidth ) / 2;
326  }
327  else
328  {
329  firstLabelWidth = 0.0;
330  }
331  }
332  else
333  {
334  firstLabelWidth = firstLabelWidth / 2;
335  }
336  return firstLabelWidth;
337 }
338 
339 QList<double> QgsScaleBarRenderer::segmentPositions( const ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const
340 {
341  QList<double> positions;
342 
343  // this whole method is deprecated, so calling a deprecated function is fine
345  double currentXCoord = settings.pen().widthF() + settings.boxContentSpace();
347 
348  //left segments
349  double leftSegmentSize = scaleContext.segmentWidth / settings.numberOfSegmentsLeft();
350  positions.reserve( settings.numberOfSegmentsLeft() + settings.numberOfSegments() );
351  for ( int i = 0; i < settings.numberOfSegmentsLeft(); ++i )
352  {
353  positions << currentXCoord;
354  currentXCoord += leftSegmentSize;
355  }
356 
357  //right segments
358  for ( int i = 0; i < settings.numberOfSegments(); ++i )
359  {
360  positions << currentXCoord;
361  currentXCoord += scaleContext.segmentWidth;
362  }
363  return positions;
364 }
365 
366 QList<double> QgsScaleBarRenderer::segmentPositions( QgsRenderContext &context, const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const
367 {
368  QList<double> positions;
369 
370  double lineWidth = QgsSymbolLayerUtils::estimateMaxSymbolBleed( settings.lineSymbol(), context ) * 2.0;
371  // need to convert to mm
372  lineWidth /= context.convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters );
373 
374  double currentXCoord = lineWidth + settings.boxContentSpace();
375 
376  //left segments
377  double leftSegmentSize = scaleContext.segmentWidth / settings.numberOfSegmentsLeft();
378  positions.reserve( settings.numberOfSegmentsLeft() + settings.numberOfSegments() );
379  for ( int i = 0; i < settings.numberOfSegmentsLeft(); ++i )
380  {
381  positions << currentXCoord;
382  currentXCoord += leftSegmentSize;
383  }
384 
385  //right segments
386  for ( int i = 0; i < settings.numberOfSegments(); ++i )
387  {
388  positions << currentXCoord;
389  currentXCoord += scaleContext.segmentWidth;
390  }
391  return positions;
392 }
393 
394 QList<double> QgsScaleBarRenderer::segmentWidths( const ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings ) const
395 {
396  QList<double> widths;
397  widths.reserve( settings.numberOfSegmentsLeft() + settings.numberOfSegments() );
398 
399  //left segments
400  if ( settings.numberOfSegmentsLeft() > 0 )
401  {
402  double leftSegmentSize = scaleContext.segmentWidth / settings.numberOfSegmentsLeft();
403  for ( int i = 0; i < settings.numberOfSegmentsLeft(); ++i )
404  {
405  widths << leftSegmentSize;
406  }
407  }
408 
409  //right segments
410  for ( int i = 0; i < settings.numberOfSegments(); ++i )
411  {
412  widths << scaleContext.segmentWidth;
413  }
414 
415  return widths;
416 }
QgsScaleBarSettings::height
double height() const
Returns the scalebar height (in millimeters).
Definition: qgsscalebarsettings.h:550
qgsexpressioncontextutils.h
QgsScaleBarSettings::mapUnitsPerScaleBarUnit
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
Definition: qgsscalebarsettings.h:243
QgsExpressionContextScopePopper
Definition: qgsexpressioncontextutils.h:354
QgsScaleBarSettings::lineSymbol
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:191
QgsRenderContext::convertToPainterUnits
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
Definition: qgsrendercontext.cpp:287
QgsScaleBarRenderer::ScaleBarContext
Contains parameters regarding scalebar calculations.
Definition: qgsscalebarrenderer.h:70
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:580
QgsExpressionContextScope::addVariable
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Definition: qgsexpressioncontext.cpp:93
qgstextrenderer.h
QgsTextRenderer::AlignCenter
@ AlignCenter
Center align.
Definition: qgstextrenderer.h:61
QgsScaleBarRenderer::segmentWidths
QList< double > segmentWidths(const QgsScaleBarRenderer::ScaleBarContext &scaleContext, const QgsScaleBarSettings &settings) const
Returns a list of widths of each segment of the scalebar.
Definition: qgsscalebarrenderer.cpp:394
qgssymbollayerutils.h
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
qgsscalebarrenderer.h
QgsScaleBarSettings::LabelBelowSegment
@ LabelBelowSegment
Labels are drawn below the scalebar.
Definition: qgsscalebarsettings.h:69
QgsTextRenderer::fontMetrics
static QFontMetricsF fontMetrics(QgsRenderContext &context, const QgsTextFormat &format)
Returns the font metrics for the given text format, when rendered in the specified render context.
Definition: qgstextrenderer.cpp:231
QgsScaleBarSettings::LabelCenteredEdge
@ LabelCenteredEdge
Labels are drawn centered relative to segment's edge.
Definition: qgsscalebarsettings.h:77
QgsTextRenderer::textWidth
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
Definition: qgstextrenderer.cpp:448
qgsscalebarsettings.h
qgslayoututils.h
QgsScaleBarSettings::subdivisionsHeight
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
Definition: qgsscalebarsettings.h:150
QgsTextRenderer::drawText
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true)
Draws text within a rectangle using the specified settings.
Definition: qgstextrenderer.cpp:45
QgsScaleBarSettings::labelBarSpace
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
Definition: qgsscalebarsettings.h:562
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:752
QgsTextFormat
Definition: qgstextformat.h:38
QgsScaleBarRenderer::applyDefaultSettings
virtual bool applyDefaultSettings(QgsScaleBarSettings &settings) const
Applies any default settings relating to the scalebar to the passed settings object.
Definition: qgsscalebarrenderer.cpp:292
QgsScaleBarSettings::boxContentSpace
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
Definition: qgsscalebarsettings.h:602
QgsScaleBarSettings::numberOfSegments
int numberOfSegments() const
Returns the number of segments included in the scalebar.
Definition: qgsscalebarsettings.h:100
QgsScaleBarSettings::labelVerticalPlacement
LabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
Definition: qgsscalebarsettings.h:575
QgsScaleBarSettings::textFormat
QgsTextFormat & textFormat()
Returns the text format used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:268
QgsScaleBarSettings
Definition: qgsscalebarsettings.h:40
QgsScaleBarSettings::pen
Q_DECL_DEPRECATED QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
Definition: qgsscalebarsettings.cpp:164
QgsTextRenderer::AlignLeft
@ AlignLeft
Left align.
Definition: qgstextrenderer.h:60
QgsScaleBarSettings::numberOfSegmentsLeft
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
Definition: qgsscalebarsettings.h:114
QgsTextRenderer::textHeight
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode=Point, QFontMetricsF *fontMetrics=nullptr)
Returns the height of a text based on a given format.
Definition: qgstextrenderer.cpp:515
QgsNumericFormat::formatDouble
virtual QString formatDouble(double value, const QgsNumericFormatContext &context) const =0
Returns a formatted string representation of a numeric double value.
QgsScaleBarRenderer::firstLabelXOffset
Q_DECL_DEPRECATED double firstLabelXOffset(const QgsScaleBarSettings &settings) const
Returns the x-offset (in millimeters) used for the first label in the scalebar.
Definition: qgsscalebarrenderer.cpp:309
QgsTextFormat::toQFont
QFont toQFont() const
Returns a QFont matching the relevant settings from this text format.
Definition: qgstextformat.cpp:493
QgsScaleBarRenderer::firstLabelString
QString firstLabelString(const QgsScaleBarSettings &settings) const
Returns the text used for the first label in the scalebar.
Definition: qgsscalebarrenderer.cpp:297
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:111
QgsScaleBarRenderer::sortKey
virtual int sortKey() const
Returns a sorting key value, where renderers with a lower sort key will be shown earlier in lists.
Definition: qgsscalebarrenderer.cpp:161
QgsScaleBarRenderer::ScaleBarContext::segmentWidth
double segmentWidth
The width, in millimeters, of each individual segment drawn.
Definition: qgsscalebarrenderer.h:77
qgsnumericformat.h
QgsScaleBarRenderer::drawDefaultLabels
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...
Definition: qgsscalebarrenderer.cpp:28
QgsScaleBarRenderer::calculateBoxSize
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...
Definition: qgsscalebarrenderer.cpp:166
QgsScaleBarRenderer::flags
virtual Flags flags() const
Returns the scalebar rendering flags, which dictates the renderer's behavior.
Definition: qgsscalebarrenderer.cpp:156
QgsScaleBarSettings::numberOfSubdivisions
int numberOfSubdivisions() const
Returns the number of subdivisions for segments included in the right part of the scalebar (only used...
Definition: qgsscalebarsettings.h:132
QgsScaleBarSettings::unitsPerSegment
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Definition: qgsscalebarsettings.h:163
QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight
@ FlagUsesSubdivisionsHeight
Renderer uses the scalebar subdivisions height (see QgsScaleBarSettings::subdivisionsHeight() )
QgsScaleBarSettings::LabelCenteredSegment
@ LabelCenteredSegment
Labels are drawn centered relative to segment.
Definition: qgsscalebarsettings.h:78
QgsLayoutUtils::fontAscentMM
static double fontAscentMM(const QFont &font)
Calculates a font ascent in millimeters, including workarounds for QT font rendering issues.
Definition: qgslayoututils.cpp:181
QgsScaleBarSettings::font
Q_DECL_DEPRECATED QFont font() const
Returns the font used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:289
QgsSymbolLayerUtils::estimateMaxSymbolBleed
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
Definition: qgssymbollayerutils.cpp:820
QgsScaleBarSettings::labelHorizontalPlacement
LabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
Definition: qgsscalebarsettings.h:589
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:174
QgsScaleBarSettings::unitLabel
QString unitLabel() const
Returns the label for units.
Definition: qgsscalebarsettings.h:255
QgsExpressionContextScope::StaticVariable
Single variable definition for use within a QgsExpressionContextScope.
Definition: qgsexpressioncontext.h:118
QgsScaleBarSettings::numericFormat
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
Definition: qgsscalebarsettings.cpp:323
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:751
qgssymbol.h
QgsNumericFormatContext
Definition: qgsnumericformat.h:34
QgsScaleBarRenderer::ScaleBarContext::flags
Flags flags
Scalebar renderer flags.
Definition: qgsscalebarrenderer.h:90
QgsLayoutUtils::textWidthMM
static double textWidthMM(const QFont &font, const QString &text)
Calculate a font width in millimeters for a text string, including workarounds for QT font rendering ...
Definition: qgslayoututils.cpp:219
QgsScaleBarRenderer::segmentPositions
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.
Definition: qgsscalebarrenderer.cpp:339