QGIS API Documentation  2.99.0-Master (0a63d1f)
qgscomposerscalebar.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerscalebar.h
3  -------------------
4  begin : March 2005
5  copyright : (C) 2005 by Radim Blazek
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 #ifndef QGSCOMPOSERSCALEBAR_H
17 #define QGSCOMPOSERSCALEBAR_H
18 
19 #include "qgis_core.h"
20 #include "qgscomposeritem.h"
21 #include <QFont>
22 #include <QPen>
23 #include <QColor>
24 
25 class QgsComposerMap;
26 class QgsScaleBarStyle;
27 
32 class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
33 {
34  Q_OBJECT
35 
36  public:
37 
38  enum Alignment
39  {
40  Left = 0,
42  Right
43  };
44 
46  {
47  MapUnits = 0,
50  NauticalMiles
51  };
52 
56  {
57  SegmentSizeFixed = 0,
58  SegmentSizeFitWidth = 1
59  };
60 
61  QgsComposerScaleBar( QgsComposition* composition );
63 
65  virtual int type() const override { return ComposerScaleBar; }
66 
68  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
69 
70  //getters and setters
71  int numSegments() const {return mNumSegments;}
72  void setNumSegments( int nSegments );
73 
74  int numSegmentsLeft() const {return mNumSegmentsLeft;}
75  void setNumSegmentsLeft( int nSegmentsLeft );
76 
77  double numUnitsPerSegment() const {return mNumUnitsPerSegment;}
78  void setNumUnitsPerSegment( double units );
79 
86  SegmentSizeMode segmentSizeMode() const { return mSegmentSizeMode; }
87 
95  void setSegmentSizeMode( SegmentSizeMode mode );
96 
105  double minBarWidth() const { return mMinBarWidth; }
106 
116  void setMinBarWidth( double minWidth );
117 
126  double maxBarWidth() const { return mMaxBarWidth; }
127 
137  void setMaxBarWidth( double maxWidth );
138 
139  double numMapUnitsPerScaleBarUnit() const {return mNumMapUnitsPerScaleBarUnit;}
140  void setNumMapUnitsPerScaleBarUnit( double d ) {mNumMapUnitsPerScaleBarUnit = d;}
141 
142  QString unitLabeling() const {return mUnitLabeling;}
143  void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}
144 
145  QFont font() const;
146  void setFont( const QFont& font );
147 
153  QColor fontColor() const {return mFontColor;}
154 
160  void setFontColor( const QColor& c ) {mFontColor = c;}
161 
167  QPen pen() const {return mPen;}
168 
174  void setPen( const QPen& pen ) {mPen = pen;}
175 
182  QBrush brush() const {return mBrush;}
183 
190  void setBrush( const QBrush& brush ) {mBrush = brush;}
191 
198  QBrush brush2() const {return mBrush2;}
199 
206  void setBrush2( const QBrush& brush ) {mBrush2 = brush;}
207 
208  double height() const {return mHeight;}
209  void setHeight( double h ) {mHeight = h;}
210 
211  void setComposerMap( const QgsComposerMap* map );
212  const QgsComposerMap* composerMap() const {return mComposerMap;}
213 
214  double labelBarSpace() const {return mLabelBarSpace;}
215  void setLabelBarSpace( double space ) {mLabelBarSpace = space;}
216 
217  double boxContentSpace() const {return mBoxContentSpace;}
218  void setBoxContentSpace( double space );
219 
220  double segmentMillimeters() const {return mSegmentMillimeters;}
221 
223  Alignment alignment() const { return mAlignment; }
224 
225  void setAlignment( Alignment a );
226 
227  ScaleBarUnits units() const { return mUnits; }
228 
229  void setUnits( ScaleBarUnits u );
230 
236  Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
237 
244  void setLineJoinStyle( Qt::PenJoinStyle style );
245 
251  Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
252 
259  void setLineCapStyle( Qt::PenCapStyle style );
260 
262  void applyDefaultSettings();
264  void applyDefaultSize( ScaleBarUnits u = Meters );
265 
268  void setStyle( const QString& styleName );
269 
271  QString style() const;
272 
277  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
278 
280  void adjustBoxSize();
281 
283  void update();
284 
286  QString firstLabelString() const;
287 
292  bool writeXml( QDomElement& elem, QDomDocument & doc ) const override;
293 
298  bool readXml( const QDomElement& itemElem, const QDomDocument& doc ) override;
299 
301  void correctXPositionAlignment( double width, double widthAfter );
302 
303  //overridden to apply minimum size
304  void setSceneRect( const QRectF &rectangle ) override;
305 
306  public slots:
307  void updateSegmentSize();
309  void invalidateCurrentMap();
310 
311  protected:
312 
326  double mMinBarWidth;
328  double mMaxBarWidth;
329 
331  QString mUnitLabeling;
333  QFont mFont;
334  QColor mFontColor;
336  QPen mPen;
338  QBrush mBrush;
340  QBrush mBrush2;
342  double mHeight;
345 
348 
351 
354 
356 
358 
359  Qt::PenJoinStyle mLineJoinStyle;
360  Qt::PenCapStyle mLineCapStyle;
361 
363  void refreshSegmentMillimeters();
364 
366  double mapWidth() const;
367 };
368 
369 #endif //QGSCOMPOSERSCALEBAR_H
370 
371 
ScaleBarUnits units() const
A scale bar item that can be added to a map composition.
double numUnitsPerSegment() const
double mLabelBarSpace
Space between bar and Text labels.
double mHeight
Height of bars/lines.
double numMapUnitsPerScaleBarUnit() const
double mNumUnitsPerSegment
Size of a segment (in map units)
QPen pen() const
Returns the pen used for drawing the scalebar.
double mNumMapUnitsPerScaleBarUnit
Number of map units per scale bar units (e.g. 1000 to have km for a map with m units) ...
SegmentSizeMode segmentSizeMode() const
Returns the size mode for scale bar segments.
QColor fontColor() const
Returns the color used for drawing text in the scalebar.
void setPen(const QPen &pen)
Sets the pen used for drawing the scalebar.
Qt::PenJoinStyle mLineJoinStyle
void setUnitLabeling(const QString &label)
QBrush brush2() const
Returns the secondary brush for the scalebar.
A item that forms part of a map composition.
double mMinBarWidth
Minimum allowed bar width, when mSegmentSizeMode is FitWidth.
QgsScaleBarStyle * mStyle
Scalebar style.
QBrush mBrush2
Secondary fill.
SegmentSizeMode
Modes for setting size for scale bar segments.
void setNumMapUnitsPerScaleBarUnit(double d)
double mSegmentMillimeters
Width of a segment (in mm)
QBrush brush() const
Returns the primary brush for the scalebar.
Qt::PenCapStyle mLineCapStyle
virtual bool readXml(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
void setBrush2(const QBrush &brush)
Sets secondary brush for the scalebar.
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
double labelBarSpace() const
int mNumSegmentsLeft
Number of segments on left side.
Abstraction of composer scale bar style.
void setLabelBarSpace(double space)
Graphics scene for map printing.
Object representing map window.
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
const QgsComposerMap * composerMap() const
int mNumSegments
Number of segments on right side.
double segmentMillimeters() const
double mMaxBarWidth
Maximum allowed bar width, when mSegmentSizeMode is FitWidth.
void setFontColor(const QColor &c)
Sets the color used for drawing text in the scalebar.
SegmentSizeMode mSegmentSizeMode
Either fixed (i.e. mNumUnitsPerSegment) or try to best fit scale bar width (mMinBarWidth, mMaxBarWidth)
QString unitLabeling() const
double boxContentSpace() const
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
Alignment alignment() const
Left / Middle/ Right.
double mBoxContentSpace
Space between content and item box.
QString mUnitLabeling
Labeling of map units.
const QgsComposerMap * mComposerMap
Reference to composer map object.
virtual bool writeXml(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
void setBrush(const QBrush &brush)
Sets primary brush for the scalebar.
double minBarWidth() const
Returns the minimum size (in millimeters) for scale bar segments.
double maxBarWidth() const
Returns the maximum size (in millimeters) for scale bar segments.
virtual int type() const override
Return correct graphics item type.