QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "qgsscalebarrenderer.h"
23#include "qgsscalebarsettings.h"
24
25#include <QColor>
26#include <QFont>
27#include <QPen>
28
30
35class 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
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 Qgis::ScaleBarSegmentSizeMode segmentSizeMode() const { return mSettings.segmentSizeMode(); }
140
147 void setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode 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 Qgis::ScaleBarDistanceLabelVerticalPlacement labelVerticalPlacement() const { return mSettings.labelVerticalPlacement(); }
508
514 void setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement placement );
515
521 Qgis::ScaleBarDistanceLabelHorizontalPlacement labelHorizontalPlacement() const { return mSettings.labelHorizontalPlacement(); }
522
528 void setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement placement );
529
534 Qgis::ScaleBarAlignment alignment() const { return mSettings.alignment(); }
535
540 void setAlignment( Qgis::ScaleBarAlignment alignment );
541
546 Qgis::DistanceUnit units() const { return mSettings.units(); }
547
552 void setUnits( Qgis::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 Qgis::DistanceUnit guessUnits() const;
605
610 void applyDefaultSize( Qgis::DistanceUnit units = Qgis::DistanceUnit::Meters );
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
658 Qgis::ScaleCalculationMethod method() const;
659
666 void setMethod( Qgis::ScaleCalculationMethod method );
667
671 void update();
672
673 void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::DataDefinedProperty::AllProperties ) override;
674 void finalizeRestoreFromXml() override;
675 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
676 ExportLayerBehavior exportLayerBehavior() const override;
677
678 protected:
679
680 void draw( QgsLayoutItemRenderContext &context ) override;
681 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
682 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
683
684 private slots:
685 void updateScale();
686 void disconnectCurrentMap();
687
688 private:
689
691 QgsLayoutItemMap *mMap = nullptr;
692 QString mMapUuid;
693
694 QgsScaleBarSettings mSettings;
695 Qgis::ScaleCalculationMethod mMethod = Qgis::ScaleCalculationMethod::HorizontalAverage;
696
698 std::unique_ptr< QgsScaleBarRenderer > mStyle;
699
701 double mSegmentMillimeters = 0.0;
702
704 void refreshSegmentMillimeters();
705
707 double mapWidth() const;
708
709 QgsScaleBarRenderer::ScaleBarContext createScaleContext() const;
710
712
717 void refreshUnitsPerSegment( const QgsExpressionContext *context = nullptr );
718
723 void refreshNumberOfSegmentsLeft( const QgsExpressionContext *context = nullptr );
724
729 void refreshNumberOfSegmentsRight( const QgsExpressionContext *context = nullptr );
730
735 void refreshMinimumBarWidth( const QgsExpressionContext *context = nullptr );
736
741 void refreshMaximumBarWidth( const QgsExpressionContext *context = nullptr );
742};
743
744#endif //QGSLAYOUTITEMSCALEBAR_H
745
746
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
ScaleBarDistanceLabelHorizontalPlacement
Scale bar distance label horizontal placement.
Definition qgis.h:5345
ScaleBarDistanceLabelVerticalPlacement
Scale bar distance label vertical placement.
Definition qgis.h:5331
ScaleBarAlignment
Scalebar alignment.
Definition qgis.h:5302
DistanceUnit
Units of distance.
Definition qgis.h:5013
ScaleBarSegmentSizeMode
Modes for setting size for scale bar segments.
Definition qgis.h:5317
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.
double height() const
Returns the scalebar height (in millimeters).
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.
static QgsLayoutItemScaleBar * create(QgsLayout *layout)
Returns a new scale bar item for the specified layout.
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...
QgsLayoutItemScaleBar(QgsLayout *layout)
Constructor for QgsLayoutItemScaleBar, with the specified parent layout.
friend class QgsLayout
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
virtual QIcon icon() const
Returns the item's icon.
friend class QgsLayoutItemMap
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.
const QgsLayout * layout() const
Returns the layout the object is attached to.
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
A line symbol type, for rendering LineString and MultiLineString geometries.
Abstract base class for numeric formatters, which allow for formatting a numeric value for display.
A container for the context for various read/write operations on objects.
Abstract base class for scale bar renderers.
Stores the appearance and layout settings for scalebar drawing with QgsScaleBarRenderer.
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:114
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84