QGIS API Documentation 3.99.0-Master (c03dd32cbdd)
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"
24#include "qgsgeometry.h"
27#include "qgsmaplayer.h"
28#include "qgsmaptopixel.h"
30#include "qgsrectangle.h"
31#include "qgsscalecalculator.h"
35
36#include <QColor>
37#include <QImage>
38#include <QPointer>
39#include <QSize>
40#include <QStringList>
41
42class QPainter;
43
49
58class CORE_EXPORT QgsLabelBlockingRegion
59{
60 public:
61
68
71
72};
73
74
92class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
93{
94 public:
96
107 QgsRectangle extent() const;
108
119 void setExtent( const QgsRectangle &rect, bool magnified = true );
120
127 double extentBuffer() const;
128
135 void setExtentBuffer( double buffer );
136
143 QSize outputSize() const;
144
150 void setOutputSize( QSize size );
151
158 float devicePixelRatio() const;
159
166 void setDevicePixelRatio( float dpr );
167
180 QSize deviceOutputSize() const;
181
186 double rotation() const;
187
192 void setRotation( double rotation );
193
201 double outputDpi() const;
202
208 void setOutputDpi( double dpi );
209
218 double dpiTarget() const;
219
226 void setDpiTarget( double dpi );
227
234 void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
235
240 double magnificationFactor() const;
241
253 QStringList layerIds( bool expandGroupLayers = false ) const;
254
266 QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;
267
268
269#ifndef SIP_RUN
276 template <typename T>
277 QVector<T> layers() const;
278#endif
279
290 void setLayers( const QList<QgsMapLayer *> &layers );
291
297 QMap<QString, QString> layerStyleOverrides() const;
298
304 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
305
312 Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
313
320 Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
321
328 QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
329
337 void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
338
345 void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
346
352 void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
353
359 QgsCoordinateReferenceSystem destinationCrs() const;
360
364 Qgis::DistanceUnit mapUnits() const;
365
372 Qgis::ScaleCalculationMethod scaleMethod() const;
373
380 void setScaleMethod( Qgis::ScaleCalculationMethod method );
381
389 bool setEllipsoid( const QString &ellipsoid );
390
396 QString ellipsoid() const { return mEllipsoid; }
397
403 void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
404
410 QColor backgroundColor() const { return mBackgroundColor; }
411
417 void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
418
424 QColor selectionColor() const { return mSelectionColor; }
425
427 void setFlags( Qgis::MapSettingsFlags flags );
429 void setFlag( Qgis::MapSettingsFlag flag, bool on = true );
431 Qgis::MapSettingsFlags flags() const;
433 bool testFlag( Qgis::MapSettingsFlag flag ) const;
434
445
456 {
457 mTextRenderFormat = format;
458 // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
459 // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
460 mLabelingEngineSettings.setDefaultTextRenderFormat( format );
461 }
462
464 void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
466 QImage::Format outputImageFormat() const { return mImageFormat; }
467
469 bool hasValidSettings() const;
471 QgsRectangle visibleExtent() const;
472
476 QPolygonF visiblePolygon() const;
477
483 QPolygonF visiblePolygonWithBuffer() const;
484
486 double mapUnitsPerPixel() const;
487
492 double scale() const;
493
500
507
515 QgsCoordinateTransformContext transformContext() const;
516
524 void setTransformContext( const QgsCoordinateTransformContext &context );
525
532 const QgsPathResolver &pathResolver() const { return mPathResolver; }
533
540 void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
541
542 const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
543
549 double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
550
556 QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
557
563 QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
564
569 QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
570
576 QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
577
583 QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
584
589 QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
590
596 QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
597
603 QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
604
609 QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
610
621 QgsRectangle computeExtentForScale( const QgsPointXY &center, double scale ) const;
622
631 double computeScaleForExtent( const QgsRectangle &extent ) const;
632
634 QgsRectangle fullExtent() const;
635
641 void readXml( QDomNode &node );
642
648 void writeXml( QDomNode &node, QDomDocument &doc );
649
654 void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
657
665
680
688
700 QgsGeometry labelBoundaryGeometry() const;
701
715 void setLabelBoundaryGeometry( const QgsGeometry &boundary );
716
723 void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
724
731 QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
732
741 void addClippingRegion( const QgsMapClippingRegion &region );
742
751 void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
752
761 QList< QgsMapClippingRegion > clippingRegions() const;
762
780
793
802
811
819 void setMaskSettings( const QgsMaskRenderSettings &settings );
820
830 void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
831
837 QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
838
845 QgsDoubleRange zRange() const;
846
853 void setZRange( const QgsDoubleRange &range );
854
861 Qgis::RendererUsage rendererUsage() const;
862
872 void setRendererUsage( Qgis::RendererUsage rendererUsage );
873
882 double frameRate() const;
883
892 void setFrameRate( double rate );
893
902 long long currentFrame() const;
903
912 void setCurrentFrame( long long frame );
913
920 const QgsElevationShadingRenderer &elevationShadingRenderer() const;
921
928 void setElevationShadingRenderer( const QgsElevationShadingRenderer &renderer );
929
936 Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const;
937
944 void setRasterizedRenderingPolicy( Qgis::RasterizedRenderingPolicy policy );
945
954 QHash< QString, QgsSelectiveMaskingSourceSet > selectiveMaskingSourceSets() const;
955
962 void setSelectiveMaskingSourceSets( const QVector< QgsSelectiveMaskingSourceSet > &sets );
963
964 protected:
965
966 double mDpi = 96.0;
967 double mDpiTarget = -1;
968
969 QSize mSize;
970 float mDevicePixelRatio = 1.0;
971
973 double mExtentBuffer = 0.0;
974
975 double mRotation = 0.0;
977
980 QStringList mLayerIds;
981 bool mHasGroupLayers = false;
982
983 QMap<QString, QString> mLayerStyleOverrides;
987
990 QString mEllipsoid;
991
994
997 QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
998
1001
1003
1004 // derived properties
1006 bool mValid = false;
1010 double mScale = 1;
1011
1012 // utiity stuff
1015
1017
1019
1021
1023
1025
1027
1029
1030 double mFrameRate = -1;
1031 long long mCurrentFrame = -1;
1032
1034
1035 QHash< QString, QgsSelectiveMaskingSourceSet > mSelectiveMaskingSourceSets;
1036
1037#ifdef QGISDEBUG
1038 bool mHasTransformContext = false;
1039#endif
1040
1041 void updateDerived();
1042
1043 private:
1044 void matchRasterizedRenderingPolicyToFlags();
1045
1046 QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
1047 QList< QgsMapClippingRegion > mClippingRegions;
1048 QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
1049
1050 QgsDoubleRange mZRange;
1051
1052};
1053
1054#endif // QGSMAPSETTINGS_H
RasterizedRenderingPolicy
Policies controlling when rasterisation of content during renders is permitted.
Definition qgis.h:2763
@ Default
Allow raster-based rendering in situations where it is required for correct rendering or where it wil...
Definition qgis.h:2764
QFlags< MapSettingsFlag > MapSettingsFlags
Map settings flags.
Definition qgis.h:2798
DistanceUnit
Units of distance.
Definition qgis.h:5122
TextRenderFormat
Options for rendering text.
Definition qgis.h:2886
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
Definition qgis.h:2887
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:5394
RendererUsage
Usage of the renderer.
Definition qgis.h:3518
@ Unknown
Renderer used for unknown usage.
Definition qgis.h:3521
MapSettingsFlag
Flags which adjust the way maps are rendered.
Definition qgis.h:2776
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).
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Handles coordinate transforms between two coordinate systems.
QgsRange which stores a range of double values.
Definition qgsrange.h:236
Renders elevation shading on an image with different methods (eye dome lighting, hillshading,...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A geometry is the spatial representation of a feature.
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:83
Abstract base class for map rendering implementations.
QSize deviceOutputSize() const
Returns the device output size of the map render.
QgsVectorSimplifyMethod mSimplifyMethod
QImage::Format mImageFormat
QgsMaskRenderSettings mMaskRenderSettings
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
QList< QgsMapLayer * > layers(bool expandGroupLayers=false) const
Returns the list of layers which will be rendered in the map.
Qgis::RendererUsage mRendererUsage
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 setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to render in the map.
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
void setDpiTarget(double dpi)
Sets the target dpi (dots per inch) to be taken into consideration when rendering.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
double magnificationFactor() const
Returns the magnification factor.
QHash< QString, QgsSelectiveMaskingSourceSet > mSelectiveMaskingSourceSets
QStringList mLayerIds
QgsLabelingEngineSettings mLabelingEngineSettings
QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType
QStringList layerIds(bool expandGroupLayers=false) const
Returns the list of layer IDs which will be rendered in the map.
void setDevicePixelRatio(float dpr)
Sets the device pixel ratio.
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
double dpiTarget() const
Returns the target DPI (dots per inch) to be taken into consideration when rendering.
QColor backgroundColor() const
Returns the background color of the map.
bool mValid
Whether the actual settings are valid (set in updateDerived()).
void setOutputDpi(double dpi)
Sets the dpi (dots per inch) used for conversion between real world units (e.g.
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
float devicePixelRatio() const
Returns the device pixel ratio.
QgsRectangle mExtent
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
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
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the map of map layer style overrides (key: layer ID, value: style name) where a different style ...
QgsElevationShadingRenderer mShadingRenderer
QgsCoordinateTransformContext mTransformContext
void setExtent(const QgsRectangle &rect, bool magnified=true)
Sets the coordinates of the rectangle which should be rendered.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
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...
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
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.
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
QString ellipsoid() const
Returns ellipsoid's acronym.
double mMagnificationFactor
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
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
Qgis::RasterizedRenderingPolicy mRasterizedRenderingPolicy
QgsMapToPixel mMapToPixel
QMap< QString, QString > layerStyleOverrides() const
Returns the map of map layer style overrides (key: layer ID, value: style name) where a different sty...
Qgis::TextRenderFormat mTextRenderFormat
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
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.
void setOutputSize(QSize size)
Sets the size of the resulting map image, in pixels.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
long long mCurrentFrame
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
void setMagnificationFactor(double factor, const QgsPointXY *center=nullptr)
Set the magnification factor.
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.
Represents a 2D point.
Definition qgspointxy.h:62
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
A rectangle specified with double values.
An interface for classes which provide 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.
Represents a named set of selective masking sources (QgsSelectiveMaskSource).
QgsTemporalRangeObject(bool enabled=false)
Constructor QgsTemporalRangeObject.
Contains settings for simplifying geometries fetched from a vector layer.
#define SIP_SKIP
Definition qgis_sip.h:133
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.