QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsscalebarsettings.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsscalebarsettings.h
3  ---------------------
4  begin : April 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
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 QGSSCALEBARSETTINGS_H
18 #define QGSSCALEBARSETTINGS_H
19 
20 #include "qgis_core.h"
21 #include "qgis.h"
22 #include "qgsunittypes.h"
23 #include "qgstextformat.h"
24 #include <QColor>
25 #include <QFont>
26 #include <QPen>
27 #include <QBrush>
28 
29 class QgsNumericFormat;
30 class QgsLineSymbol;
31 class QgsFillSymbol;
32 
40 class CORE_EXPORT QgsScaleBarSettings
41 {
42  public:
43 
47  enum Alignment
48  {
49  AlignLeft = 0,
52  };
53 
58  {
59  SegmentSizeFixed = 0,
60  SegmentSizeFitWidth = 1
61  };
62 
67  {
68  LabelAboveSegment = 0,
70  };
71 
76  {
77  LabelCenteredEdge = 0,
79  };
80 
85 
87 
92 
93  QgsScaleBarSettings &operator=( const QgsScaleBarSettings &other );
94 
100  int numberOfSegments() const { return mNumSegments; }
101 
107  void setNumberOfSegments( int segments ) { mNumSegments = segments; }
108 
114  int numberOfSegmentsLeft() const { return mNumSegmentsLeft; }
115 
121  void setNumberOfSegmentsLeft( int segments ) { mNumSegmentsLeft = segments; }
122 
132  int numberOfSubdivisions() const { return mNumSubdivisions; }
133 
143  void setNumberOfSubdivisions( int subdivisions ) { mNumSubdivisions = subdivisions; }
144 
150  double subdivisionsHeight() const { return mSubdivisionsHeight; }
151 
157  void setSubdivisionsHeight( double height ) { mSubdivisionsHeight = height; }
158 
163  double unitsPerSegment() const { return mNumUnitsPerSegment; }
164 
169  void setUnitsPerSegment( double units ) { mNumUnitsPerSegment = units; }
170 
177  SegmentSizeMode segmentSizeMode() const { return mSegmentSizeMode; }
178 
185  void setSegmentSizeMode( SegmentSizeMode mode ) { mSegmentSizeMode = mode; }
186 
195  double minimumBarWidth() const { return mMinBarWidth; }
196 
205  void setMinimumBarWidth( double width ) { mMinBarWidth = width; }
206 
215  double maximumBarWidth() const { return mMaxBarWidth; }
216 
225  void setMaximumBarWidth( double width ) { mMaxBarWidth = width; }
226 
231  QgsUnitTypes::DistanceUnit units() const { return mUnits; }
232 
237  void setUnits( QgsUnitTypes::DistanceUnit units ) { mUnits = units; }
238 
243  double mapUnitsPerScaleBarUnit() const { return mNumMapUnitsPerScaleBarUnit; }
244 
249  void setMapUnitsPerScaleBarUnit( double units ) { mNumMapUnitsPerScaleBarUnit = units; }
250 
255  QString unitLabel() const { return mUnitLabeling; }
256 
261  void setUnitLabel( const QString &label ) { mUnitLabeling = label; }
262 
268  QgsTextFormat &textFormat() { return mTextFormat; }
269 
275  QgsTextFormat textFormat() const SIP_SKIP { return mTextFormat; }
276 
282  void setTextFormat( const QgsTextFormat &format ) { mTextFormat = format; }
283 
289  Q_DECL_DEPRECATED QFont font() const SIP_DEPRECATED { return mTextFormat.font(); }
290 
296  Q_DECL_DEPRECATED void setFont( const QFont &font ) SIP_DEPRECATED
297  {
298  mTextFormat.setFont( font );
299  if ( font.pointSizeF() > 0 )
300  {
301  mTextFormat.setSize( font.pointSizeF() );
302  mTextFormat.setSizeUnit( QgsUnitTypes::RenderPoints );
303  }
304  else if ( font.pixelSize() > 0 )
305  {
306  mTextFormat.setSize( font.pixelSize() );
307  mTextFormat.setSizeUnit( QgsUnitTypes::RenderPixels );
308  }
309  }
310 
317  Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED { return mTextFormat.color(); }
318 
325  Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED { mTextFormat.setColor( color ); }
326 
333  Q_DECL_DEPRECATED QColor fillColor() const SIP_DEPRECATED;
334 
341  Q_DECL_DEPRECATED void setFillColor( const QColor &color ) SIP_DEPRECATED;
342 
349  Q_DECL_DEPRECATED QColor fillColor2() const SIP_DEPRECATED;
350 
357  Q_DECL_DEPRECATED void setFillColor2( const QColor &color ) SIP_DEPRECATED;
358 
364  Q_DECL_DEPRECATED QColor lineColor() const SIP_DEPRECATED;
365 
371  Q_DECL_DEPRECATED void setLineColor( const QColor &color ) SIP_DEPRECATED;
372 
378  Q_DECL_DEPRECATED double lineWidth() const SIP_DEPRECATED;
379 
385  Q_DECL_DEPRECATED void setLineWidth( double width ) SIP_DEPRECATED;
386 
393  Q_DECL_DEPRECATED QPen pen() const SIP_DEPRECATED;
394 
400  Q_DECL_DEPRECATED void setPen( const QPen &pen ) SIP_DEPRECATED;
401 
412  QgsLineSymbol *lineSymbol() const;
413 
423  void setLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
424 
435  QgsLineSymbol *divisionLineSymbol() const;
436 
446  void setDivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
447 
458  QgsLineSymbol *subdivisionLineSymbol() const;
459 
469  void setSubdivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
470 
480  QgsFillSymbol *fillSymbol() const;
481 
490  void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
491 
492 
502  QgsFillSymbol *alternateFillSymbol() const;
503 
512  void setAlternateFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
513 
521  Q_DECL_DEPRECATED QBrush brush() const SIP_DEPRECATED;
522 
528  Q_DECL_DEPRECATED void setBrush( const QBrush &brush ) SIP_DEPRECATED;
529 
537  Q_DECL_DEPRECATED QBrush brush2() const SIP_DEPRECATED;
538 
544  Q_DECL_DEPRECATED void setBrush2( const QBrush &brush ) SIP_DEPRECATED;
545 
550  double height() const { return mHeight; }
551 
556  void setHeight( double height ) { mHeight = height; }
557 
562  double labelBarSpace() const { return mLabelBarSpace; }
563 
568  void setLabelBarSpace( double space ) { mLabelBarSpace = space; }
569 
575  LabelVerticalPlacement labelVerticalPlacement() const { return mLabelVerticalPlacement; }
576 
582  void setLabelVerticalPlacement( LabelVerticalPlacement placement ) { mLabelVerticalPlacement = placement; }
583 
589  LabelHorizontalPlacement labelHorizontalPlacement() const { return mLabelHorizontalPlacement; }
590 
596  void setLabelHorizontalPlacement( LabelHorizontalPlacement placement ) { mLabelHorizontalPlacement = placement; }
597 
602  double boxContentSpace() const { return mBoxContentSpace; }
603 
608  void setBoxContentSpace( double space ) { mBoxContentSpace = space; }
609 
614  Alignment alignment() const { return mAlignment; }
615 
620  void setAlignment( Alignment alignment ) { mAlignment = alignment; }
621 
627  Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const SIP_DEPRECATED;
628 
634  Q_DECL_DEPRECATED void setLineJoinStyle( Qt::PenJoinStyle style ) SIP_DEPRECATED;
635 
641  Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const SIP_DEPRECATED;
642 
648  Q_DECL_DEPRECATED void setLineCapStyle( Qt::PenCapStyle style ) SIP_DEPRECATED;
649 
656  const QgsNumericFormat *numericFormat() const;
657 
666  void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
667 
668  private:
669 
671  int mNumSegments = 2;
673  int mNumSegmentsLeft = 0;
675  int mNumSubdivisions = 1;
677  double mSubdivisionsHeight = 1.5;
679  double mNumUnitsPerSegment = 0;
681  double mNumMapUnitsPerScaleBarUnit = 1.0;
683  SegmentSizeMode mSegmentSizeMode = SegmentSizeFixed;
685  double mMinBarWidth = 50.0;
687  double mMaxBarWidth = 150.0;
688 
690  QString mUnitLabeling;
691 
693  QgsTextFormat mTextFormat;
694 
696  double mHeight = 3.0;
697 
698  std::unique_ptr< QgsLineSymbol > mLineSymbol;
699  std::unique_ptr< QgsLineSymbol > mDivisionLineSymbol;
700  std::unique_ptr< QgsLineSymbol > mSubdivisionLineSymbol;
701  std::unique_ptr< QgsFillSymbol > mFillSymbol;
702  std::unique_ptr< QgsFillSymbol > mAlternateFillSymbol;
703 
705  double mLabelBarSpace = 3.0;
707  LabelVerticalPlacement mLabelVerticalPlacement = LabelAboveSegment;
709  LabelHorizontalPlacement mLabelHorizontalPlacement = LabelCenteredEdge;
710 
712  double mBoxContentSpace = 1.0;
713 
714  Alignment mAlignment = AlignLeft;
715 
716  QgsUnitTypes::DistanceUnit mUnits = QgsUnitTypes::DistanceMeters;
717 
718 
719  std::unique_ptr< QgsNumericFormat > mNumericFormat;
720 
721 };
722 
723 #endif // QGSSCALEBARSETTINGS_H
724 
QgsScaleBarSettings::SegmentSizeMode
SegmentSizeMode
Modes for setting size for scale bar segments.
Definition: qgsscalebarsettings.h:57
QgsScaleBarSettings::setLabelBarSpace
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
Definition: qgsscalebarsettings.h:568
QgsScaleBarSettings::setNumberOfSegments
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
Definition: qgsscalebarsettings.h:107
QgsScaleBarSettings::mapUnitsPerScaleBarUnit
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
Definition: qgsscalebarsettings.h:243
QgsScaleBarSettings::setAlignment
void setAlignment(Alignment alignment)
Sets the scalebar alignment.
Definition: qgsscalebarsettings.h:620
QgsScaleBarSettings::setUnitsPerSegment
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
Definition: qgsscalebarsettings.h:169
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
QgsScaleBarSettings::setLabelHorizontalPlacement
void setLabelHorizontalPlacement(LabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
Definition: qgsscalebarsettings.h:596
qgis.h
qgsunittypes.h
QgsScaleBarSettings::LabelHorizontalPlacement
LabelHorizontalPlacement
Label horizontal placement.
Definition: qgsscalebarsettings.h:75
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:259
QgsScaleBarSettings::AlignMiddle
@ AlignMiddle
Center aligned.
Definition: qgsscalebarsettings.h:50
QgsScaleBarSettings::textFormat
QgsTextFormat textFormat() const
Returns the text format used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:275
QgsScaleBarSettings::LabelBelowSegment
@ LabelBelowSegment
Labels are drawn below the scalebar.
Definition: qgsscalebarsettings.h:69
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
QgsScaleBarSettings::setMaximumBarWidth
void setMaximumBarWidth(double width)
Sets the maximum width (in millimeters) for scale bar segments.
Definition: qgsscalebarsettings.h:225
QgsScaleBarSettings::setNumberOfSubdivisions
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
Definition: qgsscalebarsettings.h:143
QgsScaleBarSettings::segmentSizeMode
SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
Definition: qgsscalebarsettings.h:177
QgsScaleBarSettings::setUnits
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
Definition: qgsscalebarsettings.h:237
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsScaleBarSettings::subdivisionsHeight
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
Definition: qgsscalebarsettings.h:150
QgsScaleBarSettings::setFont
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:296
QgsScaleBarSettings::labelBarSpace
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
Definition: qgsscalebarsettings.h:562
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsScaleBarSettings::alignment
Alignment alignment() const
Returns the scalebar alignment.
Definition: qgsscalebarsettings.h:614
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsScaleBarSettings::boxContentSpace
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
Definition: qgsscalebarsettings.h:602
QgsScaleBarSettings::setHeight
void setHeight(double height)
Sets the scalebar height (in millimeters).
Definition: qgsscalebarsettings.h:556
QgsScaleBarSettings::Alignment
Alignment
Scalebar alignment.
Definition: qgsscalebarsettings.h:47
QgsScaleBarSettings::numberOfSegments
int numberOfSegments() const
Returns the number of segments included in the scalebar.
Definition: qgsscalebarsettings.h:100
QgsScaleBarSettings::setUnitLabel
void setUnitLabel(const QString &label)
Sets the label for units.
Definition: qgsscalebarsettings.h:261
QgsScaleBarSettings::setTextFormat
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:282
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
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
Definition: qgsscalebarsettings.h:40
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsUnitTypes
Helper functions for various unit types.
Definition: qgsunittypes.h:38
QgsScaleBarSettings::units
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
Definition: qgsscalebarsettings.h:231
QgsScaleBarSettings::numberOfSegmentsLeft
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
Definition: qgsscalebarsettings.h:114
QgsScaleBarSettings::AlignRight
@ AlignRight
Right aligned.
Definition: qgsscalebarsettings.h:51
QgsScaleBarSettings::setMapUnitsPerScaleBarUnit
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
Definition: qgsscalebarsettings.h:249
QgsScaleBarSettings::maximumBarWidth
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
Definition: qgsscalebarsettings.h:215
QgsScaleBarSettings::setLabelVerticalPlacement
void setLabelVerticalPlacement(LabelVerticalPlacement placement)
Sets the vertical placement of text labels.
Definition: qgsscalebarsettings.h:582
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
QgsScaleBarSettings::setSubdivisionsHeight
void setSubdivisionsHeight(double height)
Sets the scalebar subdivisions height (in millimeters) for segments included in the right part of the...
Definition: qgsscalebarsettings.h:157
QgsScaleBarSettings::setMinimumBarWidth
void setMinimumBarWidth(double width)
Sets the minimum width (in millimeters) for scale bar segments.
Definition: qgsscalebarsettings.h:205
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::setBoxContentSpace
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
Definition: qgsscalebarsettings.h:608
QgsScaleBarSettings::unitsPerSegment
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Definition: qgsscalebarsettings.h:163
QgsScaleBarSettings::fontColor
Q_DECL_DEPRECATED QColor fontColor() const
Returns the color used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:317
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsScaleBarSettings::LabelCenteredSegment
@ LabelCenteredSegment
Labels are drawn centered relative to segment.
Definition: qgsscalebarsettings.h:78
QgsScaleBarSettings::setFontColor
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:325
QgsScaleBarSettings::font
Q_DECL_DEPRECATED QFont font() const
Returns the font used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:289
qgstextformat.h
QgsScaleBarSettings::labelHorizontalPlacement
LabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
Definition: qgsscalebarsettings.h:589
QgsScaleBarSettings::unitLabel
QString unitLabel() const
Returns the label for units.
Definition: qgsscalebarsettings.h:255
QgsScaleBarSettings::setNumberOfSegmentsLeft
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
Definition: qgsscalebarsettings.h:121
QgsScaleBarSettings::minimumBarWidth
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
Definition: qgsscalebarsettings.h:195
QgsScaleBarSettings::setSegmentSizeMode
void setSegmentSizeMode(SegmentSizeMode mode)
Sets the size mode for scale bar segments.
Definition: qgsscalebarsettings.h:185
QgsScaleBarSettings::LabelVerticalPlacement
LabelVerticalPlacement
Label vertical placement.
Definition: qgsscalebarsettings.h:66