QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
94  int numberOfSubdivisions() const { return mSettings.numberOfSubdivisions(); }
95 
105  void setNumberOfSubdivisions( int subdivisions ) { mSettings.setNumberOfSubdivisions( subdivisions ); }
106 
112  double subdivisionsHeight() const { return mSettings.subdivisionsHeight(); }
113 
119  void setSubdivisionsHeight( double height ) { mSettings.setSubdivisionsHeight( height ); }
120 
125  double unitsPerSegment() const { return mSettings.unitsPerSegment(); }
126 
131  void setUnitsPerSegment( double units );
132 
139  QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const { return mSettings.segmentSizeMode(); }
140 
147  void setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeMode mode );
148 
157  double minimumBarWidth() const { return mSettings.minimumBarWidth(); }
158 
167  void setMinimumBarWidth( double minWidth );
168 
177  double maximumBarWidth() const { return mSettings.maximumBarWidth(); }
178 
187  void setMaximumBarWidth( double maxWidth );
188 
193  double mapUnitsPerScaleBarUnit() const { return mSettings.mapUnitsPerScaleBarUnit(); }
194 
199  void setMapUnitsPerScaleBarUnit( double units ) { mSettings.setMapUnitsPerScaleBarUnit( units ); }
200 
205  QString unitLabel() const { return mSettings.unitLabel(); }
206 
211  void setUnitLabel( const QString &label ) { mSettings.setUnitLabel( label );}
212 
218  QgsTextFormat textFormat() const;
219 
225  void setTextFormat( const QgsTextFormat &format );
226 
227 
238  QgsLineSymbol *lineSymbol() const;
239 
249  void setLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
250 
261  QgsLineSymbol *divisionLineSymbol() const;
262 
272  void setDivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
273 
284  QgsLineSymbol *subdivisionLineSymbol() const;
285 
295  void setSubdivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
296 
306  QgsFillSymbol *fillSymbol() const;
307 
316  void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
317 
327  QgsFillSymbol *alternateFillSymbol() const;
328 
337  void setAlternateFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
338 
344  Q_DECL_DEPRECATED QFont font() const SIP_DEPRECATED;
345 
351  Q_DECL_DEPRECATED void setFont( const QFont &font ) SIP_DEPRECATED;
352 
359  Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED;
360 
367  Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED;
368 
375  Q_DECL_DEPRECATED QColor fillColor() const SIP_DEPRECATED;
376 
383  Q_DECL_DEPRECATED void setFillColor( const QColor &color ) SIP_DEPRECATED;
384 
391  Q_DECL_DEPRECATED QColor fillColor2() const SIP_DEPRECATED;
392 
399  Q_DECL_DEPRECATED void setFillColor2( const QColor &color ) SIP_DEPRECATED;
400 
406  Q_DECL_DEPRECATED QColor lineColor() const SIP_DEPRECATED;
407 
413  Q_DECL_DEPRECATED void setLineColor( const QColor &color ) SIP_DEPRECATED;
414 
420  Q_DECL_DEPRECATED double lineWidth() const SIP_DEPRECATED;
421 
427  Q_DECL_DEPRECATED void setLineWidth( double width ) SIP_DEPRECATED;
428 
434  Q_DECL_DEPRECATED QPen pen() const SIP_DEPRECATED;
435 
443  Q_DECL_DEPRECATED QBrush brush() const SIP_DEPRECATED;
444 
452  Q_DECL_DEPRECATED QBrush brush2() const SIP_DEPRECATED;
453 
458  double height() const { return mSettings.height(); }
459 
464  void setHeight( double height ) { mSettings.setHeight( height ); }
465 
470  void setLinkedMap( QgsLayoutItemMap *map );
471 
476  QgsLayoutItemMap *linkedMap() const { return mMap; }
477 
482  double labelBarSpace() const { return mSettings.labelBarSpace(); }
483 
488  void setLabelBarSpace( double space ) {mSettings.setLabelBarSpace( space );}
489 
494  double boxContentSpace() const { return mSettings.boxContentSpace(); }
495 
500  void setBoxContentSpace( double space );
501 
507  QgsScaleBarSettings::LabelVerticalPlacement labelVerticalPlacement() const { return mSettings.labelVerticalPlacement(); }
508 
514  void setLabelVerticalPlacement( QgsScaleBarSettings::LabelVerticalPlacement placement );
515 
521  QgsScaleBarSettings::LabelHorizontalPlacement labelHorizontalPlacement() const { return mSettings.labelHorizontalPlacement(); }
522 
528  void setLabelHorizontalPlacement( QgsScaleBarSettings::LabelHorizontalPlacement placement );
529 
534  QgsScaleBarSettings::Alignment alignment() const { return mSettings.alignment(); }
535 
540  void setAlignment( QgsScaleBarSettings::Alignment alignment );
541 
546  QgsUnitTypes::DistanceUnit units() const { return mSettings.units(); }
547 
552  void setUnits( QgsUnitTypes::DistanceUnit units );
553 
559  Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const SIP_DEPRECATED;
560 
566  Q_DECL_DEPRECATED void setLineJoinStyle( Qt::PenJoinStyle style ) SIP_DEPRECATED;
567 
573  Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const SIP_DEPRECATED;
574 
580  Q_DECL_DEPRECATED void setLineCapStyle( Qt::PenCapStyle style ) SIP_DEPRECATED;
581 
586  void applyDefaultSettings();
587 
595  bool applyDefaultRendererSettings( QgsScaleBarRenderer *renderer );
596 
604  QgsUnitTypes::DistanceUnit guessUnits() const;
605 
610  void applyDefaultSize( QgsUnitTypes::DistanceUnit units = QgsUnitTypes::DistanceMeters );
611 
615  void resizeToMinimumWidth();
616 
626  void setStyle( const QString &name );
627 
632  QString style() const;
633 
640  const QgsNumericFormat *numericFormat() const;
641 
650  void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
651 
655  void update();
656 
657  void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties ) override;
658  void finalizeRestoreFromXml() override;
659  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
660  ExportLayerBehavior exportLayerBehavior() const override;
661 
662  protected:
663 
664  void draw( QgsLayoutItemRenderContext &context ) override;
665  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
666  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
667 
668  private slots:
669  void updateScale();
670  void disconnectCurrentMap();
671 
672  private:
673 
675  QgsLayoutItemMap *mMap = nullptr;
676  QString mMapUuid;
677 
678  QgsScaleBarSettings mSettings;
679 
681  std::unique_ptr< QgsScaleBarRenderer > mStyle;
682 
684  double mSegmentMillimeters = 0.0;
685 
687  void refreshSegmentMillimeters();
688 
690  double mapWidth() const;
691 
692  QgsScaleBarRenderer::ScaleBarContext createScaleContext() const;
693 
695 
696 };
697 
698 #endif //QGSLAYOUTITEMSCALEBAR_H
699 
700 
QgsScaleBarSettings::SegmentSizeMode
SegmentSizeMode
Modes for setting size for scale bar segments.
Definition: qgsscalebarsettings.h:58
QgsLayoutItemScaleBar::unitLabel
QString unitLabel() const
Returns the label for units.
Definition: qgslayoutitemscalebar.h:205
QgsLayoutItemScaleBar::mapUnitsPerScaleBarUnit
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
Definition: qgslayoutitemscalebar.h:193
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsLayoutItemScaleBar::labelVerticalPlacement
QgsScaleBarSettings::LabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
Definition: qgslayoutitemscalebar.h:507
QgsLayoutItem::icon
virtual QIcon icon() const
Returns the item's icon.
Definition: qgslayoutitem.h:334
QgsLayoutItemScaleBar::numberOfSegmentsLeft
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
Definition: qgslayoutitemscalebar.h:76
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:45
QgsLayoutItemScaleBar::units
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
Definition: qgslayoutitemscalebar.h:546
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
qgsscalebarrenderer.h
QgsLayoutItemScaleBar::alignment
QgsScaleBarSettings::Alignment alignment() const
Returns the scalebar alignment.
Definition: qgslayoutitemscalebar.h:534
QgsScaleBarSettings::LabelHorizontalPlacement
LabelHorizontalPlacement
Label horizontal placement.
Definition: qgsscalebarsettings.h:76
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:218
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
QgsLayoutItemScaleBar::setHeight
void setHeight(double height)
Sets the scalebar height (in millimeters).
Definition: qgslayoutitemscalebar.h:464
QgsLayoutItemScaleBar::setLabelBarSpace
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
Definition: qgslayoutitemscalebar.h:488
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayoutItem::minimumSize
virtual QgsLayoutSize minimumSize() const
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
Definition: qgslayoutitem.h:560
QgsLayoutItem::type
int type() const override
Returns a unique graphics item type identifier.
Definition: qgslayoutitem.cpp:124
qgsscalebarsettings.h
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsLayoutItemScaleBar::unitsPerSegment
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Definition: qgslayoutitemscalebar.h:125
QgsLayoutItemScaleBar::numberOfSegments
int numberOfSegments() const
Returns the number of segments included in the scalebar.
Definition: qgslayoutitemscalebar.h:62
QgsScaleBarSettings::Alignment
Alignment
Scalebar alignment.
Definition: qgsscalebarsettings.h:48
qgslayoutitem.h
QgsCompositionConverter
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Definition: qgscompositionconverter.h:55
QgsLayoutItemScaleBar::setSubdivisionsHeight
void setSubdivisionsHeight(double height)
Sets the scalebar subdivisions height (in millimeters) for segments included in the right part of the...
Definition: qgslayoutitemscalebar.h:119
QgsScaleBarSettings
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
Definition: qgsscalebarsettings.h:41
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1131
QgsUnitTypes
Helper functions for various unit types.
Definition: qgsunittypes.h:39
QgsScaleBarRenderer
Abstract base class for scale bar renderers.
Definition: qgsscalebarrenderer.h:39
QgsLayoutItemScaleBar::numberOfSubdivisions
int numberOfSubdivisions() const
Returns the number of subdivisions for segments included in the right part of the scalebar (only used...
Definition: qgslayoutitemscalebar.h:94
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
QgsLayoutItemScaleBar::setMapUnitsPerScaleBarUnit
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
Definition: qgslayoutitemscalebar.h:199
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:318
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsLayoutItemScaleBar::setNumberOfSubdivisions
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
Definition: qgslayoutitemscalebar.h:105
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1234
QgsLayoutItemScaleBar::linkedMap
QgsLayoutItemMap * linkedMap() const
Returns the map item linked to the scalebar.
Definition: qgslayoutitemscalebar.h:476
QgsLayoutItemScaleBar::minimumBarWidth
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
Definition: qgslayoutitemscalebar.h:157
QgsLayoutSize
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:41
QgsLayoutItemScaleBar::maximumBarWidth
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
Definition: qgslayoutitemscalebar.h:177
QgsLayoutItemScaleBar::labelBarSpace
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
Definition: qgslayoutitemscalebar.h:482
QgsLayoutItemScaleBar::subdivisionsHeight
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
Definition: qgslayoutitemscalebar.h:112
QgsLayoutItemScaleBar
A layout item subclass for scale bars.
Definition: qgslayoutitemscalebar.h:36
QgsLayoutItemScaleBar::segmentSizeMode
QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
Definition: qgslayoutitemscalebar.h:139
QgsLayoutItemScaleBar::labelHorizontalPlacement
QgsScaleBarSettings::LabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
Definition: qgslayoutitemscalebar.h:521
QgsLayoutItemScaleBar::boxContentSpace
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
Definition: qgslayoutitemscalebar.h:494
QgsLayoutObject
A base class for objects which belong to a layout.
Definition: qgslayoutobject.h:40
QgsLayoutItemScaleBar::setUnitLabel
void setUnitLabel(const QString &label)
Sets the label for units.
Definition: qgslayoutitemscalebar.h:211
QgsScaleBarSettings::LabelVerticalPlacement
LabelVerticalPlacement
Label vertical placement.
Definition: qgsscalebarsettings.h:67