QGIS API Documentation 3.29.0-Master (ade4f0cf0f)
qgsmapsettings.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmapsettings.h
3 --------------------------------------
4 Date : December 2013
5 Copyright : (C) 2013 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSMAPSETTINGS_H
17#define QGSMAPSETTINGS_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include <QColor>
22#include <QImage>
23#include <QPointer>
24#include <QSize>
25#include <QStringList>
26
29#include "qgsmaptopixel.h"
30#include "qgsrectangle.h"
31#include "qgsscalecalculator.h"
33#include "qgsmaplayer.h"
34#include "qgsgeometry.h"
38
39class QPainter;
40
45
54class CORE_EXPORT QgsLabelBlockingRegion
55{
56 public:
57
61 explicit QgsLabelBlockingRegion( const QgsGeometry &geometry )
62 : geometry( geometry )
63 {}
64
67
68};
69
70
88class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
89{
90 public:
92
103 QgsRectangle extent() const;
104
115 void setExtent( const QgsRectangle &rect, bool magnified = true );
116
123 double extentBuffer() const;
124
131 void setExtentBuffer( double buffer );
132
139 QSize outputSize() const;
140
146 void setOutputSize( QSize size );
147
154 float devicePixelRatio() const;
155
162 void setDevicePixelRatio( float dpr );
163
176 QSize deviceOutputSize() const;
177
183 double rotation() const;
184
190 void setRotation( double rotation );
191
199 double outputDpi() const;
200
206 void setOutputDpi( double dpi );
207
216 double dpiTarget() const;
217
224 void setDpiTarget( double dpi );
225
233 void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
234
240 double magnificationFactor() const;
241
253 QStringList layerIds( bool expandGroupLayers = false ) const;
254
266 QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;
267
278 void setLayers( const QList<QgsMapLayer *> &layers );
279
286 QMap<QString, QString> layerStyleOverrides() const;
287
294 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
295
303 Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
304
312 Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
313
320 QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
321
329 void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
330
337 void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
338
344 void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
345
351 QgsCoordinateReferenceSystem destinationCrs() const;
352
356 QgsUnitTypes::DistanceUnit mapUnits() const;
357
366 bool setEllipsoid( const QString &ellipsoid );
367
374 QString ellipsoid() const { return mEllipsoid; }
375
381 void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
382
388 QColor backgroundColor() const { return mBackgroundColor; }
389
395 void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
396
402 QColor selectionColor() const { return mSelectionColor; }
403
405 void setFlags( Qgis::MapSettingsFlags flags );
407 void setFlag( Qgis::MapSettingsFlag flag, bool on = true );
409 Qgis::MapSettingsFlags flags() const;
411 bool testFlag( Qgis::MapSettingsFlag flag ) const;
412
420 {
421 return mTextRenderFormat;
422 }
423
434 {
435 mTextRenderFormat = format;
436 // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
437 // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
438 mLabelingEngineSettings.setDefaultTextRenderFormat( format );
439 }
440
442 void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
444 QImage::Format outputImageFormat() const { return mImageFormat; }
445
447 bool hasValidSettings() const;
449 QgsRectangle visibleExtent() const;
450
455 QPolygonF visiblePolygon() const;
456
462 QPolygonF visiblePolygonWithBuffer() const;
463
465 double mapUnitsPerPixel() const;
466
471 double scale() const;
472
479 void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
480
487 const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
488
497 QgsCoordinateTransformContext transformContext() const;
498
507 void setTransformContext( const QgsCoordinateTransformContext &context );
508
516 const QgsPathResolver &pathResolver() const { return mPathResolver; }
517
525 void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
526
527 const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
528
535 double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
536
542 QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
543
549 QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
550
555 QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
556
562 QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
563
569 QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
570
575 QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
576
582 QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
583
589 QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
590
595 QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
596
607 QgsRectangle computeExtentForScale( const QgsPointXY &center, double scale ) const;
608
617 double computeScaleForExtent( const QgsRectangle &extent ) const;
618
620 QgsRectangle fullExtent() const;
621
622 /* serialization */
623
624 void readXml( QDomNode &node );
625
626 void writeXml( QDomNode &node, QDomDocument &doc );
627
632 void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
634 double segmentationTolerance() const { return mSegmentationTolerance; }
635
640 void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
643
655 {
656 mLabelingEngineSettings = settings;
657 mTextRenderFormat = settings.defaultTextRenderFormat();
658 }
659
667 const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
668
680 QgsGeometry labelBoundaryGeometry() const;
681
695 void setLabelBoundaryGeometry( const QgsGeometry &boundary );
696
703 void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
704
711 QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
712
721 void addClippingRegion( const QgsMapClippingRegion &region );
722
731 void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
732
741 QList< QgsMapClippingRegion > clippingRegions() const;
742
759 void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
760
772 const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
773
783 void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
784
790 QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
791
798 QgsDoubleRange zRange() const;
799
806 void setZRange( const QgsDoubleRange &range );
807
814 Qgis::RendererUsage rendererUsage() const;
815
825 void setRendererUsage( Qgis::RendererUsage rendererUsage );
826
835 double frameRate() const;
836
845 void setFrameRate( double rate );
846
855 long long currentFrame() const;
856
865 void setCurrentFrame( long long frame );
866
867 protected:
868
869 double mDpi = 96.0;
870 double mDpiTarget = -1;
871
872 QSize mSize;
873 float mDevicePixelRatio = 1.0;
874
876 double mExtentBuffer = 0.0;
877
878 double mRotation = 0.0;
879 double mMagnificationFactor = 1.0;
880
883 QMap<QString, QString> mLayerStyleOverrides;
887
890 QString mEllipsoid;
891
894
895 Qgis::MapSettingsFlags mFlags;
896
897 QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
898
901
903
904 // derived properties
906 bool mValid = false;
909 double mMapUnitsPerPixel = 1;
910 double mScale = 1;
911
912 // utiity stuff
915
917
919
920 Qgis::TextRenderFormat mTextRenderFormat = Qgis::TextRenderFormat::AlwaysOutlines;
921
923
925
927
928 double mFrameRate = -1;
929 long long mCurrentFrame = -1;
930
931#ifdef QGISDEBUG
932 bool mHasTransformContext = false;
933#endif
934
935 void updateDerived();
936
937 private:
938
939 QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
940 QList< QgsMapClippingRegion > mClippingRegions;
941 QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
942
943 QgsDoubleRange mZRange;
944
945};
946
947#endif // QGSMAPSETTINGS_H
TextRenderFormat
Options for rendering text.
Definition: qgis.h:1557
RendererUsage
Usage of the renderer.
Definition: qgis.h:2024
@ Unknown
Renderer used for unknown usage.
MapSettingsFlag
Coordinate transformation flags.
Definition: qgis.h:1493
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices)
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
QgsRange which stores a range of double values.
Definition: qgsrange.h:203
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Label blocking region (in map coordinates and CRS).
QgsGeometry geometry
Geometry of region to avoid placing labels within (in destination map coordinates and CRS)
QgsLabelBlockingRegion(const QgsGeometry &geometry)
Constructor for a label blocking region.
Stores global configuration for labeling engine.
Qgis::TextRenderFormat defaultTextRenderFormat() const
Returns the default text rendering format for the labels.
A map clipping region (in map coordinates and CRS).
Base class for all map layer types.
Definition: qgsmaplayer.h:73
Abstract base class for map rendering implementations.
The QgsMapSettings class contains configuration for rendering of the map.
QgsVectorSimplifyMethod mSimplifyMethod
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
QColor mBackgroundColor
void setSelectionColor(const QColor &color)
Sets the color that is used for drawing of selected vector features.
void setSimplifyMethod(const QgsVectorSimplifyMethod &method)
Sets the simplification setting to use when rendering vector layers.
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
Q_DECL_DEPRECATED void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
void setTextRenderFormat(Qgis::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
void clearCustomRenderingFlag(const QString &flag)
Clears the specified custom rendering flag.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
Qgis::MapSettingsFlags mFlags
QString mCustomRenderFlags
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
QgsLabelingEngineSettings mLabelingEngineSettings
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
QColor backgroundColor() const
Returns the background color of the map.
const QgsMapToPixel & mapToPixel() const
void setCustomRenderingFlag(const QString &flag, const QVariant &value)
Sets a custom rendering flag.
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
QgsRectangle mExtent
QMap< QString, QString > mLayerStyleOverrides
QList< QgsLabelBlockingRegion > labelBlockingRegions() const
Returns the list of regions to avoid placing labels within.
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
QgsGeometry mLabelBoundaryGeometry
QgsCoordinateTransformContext mTransformContext
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
QgsPathResolver mPathResolver
QgsScaleCalculator mScaleCalculator
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QVariantMap mCustomRenderingFlags
QgsExpressionContext mExpressionContext
QColor selectionColor() const
Returns the color that is used for drawing of selected vector features.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
QVariantMap customRenderingFlags() const
Returns any custom rendering flags.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
Q_DECL_DEPRECATED QString customRenderFlags() const
Returns custom rendering flags.
QString ellipsoid() const
Returns ellipsoid's acronym.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
Qgis::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
QgsCoordinateReferenceSystem mDestCRS
QgsMapToPixel mMapToPixel
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
void setLabelBlockingRegions(const QList< QgsLabelBlockingRegion > &regions)
Sets a list of regions to avoid placing labels within.
QColor mSelectionColor
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
const QgsExpressionContext & expressionContext() const
Gets the expression context.
double mSegmentationTolerance
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
Resolves relative paths into absolute paths and vice versa.
A class to represent a 2D point.
Definition: qgspointxy.h:59
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
A rectangle specified with double values.
Definition: qgsrectangle.h:42
An interface for classes which provider custom handlers for features rendered as part of a map render...
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
Base class for objects with an associated (optional) temporal range.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
This class contains information how to simplify geometries fetched from a vector layer.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2187
const QgsCoordinateReferenceSystem & crs