QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
54  {
55  SegmentSizeFixed = 0,
56  SegmentSizeFitWidth = 1
57  };
58 
59  QgsComposerScaleBar( QgsComposition* composition );
61 
63  virtual int type() const override { return ComposerScaleBar; }
64 
66  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
67 
68  //getters and setters
69  int numSegments() const {return mNumSegments;}
70  void setNumSegments( int nSegments );
71 
72  int numSegmentsLeft() const {return mNumSegmentsLeft;}
73  void setNumSegmentsLeft( int nSegmentsLeft );
74 
75  double numUnitsPerSegment() const {return mNumUnitsPerSegment;}
76  void setNumUnitsPerSegment( double units );
77 
84  SegmentSizeMode segmentSizeMode() const { return mSegmentSizeMode; }
85 
93  void setSegmentSizeMode( SegmentSizeMode mode );
94 
103  double minBarWidth() const { return mMinBarWidth; }
104 
114  void setMinBarWidth( double minWidth );
115 
124  double maxBarWidth() const { return mMaxBarWidth; }
125 
135  void setMaxBarWidth( double maxWidth );
136 
137  double numMapUnitsPerScaleBarUnit() const {return mNumMapUnitsPerScaleBarUnit;}
138  void setNumMapUnitsPerScaleBarUnit( double d ) {mNumMapUnitsPerScaleBarUnit = d;}
139 
140  QString unitLabeling() const {return mUnitLabeling;}
141  void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}
142 
143  QFont font() const;
144  void setFont( const QFont& font );
145 
151  QColor fontColor() const {return mFontColor;}
152 
158  void setFontColor( const QColor& c ) {mFontColor = c;}
159 
165  QPen pen() const {return mPen;}
166 
172  void setPen( const QPen& pen ) {mPen = pen;}
173 
180  QBrush brush() const {return mBrush;}
181 
188  void setBrush( const QBrush& brush ) {mBrush = brush;}
189 
196  QBrush brush2() const {return mBrush2;}
197 
204  void setBrush2( const QBrush& brush ) {mBrush2 = brush;}
205 
206  double height() const {return mHeight;}
207  void setHeight( double h ) {mHeight = h;}
208 
209  void setComposerMap( const QgsComposerMap* map );
210  const QgsComposerMap* composerMap() const {return mComposerMap;}
211 
212  double labelBarSpace() const {return mLabelBarSpace;}
213  void setLabelBarSpace( double space ) {mLabelBarSpace = space;}
214 
215  double boxContentSpace() const {return mBoxContentSpace;}
216  void setBoxContentSpace( double space );
217 
218  double segmentMillimeters() const {return mSegmentMillimeters;}
219 
221  Alignment alignment() const { return mAlignment; }
222 
223  void setAlignment( Alignment a );
224 
225  ScaleBarUnits units() const { return mUnits; }
226 
227  void setUnits( ScaleBarUnits u );
228 
234  Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
241  void setLineJoinStyle( Qt::PenJoinStyle style );
242 
248  Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
255  void setLineCapStyle( Qt::PenCapStyle style );
256 
258  void applyDefaultSettings();
260  void applyDefaultSize( ScaleBarUnits u = Meters );
261 
264  void setStyle( const QString& styleName );
265 
267  QString style() const;
268 
273  void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
274 
276  void adjustBoxSize();
277 
279  void update();
280 
282  QString firstLabelString() const;
283 
288  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
289 
294  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
295 
297  void correctXPositionAlignment( double width, double widthAfter );
298 
299  //overriden to apply minimum size
300  void setSceneRect( const QRectF &rectangle ) override;
301 
302  public slots:
303  void updateSegmentSize();
305  void invalidateCurrentMap();
306 
307  protected:
308 
322  double mMinBarWidth;
324  double mMaxBarWidth;
325 
338  double mHeight;
341 
344 
347 
350 
352 
354 
355  Qt::PenJoinStyle mLineJoinStyle;
356  Qt::PenCapStyle mLineCapStyle;
357 
359  void refreshSegmentMillimeters();
360 
362  double mapWidth() const;
363 };
364 
365 #endif //QGSCOMPOSERSCALEBAR_H
366 
367 
A scale bar item that can be added to a map composition.
double minBarWidth() const
Returns the minimum size (in millimeters) for scale bar segments.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
double mLabelBarSpace
Space between bar and Text labels.
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)
Sets the pen used for drawing the scalebar.
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.
double mMinBarWidth
Minimum allowed bar width, when mSegmentSizeMode is FitWidth.
ScaleBarUnits units() const
QgsScaleBarStyle * mStyle
Scalebar style.
QBrush mBrush2
Secondary fill.
void update(const QRectF &rect)
void setNumMapUnitsPerScaleBarUnit(double d)
double numMapUnitsPerScaleBarUnit() const
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
double mSegmentMillimeters
Width of a segment (in mm)
int numSegmentsLeft() const
Qt::PenCapStyle mLineCapStyle
double labelBarSpace() const
void setBrush2(const QBrush &brush)
Sets secondary brush for the scalebar.
QString unitLabeling() const
double segmentMillimeters() const
int mNumSegmentsLeft
Number of segments on left side.
SegmentSizeMode
Modes for setting size for scale bar segments.
Abstraction of composer scale bar style.
const QgsComposerMap * composerMap() const
void setLabelBarSpace(double space)
Graphics scene for map printing.
Object representing map window.
QPen pen() const
Returns the pen used for drawing the scalebar.
QColor fontColor() const
Returns the color used for drawing text in the scalebar.
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
int mNumSegments
Number of segments on right side.
double mMaxBarWidth
Maximum allowed bar width, when mSegmentSizeMode is FitWidth.
void setFontColor(const QColor &c)
Sets the color used for drawing text in the scalebar.
SegmentSizeMode mSegmentSizeMode
Either fixed (i.e.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
double numUnitsPerSegment() const
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...
double mBoxContentSpace
Space between content and item box.
QString mUnitLabeling
Labeling of map units.
QBrush brush() const
Returns the primary brush for the scalebar.
QBrush brush2() const
Returns the secondary brush for the scalebar.
const QgsComposerMap * mComposerMap
Reference to composer map object.
SegmentSizeMode segmentSizeMode() const
Returns the size mode for scale bar segments.
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
double maxBarWidth() const
Returns the maximum size (in millimeters) for scale bar segments.
void setBrush(const QBrush &brush)
Sets primary brush for the scalebar.
virtual int type() const override
Return correct graphics item type.