QGIS API Documentation  2.99.0-Master (ba079d8)
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 "qgis_core.h"
20 #include "qgis.h"
21 #include "qgscomposeritem.h"
24 #include <QFont>
25 #include <QPen>
26 #include <QColor>
27 
28 class QgsComposerMap;
29 
34 class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
35 {
36  Q_OBJECT
37 
38  public:
39 
42 
44  virtual int type() const override { return ComposerScaleBar; }
45 
47  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
48 
49  //getters and setters
50  int numSegments() const {return mSettings.numberOfSegments();}
51  void setNumSegments( int nSegments );
52 
53  int numSegmentsLeft() const {return mSettings.numberOfSegmentsLeft();}
54  void setNumSegmentsLeft( int nSegmentsLeft );
55 
56  double numUnitsPerSegment() const {return mSettings.unitsPerSegment();}
57  void setNumUnitsPerSegment( double units );
58 
65  QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const { return mSettings.segmentSizeMode(); }
66 
74  void setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeMode mode );
75 
84  double minBarWidth() const { return mSettings.minimumBarWidth(); }
85 
95  void setMinBarWidth( double minWidth );
96 
105  double maxBarWidth() const { return mSettings.maximumBarWidth(); }
106 
116  void setMaxBarWidth( double maxWidth );
117 
118  double numMapUnitsPerScaleBarUnit() const {return mSettings.mapUnitsPerScaleBarUnit();}
119  void setNumMapUnitsPerScaleBarUnit( double d ) { mSettings.setMapUnitsPerScaleBarUnit( d );}
120 
121  QString unitLabeling() const {return mSettings.unitLabel();}
122  void setUnitLabeling( const QString &label ) { mSettings.setUnitLabel( label );}
123 
124  QFont font() const;
125  void setFont( const QFont &font );
126 
132  QColor fontColor() const {return mSettings.fontColor();}
133 
139  void setFontColor( const QColor &c ) {mSettings.setFontColor( c );}
140 
146  QColor fillColor() const {return mSettings.fillColor();}
147 
153  void setFillColor( const QColor &color ) {mSettings.setFillColor( color ); }
154 
160  QColor fillColor2() const {return mSettings.fillColor2();}
161 
167  void setFillColor2( const QColor &color ) {mSettings.setFillColor2( color ); }
168 
173  QColor lineColor() const {return mSettings.lineColor();}
174 
179  void setLineColor( const QColor &color ) { mSettings.setLineColor( color ); }
180 
185  double lineWidth() const {return mSettings.lineWidth();}
186 
191  void setLineWidth( double width ) { mSettings.setLineWidth( width ); }
192 
198  QPen pen() const {return mSettings.pen();}
199 
206  QBrush brush() const {return mSettings.brush();}
207 
214  QBrush brush2() const {return mSettings.brush2(); }
215 
216  double height() const { return mSettings.height(); }
217  void setHeight( double h ) { mSettings.setHeight( h );}
218 
222  void setComposerMap( QgsComposerMap *map );
223 
227  QgsComposerMap *composerMap() const {return mComposerMap;}
228 
229  double labelBarSpace() const {return mSettings.labelBarSpace();}
230  void setLabelBarSpace( double space ) {mSettings.setLabelBarSpace( space );}
231 
232  double boxContentSpace() const {return mSettings.boxContentSpace();}
233  void setBoxContentSpace( double space );
234 
238  QgsScaleBarSettings::Alignment alignment() const { return mSettings.alignment(); }
239 
243  void setAlignment( QgsScaleBarSettings::Alignment alignment );
244 
248  QgsUnitTypes::DistanceUnit units() const { return mSettings.units(); }
249 
253  void setUnits( QgsUnitTypes::DistanceUnit u );
254 
260  Qt::PenJoinStyle lineJoinStyle() const { return mSettings.lineJoinStyle(); }
261 
268  void setLineJoinStyle( Qt::PenJoinStyle style );
269 
275  Qt::PenCapStyle lineCapStyle() const { return mSettings.lineCapStyle(); }
276 
283  void setLineCapStyle( Qt::PenCapStyle style );
284 
286  void applyDefaultSettings();
288  void applyDefaultSize( QgsUnitTypes::DistanceUnit u = QgsUnitTypes::DistanceMeters );
289 
292  void setStyle( const QString &styleName );
293 
295  QString style() const;
296 
298  void adjustBoxSize();
299 
301  void update();
302 
303 
308  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
309 
314  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
315 
317  void correctXPositionAlignment( double width, double widthAfter );
318 
319  //overridden to apply minimum size
320  void setSceneRect( const QRectF &rectangle ) override;
321 
322  public slots:
323  void updateSegmentSize();
325  void invalidateCurrentMap();
326  virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties, const QgsExpressionContext *context = nullptr ) override;
327 
328  private:
329 
331  QgsComposerMap *mComposerMap = nullptr;
332 
333  QgsScaleBarSettings mSettings;
334 
336  QgsScaleBarRenderer *mStyle = nullptr;
337 
339  double mSegmentMillimeters;
340 
342  void refreshSegmentMillimeters();
343 
345  double mapWidth() const;
346 
347  QgsScaleBarRenderer::ScaleBarContext createScaleContext() const;
348 
349 };
350 
351 #endif //QGSCOMPOSERSCALEBAR_H
352 
353 
A scale bar item that can be added to a map composition.
double numUnitsPerSegment() const
double numMapUnitsPerScaleBarUnit() const
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
QPen pen() const
Returns the pen used for drawing the scalebar.
QColor fontColor() const
Returns the color used for drawing text in the scalebar.
void setUnitLabeling(const QString &label)
QBrush brush2() const
Returns the secondary brush for the scalebar.
A item that forms part of a map composition.
Alignment
Scalebar alignment.
QColor fillColor2() const
Returns the secondary color used for fills in the scalebar.
DataDefinedProperty
Data defined properties for different item types.
void setNumMapUnitsPerScaleBarUnit(double d)
QgsUnitTypes::DistanceUnit units() const
Returns the scalebar distance units.
QBrush brush() const
Returns the primary brush for the scalebar.
virtual bool readXml(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties, const QgsExpressionContext *context=nullptr) override
Refreshes a data defined property for the item by reevaluating the property&#39;s value and redrawing the...
double labelBarSpace() const
SegmentSizeMode
Modes for setting size for scale bar segments.
QgsComposerMap * composerMap() const
Returns the map item linked to the scalebar.
void setLabelBarSpace(double space)
Graphics scene for map printing.
Object representing map window.
QgsScaleBarSettings::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.
QColor fillColor() const
Returns the color used for fills in the scalebar.
void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
QColor lineColor() const
Returns the color used for lines in the scalebar.
QgsScaleBarSettings::Alignment alignment() const
Returns the alignment of the scalebar.
void setFontColor(const QColor &c)
Sets the color used for drawing text in the scalebar.
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...
Abstract base class for scale bar renderers.
double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
virtual bool writeXml(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
All properties for item.
double minBarWidth() const
Returns the minimum size (in millimeters) for scale bar segments.
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
double maxBarWidth() const
Returns the maximum size (in millimeters) for scale bar segments.
virtual int type() const override
Return correct graphics item type.
Contains parameters regarding scalebar calculations.