QGIS API Documentation 3.41.0-Master (d5b93354e9c)
Loading...
Searching...
No Matches
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 Qgis::ScaleBarSegmentSizeMode segmentSizeMode() const { return mSettings.segmentSizeMode(); }
139
146 void setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode 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 Qgis::ScaleBarDistanceLabelVerticalPlacement labelVerticalPlacement() const { return mSettings.labelVerticalPlacement(); }
507
513 void setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement placement );
514
520 Qgis::ScaleBarDistanceLabelHorizontalPlacement labelHorizontalPlacement() const { return mSettings.labelHorizontalPlacement(); }
521
527 void setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement placement );
528
533 Qgis::ScaleBarAlignment alignment() const { return mSettings.alignment(); }
534
539 void setAlignment( Qgis::ScaleBarAlignment 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
657 Qgis::ScaleCalculationMethod method() const;
658
665 void setMethod( Qgis::ScaleCalculationMethod method );
666
670 void update();
671
672 void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::DataDefinedProperty::AllProperties ) override;
673 void finalizeRestoreFromXml() override;
674 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
675 ExportLayerBehavior exportLayerBehavior() const override;
676
677 protected:
678
679 void draw( QgsLayoutItemRenderContext &context ) override;
680 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
681 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
682
683 private slots:
684 void updateScale();
685 void disconnectCurrentMap();
686
687 private:
688
690 QgsLayoutItemMap *mMap = nullptr;
691 QString mMapUuid;
692
693 QgsScaleBarSettings mSettings;
694 Qgis::ScaleCalculationMethod mMethod = Qgis::ScaleCalculationMethod::HorizontalAverage;
695
697 std::unique_ptr< QgsScaleBarRenderer > mStyle;
698
700 double mSegmentMillimeters = 0.0;
701
703 void refreshSegmentMillimeters();
704
706 double mapWidth() const;
707
708 QgsScaleBarRenderer::ScaleBarContext createScaleContext() const;
709
711
716 void refreshUnitsPerSegment( const QgsExpressionContext *context = nullptr );
717
722 void refreshNumberOfSegmentsLeft( const QgsExpressionContext *context = nullptr );
723
728 void refreshNumberOfSegmentsRight( const QgsExpressionContext *context = nullptr );
729
734 void refreshMinimumBarWidth( const QgsExpressionContext *context = nullptr );
735
740 void refreshMaximumBarWidth( const QgsExpressionContext *context = nullptr );
741};
742
743#endif //QGSLAYOUTITEMSCALEBAR_H
744
745
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
ScaleBarDistanceLabelHorizontalPlacement
Scale bar distance label horizontal placement.
Definition qgis.h:5018
ScaleBarDistanceLabelVerticalPlacement
Scale bar distance label vertical placement.
Definition qgis.h:5004
ScaleBarAlignment
Scalebar alignment.
Definition qgis.h:4975
DistanceUnit
Units of distance.
Definition qgis.h:4722
ScaleBarSegmentSizeMode
Modes for setting size for scale bar segments.
Definition qgis.h:4990
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.
Layout graphical items for displaying a map.
Contains settings and helpers relating to a render of a QgsLayoutItem.
A layout item subclass for scale bars.
Qgis::ScaleBarSegmentSizeMode 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.
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.
Qgis::ScaleBarAlignment alignment() const
Returns the scalebar alignment.
Qgis::ScaleBarDistanceLabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
Qgis::ScaleBarDistanceLabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
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...
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...
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.
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...
An interface for classes which can visit style entity (e.g.
Container for all settings relating to text rendering.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76