QGIS API Documentation  2.99.0-Master (e077efd)
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 "qgscomposeritem.h"
20 #include <QFont>
21 #include <QPen>
22 #include <QColor>
23 
24 class QgsComposerMap;
25 class QgsScaleBarStyle;
26 
31 class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
32 {
33  Q_OBJECT
34 
35  public:
36 
37  enum Alignment
38  {
39  Left = 0,
41  Right
42  };
43 
45  {
46  MapUnits = 0,
49  NauticalMiles
50  };
51 
55  {
56  SegmentSizeFixed = 0,
57  SegmentSizeFitWidth = 1
58  };
59 
60  QgsComposerScaleBar( QgsComposition* composition );
62 
64  virtual int type() const override { return ComposerScaleBar; }
65 
67  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
68 
69  //getters and setters
70  int numSegments() const {return mNumSegments;}
71  void setNumSegments( int nSegments );
72 
73  int numSegmentsLeft() const {return mNumSegmentsLeft;}
74  void setNumSegmentsLeft( int nSegmentsLeft );
75 
76  double numUnitsPerSegment() const {return mNumUnitsPerSegment;}
77  void setNumUnitsPerSegment( double units );
78 
85  SegmentSizeMode segmentSizeMode() const { return mSegmentSizeMode; }
86 
94  void setSegmentSizeMode( SegmentSizeMode mode );
95 
104  double minBarWidth() const { return mMinBarWidth; }
105 
115  void setMinBarWidth( double minWidth );
116 
125  double maxBarWidth() const { return mMaxBarWidth; }
126 
136  void setMaxBarWidth( double maxWidth );
137 
138  double numMapUnitsPerScaleBarUnit() const {return mNumMapUnitsPerScaleBarUnit;}
139  void setNumMapUnitsPerScaleBarUnit( double d ) {mNumMapUnitsPerScaleBarUnit = d;}
140 
141  QString unitLabeling() const {return mUnitLabeling;}
142  void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}
143 
144  QFont font() const;
145  void setFont( const QFont& font );
146 
152  QColor fontColor() const {return mFontColor;}
153 
159  void setFontColor( const QColor& c ) {mFontColor = c;}
160 
166  QPen pen() const {return mPen;}
167 
173  void setPen( const QPen& pen ) {mPen = pen;}
174 
181  QBrush brush() const {return mBrush;}
182 
189  void setBrush( const QBrush& brush ) {mBrush = brush;}
190 
197  QBrush brush2() const {return mBrush2;}
198 
205  void setBrush2( const QBrush& brush ) {mBrush2 = brush;}
206 
207  double height() const {return mHeight;}
208  void setHeight( double h ) {mHeight = h;}
209 
210  void setComposerMap( const QgsComposerMap* map );
211  const QgsComposerMap* composerMap() const {return mComposerMap;}
212 
213  double labelBarSpace() const {return mLabelBarSpace;}
214  void setLabelBarSpace( double space ) {mLabelBarSpace = space;}
215 
216  double boxContentSpace() const {return mBoxContentSpace;}
217  void setBoxContentSpace( double space );
218 
219  double segmentMillimeters() const {return mSegmentMillimeters;}
220 
222  Alignment alignment() const { return mAlignment; }
223 
224  void setAlignment( Alignment a );
225 
226  ScaleBarUnits units() const { return mUnits; }
227 
228  void setUnits( ScaleBarUnits u );
229 
235  Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
236 
243  void setLineJoinStyle( Qt::PenJoinStyle style );
244 
250  Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
251 
258  void setLineCapStyle( Qt::PenCapStyle style );
259 
261  void applyDefaultSettings();
263  void applyDefaultSize( ScaleBarUnits u = Meters );
264 
267  void setStyle( const QString& styleName );
268 
270  QString style() const;
271 
276  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
277 
279  void adjustBoxSize();
280 
282  void update();
283 
285  QString firstLabelString() const;
286 
291  bool writeXml( QDomElement& elem, QDomDocument & doc ) const override;
292 
297  bool readXml( const QDomElement& itemElem, const QDomDocument& doc ) override;
298 
300  void correctXPositionAlignment( double width, double widthAfter );
301 
302  //overridden to apply minimum size
303  void setSceneRect( const QRectF &rectangle ) override;
304 
305  public slots:
306  void updateSegmentSize();
308  void invalidateCurrentMap();
309 
310  protected:
311 
325  double mMinBarWidth;
327  double mMaxBarWidth;
328 
330  QString mUnitLabeling;
332  QFont mFont;
333  QColor mFontColor;
335  QPen mPen;
337  QBrush mBrush;
339  QBrush mBrush2;
341  double mHeight;
344 
347 
350 
353 
355 
357 
358  Qt::PenJoinStyle mLineJoinStyle;
359  Qt::PenCapStyle mLineCapStyle;
360 
362  void refreshSegmentMillimeters();
363 
365  double mapWidth() const;
366 };
367 
368 #endif //QGSCOMPOSERSCALEBAR_H
369 
370 
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.