QGIS API Documentation  3.0.2-Girona (307d082)
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 <QColor>
24 #include <QFont>
25 #include <QPen>
26 #include <QBrush>
27 
35 class CORE_EXPORT QgsScaleBarSettings
36 {
37  public:
38 
42  enum Alignment
43  {
44  AlignLeft = 0,
47  };
48 
53  {
54  SegmentSizeFixed = 0,
55  SegmentSizeFitWidth = 1
56  };
57 
62  {
63  mPen = QPen( mLineColor );
64  mPen.setJoinStyle( mLineJoinStyle );
65  mPen.setCapStyle( mLineCapStyle );
66  mPen.setWidthF( mLineWidth );
67 
68  mBrush.setColor( mFillColor );
69  mBrush.setStyle( Qt::SolidPattern );
70 
71  mBrush2.setColor( mFillColor2 );
72  mBrush2.setStyle( Qt::SolidPattern );
73 
74  mFont.setPointSizeF( 12.0 );
75  mFontColor = QColor( 0, 0, 0 );
76  }
77 
83  int numberOfSegments() const { return mNumSegments; }
84 
90  void setNumberOfSegments( int segments ) { mNumSegments = segments; }
91 
97  int numberOfSegmentsLeft() const { return mNumSegmentsLeft; }
98 
104  void setNumberOfSegmentsLeft( int segments ) { mNumSegmentsLeft = segments; }
105 
110  double unitsPerSegment() const { return mNumUnitsPerSegment; }
111 
116  void setUnitsPerSegment( double units ) { mNumUnitsPerSegment = units; }
117 
124  SegmentSizeMode segmentSizeMode() const { return mSegmentSizeMode; }
125 
132  void setSegmentSizeMode( SegmentSizeMode mode ) { mSegmentSizeMode = mode; }
133 
142  double minimumBarWidth() const { return mMinBarWidth; }
143 
152  void setMinimumBarWidth( double width ) { mMinBarWidth = width; }
153 
162  double maximumBarWidth() const { return mMaxBarWidth; }
163 
172  void setMaximumBarWidth( double width ) { mMaxBarWidth = width; }
173 
178  QgsUnitTypes::DistanceUnit units() const { return mUnits; }
179 
184  void setUnits( QgsUnitTypes::DistanceUnit units ) { mUnits = units; }
185 
190  double mapUnitsPerScaleBarUnit() const { return mNumMapUnitsPerScaleBarUnit; }
191 
196  void setMapUnitsPerScaleBarUnit( double units ) { mNumMapUnitsPerScaleBarUnit = units; }
197 
202  QString unitLabel() const { return mUnitLabeling; }
203 
208  void setUnitLabel( const QString &label ) { mUnitLabeling = label; }
209 
214  QFont font() const { return mFont; }
215 
220  void setFont( const QFont &font ) { mFont = font; }
221 
227  QColor fontColor() const { return mFontColor; }
228 
234  void setFontColor( const QColor &color ) { mFontColor = color; }
235 
241  QColor fillColor() const { return mFillColor; }
242 
248  void setFillColor( const QColor &color ) { mFillColor = color; mBrush.setColor( color ); }
249 
255  QColor fillColor2() const {return mFillColor2;}
256 
262  void setFillColor2( const QColor &color ) { mFillColor2 = color; mBrush2.setColor( color ); }
263 
268  QColor lineColor() const { return mLineColor; }
269 
274  void setLineColor( const QColor &color ) { mLineColor = color; mPen.setColor( mLineColor ); }
275 
280  double lineWidth() const { return mLineWidth; }
281 
286  void setLineWidth( double width ) { mLineWidth = width; mPen.setWidthF( width ); }
287 
293  QPen pen() const { return mPen; }
294 
299  void setPen( const QPen &pen ) { mPen = pen; }
300 
307  QBrush brush() const { return mBrush; }
308 
313  void setBrush( const QBrush &brush ) { mBrush = brush; }
314 
321  QBrush brush2() const { return mBrush2; }
322 
327  void setBrush2( const QBrush &brush ) { mBrush2 = brush; }
328 
333  double height() const { return mHeight; }
334 
339  void setHeight( double height ) { mHeight = height; }
340 
345  double labelBarSpace() const { return mLabelBarSpace; }
346 
351  void setLabelBarSpace( double space ) { mLabelBarSpace = space; }
352 
357  double boxContentSpace() const { return mBoxContentSpace; }
358 
363  void setBoxContentSpace( double space ) { mBoxContentSpace = space; }
364 
369  Alignment alignment() const { return mAlignment; }
370 
375  void setAlignment( Alignment alignment ) { mAlignment = alignment; }
376 
381  Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
382 
387  void setLineJoinStyle( Qt::PenJoinStyle style ) { mLineJoinStyle = style; mPen.setJoinStyle( style ); }
388 
393  Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
394 
399  void setLineCapStyle( Qt::PenCapStyle style ) { mLineCapStyle = style; mPen.setCapStyle( style ); }
400 
401  private:
402 
404  int mNumSegments = 2;
406  int mNumSegmentsLeft = 0;
408  double mNumUnitsPerSegment = 0;
410  double mNumMapUnitsPerScaleBarUnit = 1.0;
412  SegmentSizeMode mSegmentSizeMode = SegmentSizeFixed;
414  double mMinBarWidth = 50.0;
416  double mMaxBarWidth = 150.0;
417 
419  QString mUnitLabeling;
421  QFont mFont;
422  QColor mFontColor;
424  QColor mFillColor = QColor( 0, 0, 0 );
426  QColor mFillColor2 = QColor( 255, 255, 255 );
428  QColor mLineColor = QColor( 0, 0, 0 );
430  double mLineWidth = 0.3;
432  QPen mPen;
434  QBrush mBrush;
436  QBrush mBrush2;
438  double mHeight = 3.0;
439 
441  double mLabelBarSpace = 3.0;
442 
444  double mBoxContentSpace = 1.0;
445 
446  Alignment mAlignment = AlignLeft;
447 
449 
450  Qt::PenJoinStyle mLineJoinStyle = Qt::MiterJoin;
451  Qt::PenCapStyle mLineCapStyle = Qt::SquareCap;
452 
453 };
454 
455 #endif // QGSSCALEBARSETTINGS_H
456 
void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
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.
QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
QColor fontColor() const
Returns the color used for drawing text in the scalebar.
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.
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.
QFont font() const
Returns the font used for drawing text in the scalebar.
QColor fillColor() const
Returns the color used for fills in the scalebar.
double height() const
Returns the scalebar height (in millimeters).
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.
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.
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 setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
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.
QgsScaleBarSettings()
Constructor for QgsScaleBarSettings.
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
void setHeight(double height)
Sets the scalebar height (in millimeters).
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.
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.
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.
void setBrush(const QBrush &brush)
Sets the primary brush used for filling 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...