QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:30
Layout graphical items for displaying a map.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:45
A layout item subclass for scale bars.
QgsLayoutItemMap * linkedMap() const
Returns the map item linked to the scalebar.
QgsScaleBarSettings::Alignment alignment() const
Returns the scalebar alignment.
QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
double unitsPerSegment() const
Returns the number of scalebar units per segment.
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
QgsScaleBarSettings::LabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
int numberOfSegments() const
Returns the number of segments included in the scalebar.
void setHeight(double height)
Sets the scalebar height (in millimeters).
void setSubdivisionsHeight(double height)
Sets the scalebar subdivisions height (in millimeters) for segments included in the right part of the...
QString unitLabel() const
Returns the label for units.
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
void setUnitLabel(const QString &label)
Sets the label for units.
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
int numberOfSubdivisions() const
Returns the number of subdivisions for segments included in the right part of the scalebar (only used...
QgsScaleBarSettings::LabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
Base class for graphical items within a QgsLayout.
int type() const override
Returns a unique graphics item type identifier.
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 QIcon icon() const
Returns the item's icon.
A base class for objects which belong to a layout.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:41
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:30
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
The class is used as a container of context for various read/write operations on other objects.
Abstract base class for scale bar renderers.
The QgsScaleBarSettings class stores the appearance and layout settings for scalebar drawing with Qgs...
Alignment
Scalebar alignment.
LabelHorizontalPlacement
Label horizontal placement.
LabelVerticalPlacement
Label vertical placement.
SegmentSizeMode
Modes for setting size for scale bar segments.
An interface for classes which can visit style entity (e.g.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
Helper functions for various unit types.
Definition: qgsunittypes.h:39
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76