QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 : blazek@itc.it
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 { return ComposerScaleBar; }
56 
58  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
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();
194  void applyDefaultSize( ScaleBarUnits u = Meters );
195 
198  void setStyle( const QString& styleName );
199 
201  QString style() const;
202 
207  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
208 
210  void adjustBoxSize();
211 
213  void update();
214 
216  QString firstLabelString() const;
217 
222  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
223 
228  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
229 
231  void correctXPositionAlignment( double width, double widthAfter );
232 
233  //overriden to apply minimum size
234  void setSceneRect( const QRectF &rectangle );
235 
236  public slots:
237  void updateSegmentSize();
239  void invalidateCurrentMap();
240 
241  protected:
242 
253 
255  QString mUnitLabeling;
257  QFont mFont;
258  QColor mFontColor;
260  QPen mPen;
262  QBrush mBrush;
264  QBrush mBrush2;
266  double mHeight;
269 
272 
275 
278 
280 
282 
283  Qt::PenJoinStyle mLineJoinStyle;
284  Qt::PenCapStyle mLineCapStyle;
285 
287  void refreshSegmentMillimeters();
288 
290  double mapWidth() const;
291 };
292 
293 #endif //QGSCOMPOSERSCALEBAR_H
294 
295 
A scale bar item that can be added to a map composition.
Definition: qgscomposerscalebar.h:30
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
Definition: qgscomposerobject.cpp:61
double mLabelBarSpace
Space between bar and Text labels.
Definition: qgscomposerscalebar.h:271
double mHeight
Height of bars/lines.
Definition: qgscomposerscalebar.h:266
double mNumUnitsPerSegment
Size of a segment (in map units)
Definition: qgscomposerscalebar.h:250
Definition: qgscomposeritem.h:56
double mNumMapUnitsPerScaleBarUnit
Number of map units per scale bar units (e.g.
Definition: qgscomposerscalebar.h:252
void setPen(const QPen &pen)
Sets the pen used for drawing the scalebar.
Definition: qgscomposerscalebar.h:105
double boxContentSpace() const
Definition: qgscomposerscalebar.h:148
QColor mFontColor
Definition: qgscomposerscalebar.h:258
Qt::PenJoinStyle mLineJoinStyle
Definition: qgscomposerscalebar.h:283
QPen mPen
Outline.
Definition: qgscomposerscalebar.h:260
void setUnitLabeling(const QString &label)
Definition: qgscomposerscalebar.h:74
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
Alignment alignment() const
Left / Middle/ Right.
Definition: qgscomposerscalebar.h:154
ScaleBarUnits units() const
Definition: qgscomposerscalebar.h:158
QFont mFont
Font.
Definition: qgscomposerscalebar.h:257
QgsScaleBarStyle * mStyle
Scalebar style.
Definition: qgscomposerscalebar.h:268
double height() const
Definition: qgscomposerscalebar.h:139
QBrush mBrush2
Secondary fill.
Definition: qgscomposerscalebar.h:264
void setNumMapUnitsPerScaleBarUnit(double d)
Definition: qgscomposerscalebar.h:71
double numMapUnitsPerScaleBarUnit() const
Definition: qgscomposerscalebar.h:70
double mSegmentMillimeters
Width of a segment (in mm)
Definition: qgscomposerscalebar.h:277
int numSegmentsLeft() const
Definition: qgscomposerscalebar.h:64
Qt::PenCapStyle mLineCapStyle
Definition: qgscomposerscalebar.h:284
Definition: qgscomposerscalebar.h:46
double labelBarSpace() const
Definition: qgscomposerscalebar.h:145
void setBrush2(const QBrush &brush)
Sets secondary brush for the scalebar.
Definition: qgscomposerscalebar.h:137
virtual int type() const
return correct graphics item type.
Definition: qgscomposerscalebar.h:55
ScaleBarUnits mUnits
Definition: qgscomposerscalebar.h:281
void setHeight(double h)
Definition: qgscomposerscalebar.h:140
QString unitLabeling() const
Definition: qgscomposerscalebar.h:73
double segmentMillimeters() const
Definition: qgscomposerscalebar.h:151
int mNumSegmentsLeft
Number of segments on left side.
Definition: qgscomposerscalebar.h:248
Abstraction of composer scale bar style.
Definition: qgsscalebarstyle.h:30
const QgsComposerMap * composerMap() const
Definition: qgscomposerscalebar.h:143
void setLabelBarSpace(double space)
Definition: qgscomposerscalebar.h:146
Graphics scene for map printing.
Definition: qgscomposition.h:73
ScaleBarUnits
Definition: qgscomposerscalebar.h:43
Object representing map window.
Definition: qgscomposermap.h:47
QPen pen() const
Returns the pen used for drawing the scalebar.
Definition: qgscomposerscalebar.h:98
QColor fontColor() const
Returns the color used for drawing text in the scalebar.
Definition: qgscomposerscalebar.h:84
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
Definition: qgscomposerscalebar.h:181
Definition: qgscomposerscalebar.h:47
int mNumSegments
Number of segments on right side.
Definition: qgscomposerscalebar.h:246
void setFontColor(const QColor &c)
Sets the color used for drawing text in the scalebar.
Definition: qgscomposerscalebar.h:91
Definition: qgscomposerscalebar.h:39
Alignment
Definition: qgscomposerscalebar.h:36
int numSegments() const
Definition: qgscomposerscalebar.h:61
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
Definition: qgscomposerobject.cpp:74
double numUnitsPerSegment() const
Definition: qgscomposerscalebar.h:67
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...
Definition: qgscomposeritem.cpp:684
double mBoxContentSpace
Space between content and item box.
Definition: qgscomposerscalebar.h:274
QString mUnitLabeling
Labeling of map units.
Definition: qgscomposerscalebar.h:255
QBrush brush() const
Returns the primary brush for the scalebar.
Definition: qgscomposerscalebar.h:113
Alignment mAlignment
Definition: qgscomposerscalebar.h:279
QBrush brush2() const
Returns the secondary brush for the scalebar.
Definition: qgscomposerscalebar.h:129
const QgsComposerMap * mComposerMap
Reference to composer map object.
Definition: qgscomposerscalebar.h:244
QBrush mBrush
Fill.
Definition: qgscomposerscalebar.h:262
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
Definition: qgscomposerscalebar.h:167
void setBrush(const QBrush &brush)
Sets primary brush for the scalebar.
Definition: qgscomposerscalebar.h:121