QGIS API Documentation  3.6.0-Noosa (5873452)
qgslayoutitemscalebar.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemscalebar.h
3  ------------------------
4  begin : November 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
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 QGSLAYOUTITEMSCALEBAR_H
17 #define QGSLAYOUTITEMSCALEBAR_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgslayoutitem.h"
24 #include <QFont>
25 #include <QPen>
26 #include <QColor>
27 
28 class QgsLayoutItemMap;
29 
35 class CORE_EXPORT QgsLayoutItemScaleBar: public QgsLayoutItem
36 {
37  Q_OBJECT
38 
39  public:
40 
45 
46  int type() const override;
47  QIcon icon() const override;
48 
54  static QgsLayoutItemScaleBar *create( QgsLayout *layout ) SIP_FACTORY;
55  QgsLayoutSize minimumSize() const override;
56 
62  int numberOfSegments() const { return mSettings.numberOfSegments(); }
63 
69  void setNumberOfSegments( int segments );
70 
76  int numberOfSegmentsLeft() const { return mSettings.numberOfSegmentsLeft(); }
77 
83  void setNumberOfSegmentsLeft( int segments );
84 
89  double unitsPerSegment() const { return mSettings.unitsPerSegment(); }
90 
95  void setUnitsPerSegment( double units );
96 
103  QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const { return mSettings.segmentSizeMode(); }
104 
111  void setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeMode mode );
112 
121  double minimumBarWidth() const { return mSettings.minimumBarWidth(); }
122 
131  void setMinimumBarWidth( double minWidth );
132 
141  double maximumBarWidth() const { return mSettings.maximumBarWidth(); }
142 
151  void setMaximumBarWidth( double maxWidth );
152 
157  double mapUnitsPerScaleBarUnit() const { return mSettings.mapUnitsPerScaleBarUnit(); }
158 
163  void setMapUnitsPerScaleBarUnit( double units ) { mSettings.setMapUnitsPerScaleBarUnit( units ); }
164 
169  QString unitLabel() const { return mSettings.unitLabel(); }
170 
175  void setUnitLabel( const QString &label ) { mSettings.setUnitLabel( label );}
176 
182  QgsTextFormat textFormat() const;
183 
189  void setTextFormat( const QgsTextFormat &format );
190 
196  Q_DECL_DEPRECATED QFont font() const SIP_DEPRECATED;
197 
203  Q_DECL_DEPRECATED void setFont( const QFont &font ) SIP_DEPRECATED;
204 
211  Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED;
212 
219  Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED;
220 
226  QColor fillColor() const { return mSettings.fillColor(); }
227 
233  void setFillColor( const QColor &color ) { mSettings.setFillColor( color ); }
234 
240  QColor fillColor2() const { return mSettings.fillColor2(); }
241 
247  void setFillColor2( const QColor &color ) { mSettings.setFillColor2( color ); }
248 
253  QColor lineColor() const { return mSettings.lineColor(); }
254 
259  void setLineColor( const QColor &color ) { mSettings.setLineColor( color ); }
260 
265  double lineWidth() const { return mSettings.lineWidth(); }
266 
271  void setLineWidth( double width ) { mSettings.setLineWidth( width ); }
272 
277  QPen pen() const { return mSettings.pen(); }
278 
285  QBrush brush() const {return mSettings.brush();}
286 
293  QBrush brush2() const {return mSettings.brush2(); }
294 
299  double height() const { return mSettings.height(); }
300 
305  void setHeight( double height ) { mSettings.setHeight( height ); }
306 
311  void setLinkedMap( QgsLayoutItemMap *map );
312 
317  QgsLayoutItemMap *linkedMap() const { return mMap; }
318 
323  double labelBarSpace() const { return mSettings.labelBarSpace(); }
324 
329  void setLabelBarSpace( double space ) {mSettings.setLabelBarSpace( space );}
330 
335  double boxContentSpace() const { return mSettings.boxContentSpace(); }
336 
341  void setBoxContentSpace( double space );
342 
347  QgsScaleBarSettings::Alignment alignment() const { return mSettings.alignment(); }
348 
353  void setAlignment( QgsScaleBarSettings::Alignment alignment );
354 
359  QgsUnitTypes::DistanceUnit units() const { return mSettings.units(); }
360 
365  void setUnits( QgsUnitTypes::DistanceUnit units );
366 
371  Qt::PenJoinStyle lineJoinStyle() const { return mSettings.lineJoinStyle(); }
372 
377  void setLineJoinStyle( Qt::PenJoinStyle style );
378 
383  Qt::PenCapStyle lineCapStyle() const { return mSettings.lineCapStyle(); }
384 
389  void setLineCapStyle( Qt::PenCapStyle style );
390 
395  void applyDefaultSettings();
396 
404  QgsUnitTypes::DistanceUnit guessUnits() const;
405 
410  void applyDefaultSize( QgsUnitTypes::DistanceUnit units = QgsUnitTypes::DistanceMeters );
411 
415  void resizeToMinimumWidth();
416 
426  void setStyle( const QString &name );
427 
432  QString style() const;
433 
437  void update();
438 
440  void finalizeRestoreFromXml() override;
441  protected:
442 
443  void draw( QgsLayoutItemRenderContext &context ) override;
444  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
445  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
446 
447  private slots:
448  void updateScale();
449  void disconnectCurrentMap();
450 
451  private:
452 
454  QgsLayoutItemMap *mMap = nullptr;
455  QString mMapUuid;
456 
457  QgsScaleBarSettings mSettings;
458 
460  std::unique_ptr< QgsScaleBarRenderer > mStyle;
461 
463  double mSegmentMillimeters = 0.0;
464 
466  void refreshSegmentMillimeters();
467 
469  double mapWidth() const;
470 
471  QgsScaleBarRenderer::ScaleBarContext createScaleContext() const;
472 
474 
475 };
476 
477 #endif //QGSLAYOUTITEMSCALEBAR_H
478 
479 
The class is used as a container of context for various read/write operations on other objects...
virtual QIcon icon() const
Returns the item&#39;s icon.
void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
Base class for graphical items within a QgsLayout.
int type() const override
Returns a unique graphics item type identifier.
QColor fillColor2() const
Returns the secondary color used for fills in the scalebar.
QgsScaleBarSettings::Alignment alignment() const
Returns the scalebar alignment.
Alignment
Scalebar alignment.
QBrush brush() const
Returns the primary brush for the scalebar.
void setHeight(double height)
Sets the scalebar height (in millimeters).
void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property&#39;s value and redrawing the...
QColor lineColor() const
Returns the color used for lines in the scalebar.
void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
Layout graphical items for displaying a map.
int numberOfSegments() const
Returns the number of segments included in the scalebar.
virtual QgsLayoutSize minimumSize() const
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
double height() const
Returns the scalebar height (in millimeters).
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
QString unitLabel() const
Returns the label for units.
QColor fillColor() const
Returns the color used for fills in the scalebar.
QBrush brush2() const
Returns the secondary brush for the scalebar.
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
double unitsPerSegment() const
Returns the number of scalebar units per segment.
#define SIP_FACTORY
Definition: qgis_sip.h:69
void setUnitLabel(const QString &label)
Sets the label for units.
void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
SegmentSizeMode
Modes for setting size for scale bar segments.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
#define SIP_DEPRECATED
Definition: qgis_sip.h:99
double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
QgsLayoutItemMap * linkedMap() const
Returns the map item linked to the scalebar.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:44
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:54
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters. ...
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
A layout item subclass for scale bars.
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item&#39;s contents using the specified item render context.
Container for all settings relating to text rendering.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40
DataDefinedProperty
Data defined properties for different item types.
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
All properties for item.
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
Contains parameters regarding scalebar calculations.