QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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"
22#include "qgsscalebarsettings.h"
23#include "qgsscalebarrenderer.h"
24#include <QFont>
25#include <QPen>
26#include <QColor>
27
29
34class CORE_EXPORT QgsLayoutItemScaleBar: public QgsLayoutItem
35{
36 Q_OBJECT
37
38 public:
39
44
45 int type() const override;
46 QIcon icon() const override;
47
53 static QgsLayoutItemScaleBar *create( QgsLayout *layout ) SIP_FACTORY;
54 QgsLayoutSize minimumSize() const override;
55
61 int numberOfSegments() const { return mSettings.numberOfSegments(); }
62
68 void setNumberOfSegments( int segments );
69
75 int numberOfSegmentsLeft() const { return mSettings.numberOfSegmentsLeft(); }
76
82 void setNumberOfSegmentsLeft( int segments );
83
93 int numberOfSubdivisions() const { return mSettings.numberOfSubdivisions(); }
94
104 void setNumberOfSubdivisions( int subdivisions ) { mSettings.setNumberOfSubdivisions( subdivisions ); }
105
111 double subdivisionsHeight() const { return mSettings.subdivisionsHeight(); }
112
118 void setSubdivisionsHeight( double height ) { mSettings.setSubdivisionsHeight( height ); }
119
124 double unitsPerSegment() const { return mSettings.unitsPerSegment(); }
125
130 void setUnitsPerSegment( double units );
131
138 QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const { return mSettings.segmentSizeMode(); }
139
146 void setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeMode mode );
147
156 double minimumBarWidth() const { return mSettings.minimumBarWidth(); }
157
166 void setMinimumBarWidth( double minWidth );
167
176 double maximumBarWidth() const { return mSettings.maximumBarWidth(); }
177
186 void setMaximumBarWidth( double maxWidth );
187
192 double mapUnitsPerScaleBarUnit() const { return mSettings.mapUnitsPerScaleBarUnit(); }
193
198 void setMapUnitsPerScaleBarUnit( double units ) { mSettings.setMapUnitsPerScaleBarUnit( units ); }
199
204 QString unitLabel() const { return mSettings.unitLabel(); }
205
210 void setUnitLabel( const QString &label ) { mSettings.setUnitLabel( label );}
211
217 QgsTextFormat textFormat() const;
218
224 void setTextFormat( const QgsTextFormat &format );
225
226
237 QgsLineSymbol *lineSymbol() const;
238
248 void setLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
249
260 QgsLineSymbol *divisionLineSymbol() const;
261
271 void setDivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
272
283 QgsLineSymbol *subdivisionLineSymbol() const;
284
294 void setSubdivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
295
305 QgsFillSymbol *fillSymbol() const;
306
315 void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
316
326 QgsFillSymbol *alternateFillSymbol() const;
327
336 void setAlternateFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
337
343 Q_DECL_DEPRECATED QFont font() const SIP_DEPRECATED;
344
350 Q_DECL_DEPRECATED void setFont( const QFont &font ) SIP_DEPRECATED;
351
358 Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED;
359
366 Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED;
367
374 Q_DECL_DEPRECATED QColor fillColor() const SIP_DEPRECATED;
375
382 Q_DECL_DEPRECATED void setFillColor( const QColor &color ) SIP_DEPRECATED;
383
390 Q_DECL_DEPRECATED QColor fillColor2() const SIP_DEPRECATED;
391
398 Q_DECL_DEPRECATED void setFillColor2( const QColor &color ) SIP_DEPRECATED;
399
405 Q_DECL_DEPRECATED QColor lineColor() const SIP_DEPRECATED;
406
412 Q_DECL_DEPRECATED void setLineColor( const QColor &color ) SIP_DEPRECATED;
413
419 Q_DECL_DEPRECATED double lineWidth() const SIP_DEPRECATED;
420
426 Q_DECL_DEPRECATED void setLineWidth( double width ) SIP_DEPRECATED;
427
433 Q_DECL_DEPRECATED QPen pen() const SIP_DEPRECATED;
434
442 Q_DECL_DEPRECATED QBrush brush() const SIP_DEPRECATED;
443
451 Q_DECL_DEPRECATED QBrush brush2() const SIP_DEPRECATED;
452
457 double height() const { return mSettings.height(); }
458
463 void setHeight( double height ) { mSettings.setHeight( height ); }
464
469 void setLinkedMap( QgsLayoutItemMap *map );
470
475 QgsLayoutItemMap *linkedMap() const { return mMap; }
476
481 double labelBarSpace() const { return mSettings.labelBarSpace(); }
482
487 void setLabelBarSpace( double space ) {mSettings.setLabelBarSpace( space );}
488
493 double boxContentSpace() const { return mSettings.boxContentSpace(); }
494
499 void setBoxContentSpace( double space );
500
506 QgsScaleBarSettings::LabelVerticalPlacement labelVerticalPlacement() const { return mSettings.labelVerticalPlacement(); }
507
513 void setLabelVerticalPlacement( QgsScaleBarSettings::LabelVerticalPlacement placement );
514
520 QgsScaleBarSettings::LabelHorizontalPlacement labelHorizontalPlacement() const { return mSettings.labelHorizontalPlacement(); }
521
527 void setLabelHorizontalPlacement( QgsScaleBarSettings::LabelHorizontalPlacement placement );
528
533 QgsScaleBarSettings::Alignment alignment() const { return mSettings.alignment(); }
534
539 void setAlignment( QgsScaleBarSettings::Alignment alignment );
540
545 Qgis::DistanceUnit units() const { return mSettings.units(); }
546
551 void setUnits( Qgis::DistanceUnit units );
552
558 Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const SIP_DEPRECATED;
559
565 Q_DECL_DEPRECATED void setLineJoinStyle( Qt::PenJoinStyle style ) SIP_DEPRECATED;
566
572 Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const SIP_DEPRECATED;
573
579 Q_DECL_DEPRECATED void setLineCapStyle( Qt::PenCapStyle style ) SIP_DEPRECATED;
580
585 void applyDefaultSettings();
586
594 bool applyDefaultRendererSettings( QgsScaleBarRenderer *renderer );
595
603 Qgis::DistanceUnit guessUnits() const;
604
609 void applyDefaultSize( Qgis::DistanceUnit units = Qgis::DistanceUnit::Meters );
610
614 void resizeToMinimumWidth();
615
625 void setStyle( const QString &name );
626
631 QString style() const;
632
639 const QgsNumericFormat *numericFormat() const;
640
649 void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
650
654 void update();
655
656 void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::DataDefinedProperty::AllProperties ) override;
657 void finalizeRestoreFromXml() override;
658 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
659 ExportLayerBehavior exportLayerBehavior() const override;
660
661 protected:
662
663 void draw( QgsLayoutItemRenderContext &context ) override;
664 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
665 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
666
667 private slots:
668 void updateScale();
669 void disconnectCurrentMap();
670
671 private:
672
674 QgsLayoutItemMap *mMap = nullptr;
675 QString mMapUuid;
676
677 QgsScaleBarSettings mSettings;
678
680 std::unique_ptr< QgsScaleBarRenderer > mStyle;
681
683 double mSegmentMillimeters = 0.0;
684
686 void refreshSegmentMillimeters();
687
689 double mapWidth() const;
690
691 QgsScaleBarRenderer::ScaleBarContext createScaleContext() const;
692
694
699 void refreshUnitsPerSegment( const QgsExpressionContext *context = nullptr );
700
705 void refreshNumberOfSegmentsLeft( const QgsExpressionContext *context = nullptr );
706
711 void refreshNumberOfSegmentsRight( const QgsExpressionContext *context = nullptr );
712
717 void refreshMinimumBarWidth( const QgsExpressionContext *context = nullptr );
718
723 void refreshMaximumBarWidth( const QgsExpressionContext *context = nullptr );
724};
725
726#endif //QGSLAYOUTITEMSCALEBAR_H
727
728
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:54
DistanceUnit
Units of distance.
Definition: qgis.h:4124
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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:43
A layout item subclass for scale bars.
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.
Qgis::DistanceUnit units() const
Returns the distance units used by the scalebar.
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
QgsLayoutItemMap * linkedMap() const
Returns the map item linked to the scalebar.
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...
Base class for graphical items within a QgsLayout.
virtual QIcon icon() const
Returns the item's icon.
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...
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:40
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
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
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:73
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76