QGIS API Documentation  2.4.0-Chugiak
 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 
123  Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
130  void setLineJoinStyle( Qt::PenJoinStyle style );
131 
137  Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
144  void setLineCapStyle( Qt::PenCapStyle style );
145 
147  void applyDefaultSettings();
150  void applyDefaultSize( ScaleBarUnits u = Meters );
151 
154  void setStyle( const QString& styleName );
155 
157  QString style() const;
158 
163  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
164 
166  void adjustBoxSize();
167 
169  void update();
170 
172  QString firstLabelString() const;
173 
178  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
179 
184  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
185 
187  void correctXPositionAlignment( double width, double widthAfter );
188 
189  public slots:
190  void updateSegmentSize();
192  void invalidateCurrentMap();
193 
194  protected:
195 
206 
208  QString mUnitLabeling;
210  QFont mFont;
211  QColor mFontColor;
213  QPen mPen;
215  QBrush mBrush;
217  double mHeight;
220 
223 
226 
229 
231 
233 
234  Qt::PenJoinStyle mLineJoinStyle;
235  Qt::PenCapStyle mLineCapStyle;
236 
238  void refreshSegmentMillimeters();
239 
241  double mapWidth() const;
242 
243 };
244 
245 #endif //QGSCOMPOSERSCALEBAR_H
246 
247 
A scale bar item that can be added to a map composition.
ScaleBarUnits
Added in version 1.9.
double mLabelBarSpace
Space between bar and Text labels.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)=0
sets state from Dom document
double mHeight
Height of bars/lines.
double mNumUnitsPerSegment
Size of a segment (in map units)
double mNumMapUnitsPerScaleBarUnit
Number of map units per scale bar units (e.g.
void setPen(const QPen &pen)
double boxContentSpace() const
Qt::PenJoinStyle mLineJoinStyle
void setUnitLabeling(const QString &label)
A item that forms part of a map composition.
Alignment alignment() const
Left / Middle/ Right.
ScaleBarUnits units() const
QgsScaleBarStyle * mStyle
Scalebar style.
double height() const
void setNumMapUnitsPerScaleBarUnit(double d)
double numMapUnitsPerScaleBarUnit() const
double mSegmentMillimeters
Width of a segment (in mm)
int numSegmentsLeft() const
Qt::PenCapStyle mLineCapStyle
double labelBarSpace() const
virtual int type() const
return correct graphics item type.
void setHeight(double h)
QString unitLabeling() const
Alignment
Added in version 1.8.
double segmentMillimeters() const
int mNumSegmentsLeft
Number of segments on left side.
Abstraction of composer scale bar style.
const QgsComposerMap * composerMap() const
void setLabelBarSpace(double space)
Graphics scene for map printing.
Object representing map window.
QColor fontColor() const
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
int mNumSegments
Number of segments on right side.
void setFontColor(const QColor &c)
double numUnitsPerSegment() const
double mBoxContentSpace
Space between content and item box.
QString mUnitLabeling
Labeling of map units.
const QgsComposerMap * mComposerMap
Reference to composer map object.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const =0
stores state in Dom element
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
void setBrush(const QBrush &brush)