QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:30
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:30
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
void setAlignment(Alignment alignment)
Sets the scalebar alignment.
SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
int numberOfSegments() const
Returns the number of segments included in the scalebar.
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Q_DECL_DEPRECATED QColor fontColor() const
Returns the color used for drawing text in the scalebar.
void setLabelVerticalPlacement(LabelVerticalPlacement placement)
Sets the vertical placement of text labels.
void setUnitLabel(const QString &label)
Sets the label for units.
LabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
Alignment alignment() const
Returns the scalebar alignment.
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
void setHeight(double height)
Sets the scalebar height (in millimeters).
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
Alignment
Scalebar alignment.
@ AlignMiddle
Center aligned.
@ AlignRight
Right aligned.
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
LabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
QgsTextFormat textFormat() const
Returns the text format used for drawing text in the scalebar.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
QString unitLabel() const
Returns the label for units.
int numberOfSubdivisions() const
Returns the number of subdivisions for segments included in the right part of the scalebar (only used...
Q_DECL_DEPRECATED QFont font() const
Returns the font used for drawing text in the scalebar.
LabelHorizontalPlacement
Label horizontal placement.
@ LabelCenteredSegment
Labels are drawn centered relative to segment.
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
LabelVerticalPlacement
Label vertical placement.
@ LabelBelowSegment
Labels are drawn below the scalebar.
void setLabelHorizontalPlacement(LabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
void setSubdivisionsHeight(double height)
Sets the scalebar subdivisions height (in millimeters) for segments included in the right part of the...
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
QgsTextFormat & textFormat()
Returns the text format used for drawing text in the scalebar.
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
SegmentSizeMode
Modes for setting size for scale bar segments.
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
void setSegmentSizeMode(SegmentSizeMode mode)
Sets the size mode for scale bar segments.
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
void setMinimumBarWidth(double width)
Sets the minimum width (in millimeters) for scale bar segments.
void setMaximumBarWidth(double width)
Sets the maximum width (in millimeters) for scale bar segments.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
Helper functions for various unit types.
Definition: qgsunittypes.h:39
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36