QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
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"
39
40class QPainter;
41
46
55class CORE_EXPORT QgsLabelBlockingRegion
56{
57 public:
58
62 explicit QgsLabelBlockingRegion( const QgsGeometry &geometry )
63 : geometry( geometry )
64 {}
65
68
69};
70
71
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
182 double rotation() const;
183
188 void setRotation( double rotation );
189
197 double outputDpi() const;
198
204 void setOutputDpi( double dpi );
205
214 double dpiTarget() const;
215
222 void setDpiTarget( double dpi );
223
230 void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
231
236 double magnificationFactor() const;
237
249 QStringList layerIds( bool expandGroupLayers = false ) const;
250
262 QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;
263
274 void setLayers( const QList<QgsMapLayer *> &layers );
275
281 QMap<QString, QString> layerStyleOverrides() const;
282
288 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
289
296 Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
297
304 Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
305
312 QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
313
321 void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
322
329 void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
330
336 void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
337
343 QgsCoordinateReferenceSystem destinationCrs() const;
344
348 Qgis::DistanceUnit mapUnits() const;
349
357 bool setEllipsoid( const QString &ellipsoid );
358
364 QString ellipsoid() const { return mEllipsoid; }
365
371 void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
372
378 QColor backgroundColor() const { return mBackgroundColor; }
379
385 void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
386
392 QColor selectionColor() const { return mSelectionColor; }
393
395 void setFlags( Qgis::MapSettingsFlags flags );
397 void setFlag( Qgis::MapSettingsFlag flag, bool on = true );
399 Qgis::MapSettingsFlags flags() const;
401 bool testFlag( Qgis::MapSettingsFlag flag ) const;
402
410 {
411 return mTextRenderFormat;
412 }
413
424 {
425 mTextRenderFormat = format;
426 // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
427 // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
428 mLabelingEngineSettings.setDefaultTextRenderFormat( format );
429 }
430
432 void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
434 QImage::Format outputImageFormat() const { return mImageFormat; }
435
437 bool hasValidSettings() const;
439 QgsRectangle visibleExtent() const;
440
444 QPolygonF visiblePolygon() const;
445
451 QPolygonF visiblePolygonWithBuffer() const;
452
454 double mapUnitsPerPixel() const;
455
460 double scale() const;
461
467 void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
468
474 const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
475
483 QgsCoordinateTransformContext transformContext() const;
484
492 void setTransformContext( const QgsCoordinateTransformContext &context );
493
500 const QgsPathResolver &pathResolver() const { return mPathResolver; }
501
508 void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
509
510 const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
511
517 double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
518
524 QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
525
531 QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
532
537 QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
538
544 QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
545
551 QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
552
557 QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
558
564 QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
565
571 QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
572
577 QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
578
589 QgsRectangle computeExtentForScale( const QgsPointXY &center, double scale ) const;
590
599 double computeScaleForExtent( const QgsRectangle &extent ) const;
600
602 QgsRectangle fullExtent() const;
603
604 /* serialization */
605
606 void readXml( QDomNode &node );
607
608 void writeXml( QDomNode &node, QDomDocument &doc );
609
614 void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
616 double segmentationTolerance() const { return mSegmentationTolerance; }
617
622 void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
625
636 {
637 mLabelingEngineSettings = settings;
638 mTextRenderFormat = settings.defaultTextRenderFormat();
639 }
640
647 const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
648
660 QgsGeometry labelBoundaryGeometry() const;
661
675 void setLabelBoundaryGeometry( const QgsGeometry &boundary );
676
683 void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
684
691 QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
692
701 void addClippingRegion( const QgsMapClippingRegion &region );
702
711 void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
712
721 QList< QgsMapClippingRegion > clippingRegions() const;
722
739 void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
740
752 const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
753
763 void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
764
770 QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
771
778 QgsDoubleRange zRange() const;
779
786 void setZRange( const QgsDoubleRange &range );
787
794 Qgis::RendererUsage rendererUsage() const;
795
805 void setRendererUsage( Qgis::RendererUsage rendererUsage );
806
815 double frameRate() const;
816
825 void setFrameRate( double rate );
826
835 long long currentFrame() const;
836
845 void setCurrentFrame( long long frame );
846
853 const QgsElevationShadingRenderer &elevationShadingRenderer() const;
854
861 void setElevationShadingRenderer( const QgsElevationShadingRenderer &renderer );
862
863 protected:
864
865 double mDpi = 96.0;
866 double mDpiTarget = -1;
867
868 QSize mSize;
869 float mDevicePixelRatio = 1.0;
870
872 double mExtentBuffer = 0.0;
873
874 double mRotation = 0.0;
875 double mMagnificationFactor = 1.0;
876
879 QMap<QString, QString> mLayerStyleOverrides;
883
886 QString mEllipsoid;
887
890
891 Qgis::MapSettingsFlags mFlags;
892
893 QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
894
897
899
900 // derived properties
902 bool mValid = false;
905 double mMapUnitsPerPixel = 1;
906 double mScale = 1;
907
908 // utiity stuff
911
913
915
917
919
921
923
925
926 double mFrameRate = -1;
927 long long mCurrentFrame = -1;
928
929#ifdef QGISDEBUG
930 bool mHasTransformContext = false;
931#endif
932
933 void updateDerived();
934
935 private:
936
937 QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
938 QList< QgsMapClippingRegion > mClippingRegions;
939 QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
940
941 QgsDoubleRange mZRange;
942
943};
944
945#endif // QGSMAPSETTINGS_H
DistanceUnit
Units of distance.
Definition qgis.h:4062
TextRenderFormat
Flags which control how map layer renderers behave.
Definition qgis.h:2287
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
RendererUsage
Usage of the renderer.
Definition qgis.h:2781
@ Unknown
Renderer used for unknown usage.
MapSettingsFlag
Coordinate transformation flags.
Definition qgis.h:2201
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:201
This class can render elevation shading on an image with different methods (eye dome lighting,...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A geometry is the spatial representation of a feature.
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:75
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.
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
QgsElevationShadingRenderer mShadingRenderer
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.
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.
Resolves relative paths into absolute paths and vice versa.
A class to represent a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A rectangle specified with double values.
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.
This class contains information how to simplify geometries fetched from a vector layer.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
const QgsCoordinateReferenceSystem & crs