QGIS API Documentation  2.99.0-Master (ae4d26a)
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 
35 class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
36 {
37  Q_OBJECT
38 
39  public:
40 
43 
45  virtual int type() const override { return ComposerScaleBar; }
46 
48  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
49 
50  //getters and setters
51  int numSegments() const {return mSettings.numberOfSegments();}
52  void setNumSegments( int nSegments );
53 
54  int numSegmentsLeft() const {return mSettings.numberOfSegmentsLeft();}
55  void setNumSegmentsLeft( int nSegmentsLeft );
56 
57  double numUnitsPerSegment() const {return mSettings.unitsPerSegment();}
58  void setNumUnitsPerSegment( double units );
59 
67  QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const { return mSettings.segmentSizeMode(); }
68 
77  void setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeMode mode );
78 
88  double minBarWidth() const { return mSettings.minimumBarWidth(); }
89 
100  void setMinBarWidth( double minWidth );
101 
111  double maxBarWidth() const { return mSettings.maximumBarWidth(); }
112 
123  void setMaxBarWidth( double maxWidth );
124 
125  double numMapUnitsPerScaleBarUnit() const {return mSettings.mapUnitsPerScaleBarUnit();}
126  void setNumMapUnitsPerScaleBarUnit( double d ) { mSettings.setMapUnitsPerScaleBarUnit( d );}
127 
128  QString unitLabeling() const {return mSettings.unitLabel();}
129  void setUnitLabeling( const QString &label ) { mSettings.setUnitLabel( label );}
130 
131  QFont font() const;
132  void setFont( const QFont &font );
133 
140  QColor fontColor() const {return mSettings.fontColor();}
141 
148  void setFontColor( const QColor &c ) {mSettings.setFontColor( c );}
149 
156  QColor fillColor() const {return mSettings.fillColor();}
157 
164  void setFillColor( const QColor &color ) {mSettings.setFillColor( color ); }
165 
172  QColor fillColor2() const {return mSettings.fillColor2();}
173 
180  void setFillColor2( const QColor &color ) {mSettings.setFillColor2( color ); }
181 
187  QColor lineColor() const {return mSettings.lineColor();}
188 
194  void setLineColor( const QColor &color ) { mSettings.setLineColor( color ); }
195 
201  double lineWidth() const {return mSettings.lineWidth();}
202 
208  void setLineWidth( double width ) { mSettings.setLineWidth( width ); }
209 
216  QPen pen() const {return mSettings.pen();}
217 
225  QBrush brush() const {return mSettings.brush();}
226 
234  QBrush brush2() const {return mSettings.brush2(); }
235 
236  double height() const { return mSettings.height(); }
237  void setHeight( double h ) { mSettings.setHeight( h );}
238 
242  void setComposerMap( QgsComposerMap *map );
243 
247  QgsComposerMap *composerMap() const {return mComposerMap;}
248 
249  double labelBarSpace() const {return mSettings.labelBarSpace();}
250  void setLabelBarSpace( double space ) {mSettings.setLabelBarSpace( space );}
251 
252  double boxContentSpace() const {return mSettings.boxContentSpace();}
253  void setBoxContentSpace( double space );
254 
258  QgsScaleBarSettings::Alignment alignment() const { return mSettings.alignment(); }
259 
263  void setAlignment( QgsScaleBarSettings::Alignment alignment );
264 
268  QgsUnitTypes::DistanceUnit units() const { return mSettings.units(); }
269 
273  void setUnits( QgsUnitTypes::DistanceUnit u );
274 
281  Qt::PenJoinStyle lineJoinStyle() const { return mSettings.lineJoinStyle(); }
282 
290  void setLineJoinStyle( Qt::PenJoinStyle style );
291 
298  Qt::PenCapStyle lineCapStyle() const { return mSettings.lineCapStyle(); }
299 
307  void setLineCapStyle( Qt::PenCapStyle style );
308 
310  void applyDefaultSettings();
312  void applyDefaultSize( QgsUnitTypes::DistanceUnit u = QgsUnitTypes::DistanceMeters );
313 
317  void setStyle( const QString &styleName );
318 
320  QString style() const;
321 
323  void adjustBoxSize();
324 
326  void update();
327 
328 
334  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
335 
341  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
342 
344  void correctXPositionAlignment( double width, double widthAfter );
345 
346  //overridden to apply minimum size
347  void setSceneRect( const QRectF &rectangle ) override;
348 
349  public slots:
350  void updateSegmentSize();
352  void invalidateCurrentMap();
353  virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties, const QgsExpressionContext *context = nullptr ) override;
354 
355  private:
356 
358  QgsComposerMap *mComposerMap = nullptr;
359 
360  QgsScaleBarSettings mSettings;
361 
363  QgsScaleBarRenderer *mStyle = nullptr;
364 
366  double mSegmentMillimeters;
367 
369  void refreshSegmentMillimeters();
370 
372  double mapWidth() const;
373 
374  QgsScaleBarRenderer::ScaleBarContext createScaleContext() const;
375 
376 };
377 
378 #endif //QGSCOMPOSERSCALEBAR_H
379 
380 
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:46
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:43
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.