QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
30 class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
31 {
32  Q_OBJECT
33 
34  public:
35 
36  enum Alignment
37  {
38  Left = 0,
40  Right
41  };
42 
44  {
45  MapUnits = 0,
48  NauticalMiles
49  };
50 
51  QgsComposerScaleBar( QgsComposition* composition );
53 
55  virtual int type() const override { return ComposerScaleBar; }
56 
58  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
59 
60  //getters and setters
61  int numSegments() const {return mNumSegments;}
62  void setNumSegments( int nSegments );
63 
64  int numSegmentsLeft() const {return mNumSegmentsLeft;}
65  void setNumSegmentsLeft( int nSegmentsLeft );
66 
67  double numUnitsPerSegment() const {return mNumUnitsPerSegment;}
68  void setNumUnitsPerSegment( double units );
69 
70  double numMapUnitsPerScaleBarUnit() const {return mNumMapUnitsPerScaleBarUnit;}
71  void setNumMapUnitsPerScaleBarUnit( double d ) {mNumMapUnitsPerScaleBarUnit = d;}
72 
73  QString unitLabeling() const {return mUnitLabeling;}
74  void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}
75 
76  QFont font() const;
77  void setFont( const QFont& font );
78 
84  QColor fontColor() const {return mFontColor;}
85 
91  void setFontColor( const QColor& c ) {mFontColor = c;}
92 
98  QPen pen() const {return mPen;}
99 
105  void setPen( const QPen& pen ) {mPen = pen;}
106 
113  QBrush brush() const {return mBrush;}
114 
121  void setBrush( const QBrush& brush ) {mBrush = brush;}
122 
129  QBrush brush2() const {return mBrush2;}
130 
137  void setBrush2( const QBrush& brush ) {mBrush2 = brush;}
138 
139  double height() const {return mHeight;}
140  void setHeight( double h ) {mHeight = h;}
141 
142  void setComposerMap( const QgsComposerMap* map );
143  const QgsComposerMap* composerMap() const {return mComposerMap;}
144 
145  double labelBarSpace() const {return mLabelBarSpace;}
146  void setLabelBarSpace( double space ) {mLabelBarSpace = space;}
147 
148  double boxContentSpace() const {return mBoxContentSpace;}
149  void setBoxContentSpace( double space );
150 
151  double segmentMillimeters() const {return mSegmentMillimeters;}
152 
154  Alignment alignment() const { return mAlignment; }
155 
156  void setAlignment( Alignment a );
157 
158  ScaleBarUnits units() const { return mUnits; }
159 
160  void setUnits( ScaleBarUnits u );
161 
167  Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
174  void setLineJoinStyle( Qt::PenJoinStyle style );
175 
181  Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
188  void setLineCapStyle( Qt::PenCapStyle style );
189 
191  void applyDefaultSettings();
193  void applyDefaultSize( ScaleBarUnits u = Meters );
194 
197  void setStyle( const QString& styleName );
198 
200  QString style() const;
201 
206  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
207 
209  void adjustBoxSize();
210 
212  void update();
213 
215  QString firstLabelString() const;
216 
221  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
222 
227  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
228 
230  void correctXPositionAlignment( double width, double widthAfter );
231 
232  //overriden to apply minimum size
233  void setSceneRect( const QRectF &rectangle ) override;
234 
235  public slots:
236  void updateSegmentSize();
238  void invalidateCurrentMap();
239 
240  protected:
241 
252 
254  QString mUnitLabeling;
256  QFont mFont;
257  QColor mFontColor;
259  QPen mPen;
261  QBrush mBrush;
263  QBrush mBrush2;
265  double mHeight;
268 
271 
274 
277 
279 
281 
282  Qt::PenJoinStyle mLineJoinStyle;
283  Qt::PenCapStyle mLineCapStyle;
284 
286  void refreshSegmentMillimeters();
287 
289  double mapWidth() const;
290 };
291 
292 #endif //QGSCOMPOSERSCALEBAR_H
293 
294