QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 "qgstextrenderer.h"
24 #include <QColor>
25 #include <QFont>
26 #include <QPen>
27 #include <QBrush>
28 
29 class QgsNumericFormat;
30 
31 
39 class CORE_EXPORT QgsScaleBarSettings
40 {
41  public:
42 
46  enum Alignment
47  {
48  AlignLeft = 0,
51  };
52 
57  {
58  SegmentSizeFixed = 0,
59  SegmentSizeFitWidth = 1
60  };
61 
66  {
67  LabelAboveSegment = 0,
69  };
70 
75  {
76  LabelCenteredEdge = 0,
78  };
79 
84 
86 
91 
92  QgsScaleBarSettings &operator=( const QgsScaleBarSettings &other );
93 
99  int numberOfSegments() const { return mNumSegments; }
100 
106  void setNumberOfSegments( int segments ) { mNumSegments = segments; }
107 
113  int numberOfSegmentsLeft() const { return mNumSegmentsLeft; }
114 
120  void setNumberOfSegmentsLeft( int segments ) { mNumSegmentsLeft = segments; }
121 
126  double unitsPerSegment() const { return mNumUnitsPerSegment; }
127 
132  void setUnitsPerSegment( double units ) { mNumUnitsPerSegment = units; }
133 
140  SegmentSizeMode segmentSizeMode() const { return mSegmentSizeMode; }
141 
148  void setSegmentSizeMode( SegmentSizeMode mode ) { mSegmentSizeMode = mode; }
149 
158  double minimumBarWidth() const { return mMinBarWidth; }
159 
168  void setMinimumBarWidth( double width ) { mMinBarWidth = width; }
169 
178  double maximumBarWidth() const { return mMaxBarWidth; }
179 
188  void setMaximumBarWidth( double width ) { mMaxBarWidth = width; }
189 
194  QgsUnitTypes::DistanceUnit units() const { return mUnits; }
195 
200  void setUnits( QgsUnitTypes::DistanceUnit units ) { mUnits = units; }
201 
206  double mapUnitsPerScaleBarUnit() const { return mNumMapUnitsPerScaleBarUnit; }
207 
212  void setMapUnitsPerScaleBarUnit( double units ) { mNumMapUnitsPerScaleBarUnit = units; }
213 
218  QString unitLabel() const { return mUnitLabeling; }
219 
224  void setUnitLabel( const QString &label ) { mUnitLabeling = label; }
225 
231  QgsTextFormat &textFormat() { return mTextFormat; }
232 
238  QgsTextFormat textFormat() const SIP_SKIP { return mTextFormat; }
239 
245  void setTextFormat( const QgsTextFormat &format ) { mTextFormat = format; }
246 
252  Q_DECL_DEPRECATED QFont font() const SIP_DEPRECATED { return mTextFormat.font(); }
253 
259  Q_DECL_DEPRECATED void setFont( const QFont &font ) SIP_DEPRECATED
260  {
261  mTextFormat.setFont( font );
262  if ( font.pointSizeF() > 0 )
263  {
264  mTextFormat.setSize( font.pointSizeF() );
265  mTextFormat.setSizeUnit( QgsUnitTypes::RenderPoints );
266  }
267  else if ( font.pixelSize() > 0 )
268  {
269  mTextFormat.setSize( font.pixelSize() );
270  mTextFormat.setSizeUnit( QgsUnitTypes::RenderPixels );
271  }
272  }
273 
280  Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED { return mTextFormat.color(); }
281 
288  Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED { mTextFormat.setColor( color ); }
289 
295  QColor fillColor() const { return mFillColor; }
296 
302  void setFillColor( const QColor &color ) { mFillColor = color; mBrush.setColor( color ); }
303 
309  QColor fillColor2() const {return mFillColor2;}
310 
316  void setFillColor2( const QColor &color ) { mFillColor2 = color; mBrush2.setColor( color ); }
317 
322  QColor lineColor() const { return mLineColor; }
323 
328  void setLineColor( const QColor &color ) { mLineColor = color; mPen.setColor( mLineColor ); }
329 
334  double lineWidth() const { return mLineWidth; }
335 
340  void setLineWidth( double width ) { mLineWidth = width; mPen.setWidthF( width ); }
341 
347  QPen pen() const { return mPen; }
348 
353  void setPen( const QPen &pen ) { mPen = pen; }
354 
361  QBrush brush() const { return mBrush; }
362 
367  void setBrush( const QBrush &brush ) { mBrush = brush; }
368 
375  QBrush brush2() const { return mBrush2; }
376 
381  void setBrush2( const QBrush &brush ) { mBrush2 = brush; }
382 
387  double height() const { return mHeight; }
388 
393  void setHeight( double height ) { mHeight = height; }
394 
399  double labelBarSpace() const { return mLabelBarSpace; }
400 
405  void setLabelBarSpace( double space ) { mLabelBarSpace = space; }
406 
412  LabelVerticalPlacement labelVerticalPlacement() const { return mLabelVerticalPlacement; }
413 
419  void setLabelVerticalPlacement( LabelVerticalPlacement placement ) { mLabelVerticalPlacement = placement; }
420 
426  LabelHorizontalPlacement labelHorizontalPlacement() const { return mLabelHorizontalPlacement; }
427 
433  void setLabelHorizontalPlacement( LabelHorizontalPlacement placement ) { mLabelHorizontalPlacement = placement; }
434 
439  double boxContentSpace() const { return mBoxContentSpace; }
440 
445  void setBoxContentSpace( double space ) { mBoxContentSpace = space; }
446 
451  Alignment alignment() const { return mAlignment; }
452 
457  void setAlignment( Alignment alignment ) { mAlignment = alignment; }
458 
463  Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
464 
469  void setLineJoinStyle( Qt::PenJoinStyle style ) { mLineJoinStyle = style; mPen.setJoinStyle( style ); }
470 
475  Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
476 
481  void setLineCapStyle( Qt::PenCapStyle style ) { mLineCapStyle = style; mPen.setCapStyle( style ); }
482 
489  const QgsNumericFormat *numericFormat() const;
490 
499  void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
500 
501  private:
502 
504  int mNumSegments = 2;
506  int mNumSegmentsLeft = 0;
508  double mNumUnitsPerSegment = 0;
510  double mNumMapUnitsPerScaleBarUnit = 1.0;
512  SegmentSizeMode mSegmentSizeMode = SegmentSizeFixed;
514  double mMinBarWidth = 50.0;
516  double mMaxBarWidth = 150.0;
517 
519  QString mUnitLabeling;
520 
522  QgsTextFormat mTextFormat;
523 
525  QColor mFillColor = QColor( 0, 0, 0 );
527  QColor mFillColor2 = QColor( 255, 255, 255 );
529  QColor mLineColor = QColor( 0, 0, 0 );
531  double mLineWidth = 0.3;
533  QPen mPen;
535  QBrush mBrush;
537  QBrush mBrush2;
539  double mHeight = 3.0;
540 
542  double mLabelBarSpace = 3.0;
544  LabelVerticalPlacement mLabelVerticalPlacement = LabelAboveSegment;
546  LabelHorizontalPlacement mLabelHorizontalPlacement = LabelCenteredEdge;
547 
549  double mBoxContentSpace = 1.0;
550 
551  Alignment mAlignment = AlignLeft;
552 
554 
555  Qt::PenJoinStyle mLineJoinStyle = Qt::MiterJoin;
556  Qt::PenCapStyle mLineCapStyle = Qt::SquareCap;
557 
558  std::unique_ptr< QgsNumericFormat > mNumericFormat;
559 
560 };
561 
562 #endif // QGSSCALEBARSETTINGS_H
563 
void setMinimumBarWidth(double width)
Sets the minimum width (in millimeters) for scale bar segments.
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
QBrush brush() const
Returns the primary brush used for filling the scalebar.
void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
QString unitLabel() const
Returns the label for units.
QgsTextFormat textFormat() const
Returns the text format used for drawing text in the scalebar.
QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
LabelVerticalPlacement
Label vertical placement.
Alignment alignment() const
Returns the scalebar alignment.
void setPen(const QPen &pen)
Sets the pen used for drawing outlines in the scalebar.
QColor fillColor2() const
Returns the secondary color used for fills in the scalebar.
SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
void setLabelVerticalPlacement(LabelVerticalPlacement placement)
Sets the vertical placement of text labels.
double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
Alignment
Scalebar alignment.
QColor lineColor() const
Returns the color used for lines in the scalebar.
Q_DECL_DEPRECATED QFont font() const
Returns the font used for drawing text in the scalebar.
LabelHorizontalPlacement
Label horizontal placement.
QColor fillColor() const
Returns the color used for fills in the scalebar.
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
double height() const
Returns the scalebar height (in millimeters).
LabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
int numberOfSegments() const
Returns the number of segments included in the scalebar.
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
void setLineCapStyle(Qt::PenCapStyle style)
Sets the cap style used when drawing the lines in the scalebar.
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
#define SIP_SKIP
Definition: qgis_sip.h:126
void setAlignment(Alignment alignment)
Sets the scalebar alignment.
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters. ...
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
void setMaximumBarWidth(double width)
Sets the maximum width (in millimeters) for scale bar segments.
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
void setSegmentSizeMode(SegmentSizeMode mode)
Sets the size mode for scale bar segments.
void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
SegmentSizeMode
Modes for setting size for scale bar segments.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
LabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
QgsTextFormat & textFormat()
Returns the text format used for drawing text in the scalebar.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:66
void setHeight(double height)
Sets the scalebar height (in millimeters).
Q_DECL_DEPRECATED QColor fontColor() const
Returns the color used for drawing text in the scalebar.
Points (e.g., for font sizes)
Definition: qgsunittypes.h:151
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
void setLineJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the lines in the scalebar.
void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
Labels are drawn centered relative to segment.
void setLabelHorizontalPlacement(LabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
void setBrush2(const QBrush &brush)
Sets the secondary brush used for filling the scalebar.
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
QBrush brush2() const
Returns the secondary brush for the scalebar.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
Container for all settings relating to text rendering.
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
Labels are drawn below the scalebar.
void setBrush(const QBrush &brush)
Sets the primary brush used for filling the scalebar.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
void setUnitLabel(const QString &label)
Sets the label for units.
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...