QGIS API Documentation  2.17.0-Master (dfeb663)
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 
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  //overridden 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 
ScaleBarUnits units() const
A scale bar item that can be added to a map composition.
double numUnitsPerSegment() const
double mLabelBarSpace
Space between bar and Text labels.
double mHeight
Height of bars/lines.
double numMapUnitsPerScaleBarUnit() const
double mNumUnitsPerSegment
Size of a segment (in map units)
QPen pen() const
Returns the pen used for drawing the scalebar.
double mNumMapUnitsPerScaleBarUnit
Number of map units per scale bar units (e.g.
SegmentSizeMode segmentSizeMode() const
Returns the size mode for scale bar segments.
QColor fontColor() const
Returns the color used for drawing text in the scalebar.
void setPen(const QPen &pen)
Sets the pen used for drawing the scalebar.
Qt::PenJoinStyle mLineJoinStyle
void setUnitLabeling(const QString &label)
QBrush brush2() const
Returns the secondary brush for the scalebar.
A item that forms part of a map composition.
double mMinBarWidth
Minimum allowed bar width, when mSegmentSizeMode is FitWidth.
QgsScaleBarStyle * mStyle
Scalebar style.
QBrush mBrush2
Secondary fill.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
SegmentSizeMode
Modes for setting size for scale bar segments.
void update(const QRectF &rect)
void setNumMapUnitsPerScaleBarUnit(double d)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
double mSegmentMillimeters
Width of a segment (in mm)
QBrush brush() const
Returns the primary brush for the scalebar.
Qt::PenCapStyle mLineCapStyle
void setBrush2(const QBrush &brush)
Sets secondary brush for the scalebar.
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
double labelBarSpace() const
int mNumSegmentsLeft
Number of segments on left side.
Abstraction of composer scale bar style.
void setLabelBarSpace(double space)
Graphics scene for map printing.
Object representing map window.
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
const QgsComposerMap * composerMap() const
int mNumSegments
Number of segments on right side.
double segmentMillimeters() const
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.
QString unitLabeling() const
double boxContentSpace() 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...
Alignment alignment() const
Left / Middle/ Right.
double mBoxContentSpace
Space between content and item box.
QString mUnitLabeling
Labeling of map units.
const QgsComposerMap * mComposerMap
Reference to composer map object.
void setBrush(const QBrush &brush)
Sets primary brush for the scalebar.
double minBarWidth() const
Returns the minimum size (in millimeters) for scale bar segments.
double maxBarWidth() const
Returns the maximum size (in millimeters) for scale bar segments.
virtual int type() const override
Return correct graphics item type.