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 
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  void setFont( const QFont& font );
80 
86  QColor fontColor() const {return mFontColor;}
87 
93  void setFontColor( const QColor& c ) {mFontColor = c;}
94 
100  QPen pen() const {return mPen;}
101 
107  void setPen( const QPen& pen ) {mPen = pen;}
108 
115  QBrush brush() const {return mBrush;}
116 
123  void setBrush( const QBrush& brush ) {mBrush = brush;}
124 
131  QBrush brush2() const {return mBrush2;}
132 
139  void setBrush2( const QBrush& brush ) {mBrush2 = brush;}
140 
141  double height() const {return mHeight;}
142  void setHeight( double h ) {mHeight = h;}
143 
144  void setComposerMap( const QgsComposerMap* map );
145  const QgsComposerMap* composerMap() const {return mComposerMap;}
146 
147  double labelBarSpace() const {return mLabelBarSpace;}
148  void setLabelBarSpace( double space ) {mLabelBarSpace = space;}
149 
150  double boxContentSpace() const {return mBoxContentSpace;}
151  void setBoxContentSpace( double space );
152 
153  double segmentMillimeters() const {return mSegmentMillimeters;}
154 
157  Alignment alignment() const { return mAlignment; }
158 
160  void setAlignment( Alignment a );
161 
163  ScaleBarUnits units() const { return mUnits; }
164 
166  void setUnits( ScaleBarUnits u );
167 
173  Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
180  void setLineJoinStyle( Qt::PenJoinStyle style );
181 
187  Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
194  void setLineCapStyle( Qt::PenCapStyle style );
195 
197  void applyDefaultSettings();
200  void applyDefaultSize( ScaleBarUnits u = Meters );
201 
204  void setStyle( const QString& styleName );
205 
207  QString style() const;
208 
213  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
214 
216  void adjustBoxSize();
217 
219  void update();
220 
222  QString firstLabelString() const;
223 
228  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
229 
234  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
235 
237  void correctXPositionAlignment( double width, double widthAfter );
238 
239  public slots:
240  void updateSegmentSize();
242  void invalidateCurrentMap();
243 
244  protected:
245 
256 
258  QString mUnitLabeling;
260  QFont mFont;
261  QColor mFontColor;
263  QPen mPen;
265  QBrush mBrush;
267  QBrush mBrush2;
269  double mHeight;
272 
275 
278 
281 
283 
285 
286  Qt::PenJoinStyle mLineJoinStyle;
287  Qt::PenCapStyle mLineCapStyle;
288 
290  void refreshSegmentMillimeters();
291 
293  double mapWidth() const;
294 
295 };
296 
297 #endif //QGSCOMPOSERSCALEBAR_H
298 
299 
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:274
double mHeight
Height of bars/lines.
Definition: qgscomposerscalebar.h:269
double mNumUnitsPerSegment
Size of a segment (in map units)
Definition: qgscomposerscalebar.h:253
Definition: qgscomposeritem.h:56
double mNumMapUnitsPerScaleBarUnit
Number of map units per scale bar units (e.g.
Definition: qgscomposerscalebar.h:255
void setPen(const QPen &pen)
Sets the pen used for drawing the scalebar.
Definition: qgscomposerscalebar.h:107
double boxContentSpace() const
Definition: qgscomposerscalebar.h:150
QColor mFontColor
Definition: qgscomposerscalebar.h:261
Qt::PenJoinStyle mLineJoinStyle
Definition: qgscomposerscalebar.h:286
QPen mPen
Outline.
Definition: qgscomposerscalebar.h:263
void setUnitLabeling(const QString &label)
Definition: qgscomposerscalebar.h:76
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
Alignment alignment() const
Left / Middle/ Right.
Definition: qgscomposerscalebar.h:157
ScaleBarUnits units() const
Definition: qgscomposerscalebar.h:163
QFont mFont
Font.
Definition: qgscomposerscalebar.h:260
QgsScaleBarStyle * mStyle
Scalebar style.
Definition: qgscomposerscalebar.h:271
double height() const
Definition: qgscomposerscalebar.h:141
QBrush mBrush2
Secondary fill.
Definition: qgscomposerscalebar.h:267
void setNumMapUnitsPerScaleBarUnit(double d)
Definition: qgscomposerscalebar.h:73
double numMapUnitsPerScaleBarUnit() const
Definition: qgscomposerscalebar.h:72
double mSegmentMillimeters
Width of a segment (in mm)
Definition: qgscomposerscalebar.h:280
int numSegmentsLeft() const
Definition: qgscomposerscalebar.h:66
Qt::PenCapStyle mLineCapStyle
Definition: qgscomposerscalebar.h:287
Definition: qgscomposerscalebar.h:48
double labelBarSpace() const
Definition: qgscomposerscalebar.h:147
void setBrush2(const QBrush &brush)
Sets secondary brush for the scalebar.
Definition: qgscomposerscalebar.h:139
virtual int type() const
return correct graphics item type.
Definition: qgscomposerscalebar.h:57
ScaleBarUnits mUnits
Definition: qgscomposerscalebar.h:284
void setHeight(double h)
Definition: qgscomposerscalebar.h:142
QString unitLabeling() const
Definition: qgscomposerscalebar.h:75
double segmentMillimeters() const
Definition: qgscomposerscalebar.h:153
int mNumSegmentsLeft
Number of segments on left side.
Definition: qgscomposerscalebar.h:251
Abstraction of composer scale bar style.
Definition: qgsscalebarstyle.h:30
const QgsComposerMap * composerMap() const
Definition: qgscomposerscalebar.h:145
void setLabelBarSpace(double space)
Definition: qgscomposerscalebar.h:148
Graphics scene for map printing.
Definition: qgscomposition.h:72
ScaleBarUnits
Added in version 1.9.
Definition: qgscomposerscalebar.h:45
Object representing map window.
Definition: qgscomposermap.h:46
QPen pen() const
Returns the pen used for drawing the scalebar.
Definition: qgscomposerscalebar.h:100
QColor fontColor() const
Returns the color used for drawing text in the scalebar.
Definition: qgscomposerscalebar.h:86
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
Definition: qgscomposerscalebar.h:187
Definition: qgscomposerscalebar.h:49
int mNumSegments
Number of segments on right side.
Definition: qgscomposerscalebar.h:249
void setFontColor(const QColor &c)
Sets the color used for drawing text in the scalebar.
Definition: qgscomposerscalebar.h:93
Definition: qgscomposerscalebar.h:40
Alignment
Added in version 1.8.
Definition: qgscomposerscalebar.h:37
int numSegments() const
Definition: qgscomposerscalebar.h:63
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:69
double mBoxContentSpace
Space between content and item box.
Definition: qgscomposerscalebar.h:277
QString mUnitLabeling
Labeling of map units.
Definition: qgscomposerscalebar.h:258
QBrush brush() const
Returns the primary brush for the scalebar.
Definition: qgscomposerscalebar.h:115
Alignment mAlignment
Definition: qgscomposerscalebar.h:282
QBrush brush2() const
Returns the secondary brush for the scalebar.
Definition: qgscomposerscalebar.h:131
const QgsComposerMap * mComposerMap
Reference to composer map object.
Definition: qgscomposerscalebar.h:247
QBrush mBrush
Fill.
Definition: qgscomposerscalebar.h:265
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
Definition: qgscomposerscalebar.h:173
void setBrush(const QBrush &brush)
Sets primary brush for the scalebar.
Definition: qgscomposerscalebar.h:123