QGIS API Documentation  2.0.1-Dufour
 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,
49  Feet
50  };
51 
52  QgsComposerScaleBar( QgsComposition* composition );
54 
56  virtual int type() const { return ComposerScaleBar; }
57 
59  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
60 
61  //getters and setters
62  int numSegments() const {return mNumSegments;}
63  void setNumSegments( int nSegments );
64 
65  int numSegmentsLeft() const {return mNumSegmentsLeft;}
66  void setNumSegmentsLeft( int nSegmentsLeft );
67 
68  double numUnitsPerSegment() const {return mNumUnitsPerSegment;}
69  void setNumUnitsPerSegment( double units );
70 
71  double numMapUnitsPerScaleBarUnit() const {return mNumMapUnitsPerScaleBarUnit;}
72  void setNumMapUnitsPerScaleBarUnit( double d ) {mNumMapUnitsPerScaleBarUnit = d;}
73 
74  QString unitLabeling() const {return mUnitLabeling;}
75  void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}
76 
77  QFont font() const;
78 
79  QColor fontColor() const {return mFontColor;}
80  void setFontColor( const QColor& c ) {mFontColor = c;}
81 
82  void setFont( const QFont& font );
83 
84  QPen pen() const {return mPen;}
85  void setPen( const QPen& pen ) {mPen = pen;}
86 
87  QBrush brush() const {return mBrush;}
88  void setBrush( const QBrush& brush ) {mBrush = brush;}
89 
90  double height() const {return mHeight;}
91  void setHeight( double h ) {mHeight = h;}
92 
93  void setComposerMap( const QgsComposerMap* map );
94  const QgsComposerMap* composerMap() const {return mComposerMap;}
95 
96  double labelBarSpace() const {return mLabelBarSpace;}
97  void setLabelBarSpace( double space ) {mLabelBarSpace = space;}
98 
99  double boxContentSpace() const {return mBoxContentSpace;}
100  void setBoxContentSpace( double space );
101 
102  double segmentMillimeters() const {return mSegmentMillimeters;}
103 
106  Alignment alignment() const { return mAlignment; }
107 
109  void setAlignment( Alignment a );
110 
112  ScaleBarUnits units() const { return mUnits; }
113 
115  void setUnits( ScaleBarUnits u );
116 
118  void applyDefaultSettings();
121  void applyDefaultSize();
122 
125  void setStyle( const QString& styleName );
126 
128  QString style() const;
129 
132  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
133 
135  void adjustBoxSize();
136 
138  void update();
139 
141  QString firstLabelString() const;
142 
147  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
148 
153  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
154 
156  void correctXPositionAlignment( double width, double widthAfter );
157 
158  public slots:
159  void updateSegmentSize();
161  void invalidateCurrentMap();
162 
163  protected:
164 
175 
177  QString mUnitLabeling;
179  QFont mFont;
180  QColor mFontColor;
182  QPen mPen;
184  QBrush mBrush;
186  double mHeight;
189 
192 
195 
198 
200 
202 
204  void refreshSegmentMillimeters();
205 
207  double mapWidth() const;
208 };
209 
210 #endif //QGSCOMPOSERSCALEBAR_H
211 
212