QGIS API Documentation 3.41.0-Master (25ec5511245)
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"
40
41class QPainter;
42
47
56class CORE_EXPORT QgsLabelBlockingRegion
57{
58 public:
59
63 explicit QgsLabelBlockingRegion( const QgsGeometry &geometry )
64 : geometry( geometry )
65 {}
66
69
70};
71
72
90class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
91{
92 public:
94
105 QgsRectangle extent() const;
106
117 void setExtent( const QgsRectangle &rect, bool magnified = true );
118
125 double extentBuffer() const;
126
133 void setExtentBuffer( double buffer );
134
141 QSize outputSize() const;
142
148 void setOutputSize( QSize size );
149
156 float devicePixelRatio() const;
157
164 void setDevicePixelRatio( float dpr );
165
178 QSize deviceOutputSize() const;
179
184 double rotation() const;
185
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
232 void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
233
238 double magnificationFactor() const;
239
251 QStringList layerIds( bool expandGroupLayers = false ) const;
252
264 QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;
265
266
267#ifndef SIP_RUN
274 template <typename T>
275 QVector<T> layers() const;
276#endif
277
288 void setLayers( const QList<QgsMapLayer *> &layers );
289
295 QMap<QString, QString> layerStyleOverrides() const;
296
302 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
303
310 Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
311
318 Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
319
326 QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
327
335 void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
336
343 void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
344
350 void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
351
357 QgsCoordinateReferenceSystem destinationCrs() const;
358
362 Qgis::DistanceUnit mapUnits() const;
363
371 bool setEllipsoid( const QString &ellipsoid );
372
378 QString ellipsoid() const { return mEllipsoid; }
379
385 void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
386
392 QColor backgroundColor() const { return mBackgroundColor; }
393
399 void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
400
406 QColor selectionColor() const { return mSelectionColor; }
407
409 void setFlags( Qgis::MapSettingsFlags flags );
411 void setFlag( Qgis::MapSettingsFlag flag, bool on = true );
413 Qgis::MapSettingsFlags flags() const;
415 bool testFlag( Qgis::MapSettingsFlag flag ) const;
416
424 {
425 return mTextRenderFormat;
426 }
427
438 {
439 mTextRenderFormat = format;
440 // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
441 // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
442 mLabelingEngineSettings.setDefaultTextRenderFormat( format );
443 }
444
446 void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
448 QImage::Format outputImageFormat() const { return mImageFormat; }
449
451 bool hasValidSettings() const;
453 QgsRectangle visibleExtent() const;
454
458 QPolygonF visiblePolygon() const;
459
465 QPolygonF visiblePolygonWithBuffer() const;
466
468 double mapUnitsPerPixel() const;
469
474 double scale() const;
475
481 void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
482
488 const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
489
497 QgsCoordinateTransformContext transformContext() const;
498
506 void setTransformContext( const QgsCoordinateTransformContext &context );
507
514 const QgsPathResolver &pathResolver() const { return mPathResolver; }
515
522 void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
523
524 const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
525
531 double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
532
538 QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
539
545 QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
546
551 QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
552
558 QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
559
565 QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
566
571 QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
572
578 QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
579
585 QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
586
591 QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
592
603 QgsRectangle computeExtentForScale( const QgsPointXY &center, double scale ) const;
604
613 double computeScaleForExtent( const QgsRectangle &extent ) const;
614
616 QgsRectangle fullExtent() const;
617
623 void readXml( QDomNode &node );
624
630 void writeXml( QDomNode &node, QDomDocument &doc );
631
636 void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
638 double segmentationTolerance() const { return mSegmentationTolerance; }
639
644 void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
647
658 {
659 mLabelingEngineSettings = settings;
660 mTextRenderFormat = settings.defaultTextRenderFormat();
661 }
662
669 const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
670
682 QgsGeometry labelBoundaryGeometry() const;
683
697 void setLabelBoundaryGeometry( const QgsGeometry &boundary );
698
705 void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
706
713 QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
714
723 void addClippingRegion( const QgsMapClippingRegion &region );
724
733 void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
734
743 QList< QgsMapClippingRegion > clippingRegions() const;
744
761 void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
762
774 const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
775
783 const QgsMaskRenderSettings &maskSettings() const SIP_SKIP { return mMaskRenderSettings; }
784
792 QgsMaskRenderSettings &maskSettings() { return mMaskRenderSettings; }
793
801 void setMaskSettings( const QgsMaskRenderSettings &settings );
802
812 void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
813
819 QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
820
827 QgsDoubleRange zRange() const;
828
835 void setZRange( const QgsDoubleRange &range );
836
843 Qgis::RendererUsage rendererUsage() const;
844
854 void setRendererUsage( Qgis::RendererUsage rendererUsage );
855
864 double frameRate() const;
865
874 void setFrameRate( double rate );
875
884 long long currentFrame() const;
885
894 void setCurrentFrame( long long frame );
895
902 const QgsElevationShadingRenderer &elevationShadingRenderer() const;
903
910 void setElevationShadingRenderer( const QgsElevationShadingRenderer &renderer );
911
912 protected:
913
914 double mDpi = 96.0;
915 double mDpiTarget = -1;
916
917 QSize mSize;
918 float mDevicePixelRatio = 1.0;
919
921 double mExtentBuffer = 0.0;
922
923 double mRotation = 0.0;
924 double mMagnificationFactor = 1.0;
925
928 QMap<QString, QString> mLayerStyleOverrides;
932
935 QString mEllipsoid;
936
939
941
942 QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
943
946
948
949 // derived properties
951 bool mValid = false;
954 double mMapUnitsPerPixel = 1;
955 double mScale = 1;
956
957 // utiity stuff
960
962
964
966
968
970
972
974
975 double mFrameRate = -1;
976 long long mCurrentFrame = -1;
977
979
980#ifdef QGISDEBUG
981 bool mHasTransformContext = false;
982#endif
983
984 void updateDerived();
985
986 private:
987
988 QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
989 QList< QgsMapClippingRegion > mClippingRegions;
990 QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
991
992 QgsDoubleRange mZRange;
993
994};
995
996#endif // QGSMAPSETTINGS_H
QFlags< MapSettingsFlag > MapSettingsFlags
Map settings flags.
Definition qgis.h:2556
DistanceUnit
Units of distance.
Definition qgis.h:4669
TextRenderFormat
Options for rendering text.
Definition qgis.h:2624
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
RendererUsage
Usage of the renderer.
Definition qgis.h:3188
@ Unknown
Renderer used for unknown usage.
MapSettingsFlag
Flags which adjust the way maps are rendered.
Definition qgis.h:2534
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:231
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:76
Abstract base class for map rendering implementations.
The QgsMapSettings class contains configuration for rendering of the map.
QgsVectorSimplifyMethod mSimplifyMethod
QgsMaskRenderSettings mMaskRenderSettings
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...
QgsMaskRenderSettings & maskSettings()
Returns a reference to the mask render settings, which control how masks are drawn and behave during ...
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.
const QgsMaskRenderSettings & maskSettings() const
Returns a reference to the mask render settings, which control how masks are drawn and behave during ...
double mSegmentationTolerance
Perform transforms between map coordinates and device coordinates.
Contains settings regarding how masks are calculated and handled during a map render.
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.
#define SIP_SKIP
Definition qgis_sip.h:126
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
const QgsCoordinateReferenceSystem & crs