QGIS API Documentation  2.2.0-Valmiera
 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 
37  enum Alignment
38  {
39  Left = 0,
41  Right
42  };
43 
46  {
47  MapUnits = 0,
50  NauticalMiles
51  };
52 
53  QgsComposerScaleBar( QgsComposition* composition );
55 
57  virtual int type() const { return ComposerScaleBar; }
58 
60  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
61 
62  //getters and setters
63  int numSegments() const {return mNumSegments;}
64  void setNumSegments( int nSegments );
65 
66  int numSegmentsLeft() const {return mNumSegmentsLeft;}
67  void setNumSegmentsLeft( int nSegmentsLeft );
68 
69  double numUnitsPerSegment() const {return mNumUnitsPerSegment;}
70  void setNumUnitsPerSegment( double units );
71 
72  double numMapUnitsPerScaleBarUnit() const {return mNumMapUnitsPerScaleBarUnit;}
73  void setNumMapUnitsPerScaleBarUnit( double d ) {mNumMapUnitsPerScaleBarUnit = d;}
74 
75  QString unitLabeling() const {return mUnitLabeling;}
76  void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}
77 
78  QFont font() const;
79 
80  QColor fontColor() const {return mFontColor;}
81  void setFontColor( const QColor& c ) {mFontColor = c;}
82 
83  void setFont( const QFont& font );
84 
85  QPen pen() const {return mPen;}
86  void setPen( const QPen& pen ) {mPen = pen;}
87 
88  QBrush brush() const {return mBrush;}
89  void setBrush( const QBrush& brush ) {mBrush = brush;}
90 
91  double height() const {return mHeight;}
92  void setHeight( double h ) {mHeight = h;}
93 
94  void setComposerMap( const QgsComposerMap* map );
95  const QgsComposerMap* composerMap() const {return mComposerMap;}
96 
97  double labelBarSpace() const {return mLabelBarSpace;}
98  void setLabelBarSpace( double space ) {mLabelBarSpace = space;}
99 
100  double boxContentSpace() const {return mBoxContentSpace;}
101  void setBoxContentSpace( double space );
102 
103  double segmentMillimeters() const {return mSegmentMillimeters;}
104 
107  Alignment alignment() const { return mAlignment; }
108 
110  void setAlignment( Alignment a );
111 
113  ScaleBarUnits units() const { return mUnits; }
114 
116  void setUnits( ScaleBarUnits u );
117 
119  void applyDefaultSettings();
122  void applyDefaultSize( ScaleBarUnits u = Meters );
123 
126  void setStyle( const QString& styleName );
127 
129  QString style() const;
130 
135  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
136 
138  void adjustBoxSize();
139 
141  void update();
142 
144  QString firstLabelString() const;
145 
150  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
151 
156  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
157 
159  void correctXPositionAlignment( double width, double widthAfter );
160 
161  public slots:
162  void updateSegmentSize();
164  void invalidateCurrentMap();
165 
166  protected:
167 
178 
180  QString mUnitLabeling;
182  QFont mFont;
183  QColor mFontColor;
185  QPen mPen;
187  QBrush mBrush;
189  double mHeight;
192 
195 
198 
201 
203 
205 
207  void refreshSegmentMillimeters();
208 
210  double mapWidth() const;
211 
212 };
213 
214 #endif //QGSCOMPOSERSCALEBAR_H
215 
216