QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
67
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> QVector<T> layers() const;
275#endif
276
287 void setLayers( const QList<QgsMapLayer *> &layers );
288
294 QMap<QString, QString> layerStyleOverrides() const;
295
301 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
302
309 Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
310
317 Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
318
325 QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
326
334 void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
335
342 void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
343
349 void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
350
356 QgsCoordinateReferenceSystem destinationCrs() const;
357
361 Qgis::DistanceUnit mapUnits() const;
362
369 Qgis::ScaleCalculationMethod scaleMethod() const;
370
377 void setScaleMethod( Qgis::ScaleCalculationMethod method );
378
386 bool setEllipsoid( const QString &ellipsoid );
387
393 QString ellipsoid() const { return mEllipsoid; }
394
400 void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
401
407 QColor backgroundColor() const { return mBackgroundColor; }
408
414 void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
415
421 QColor selectionColor() const { return mSelectionColor; }
422
424 void setFlags( Qgis::MapSettingsFlags flags );
426 void setFlag( Qgis::MapSettingsFlag flag, bool on = true );
428 Qgis::MapSettingsFlags flags() const;
430 bool testFlag( Qgis::MapSettingsFlag flag ) const;
431
439
450 {
451 mTextRenderFormat = format;
452 // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
453 // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
454 mLabelingEngineSettings.setDefaultTextRenderFormat( format );
455 }
456
458 void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
460 QImage::Format outputImageFormat() const { return mImageFormat; }
461
463 bool hasValidSettings() const;
465 QgsRectangle visibleExtent() const;
466
470 QPolygonF visiblePolygon() const;
471
477 QPolygonF visiblePolygonWithBuffer() const;
478
480 double mapUnitsPerPixel() const;
481
486 double scale() const;
487
494
501
509 QgsCoordinateTransformContext transformContext() const;
510
518 void setTransformContext( const QgsCoordinateTransformContext &context );
519
526 const QgsPathResolver &pathResolver() const { return mPathResolver; }
527
534 void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
535
536 const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
537
543 double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
544
550 QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
551
557 QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
558
563 QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
564
570 QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
571
577 QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
578
583 QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
584
590 QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
591
597 QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
598
603 QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
604
615 QgsRectangle computeExtentForScale( const QgsPointXY &center, double scale ) const;
616
625 double computeScaleForExtent( const QgsRectangle &extent ) const;
626
628 QgsRectangle fullExtent() const;
629
635 void readXml( QDomNode &node );
636
642 void writeXml( QDomNode &node, QDomDocument &doc );
643
648 void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
651
659
674
682
694 QgsGeometry labelBoundaryGeometry() const;
695
709 void setLabelBoundaryGeometry( const QgsGeometry &boundary );
710
717 void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
718
725 QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
726
735 void addClippingRegion( const QgsMapClippingRegion &region );
736
745 void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
746
755 QList< QgsMapClippingRegion > clippingRegions() const;
756
774
787
796
805
813 void setMaskSettings( const QgsMaskRenderSettings &settings );
814
824 void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
825
831 QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
832
839 QgsDoubleRange zRange() const;
840
847 void setZRange( const QgsDoubleRange &range );
848
855 Qgis::RendererUsage rendererUsage() const;
856
866 void setRendererUsage( Qgis::RendererUsage rendererUsage );
867
876 double frameRate() const;
877
886 void setFrameRate( double rate );
887
896 long long currentFrame() const;
897
906 void setCurrentFrame( long long frame );
907
914 const QgsElevationShadingRenderer &elevationShadingRenderer() const;
915
922 void setElevationShadingRenderer( const QgsElevationShadingRenderer &renderer );
923
930 Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const;
931
938 void setRasterizedRenderingPolicy( Qgis::RasterizedRenderingPolicy policy );
939
948 QHash< QString, QgsSelectiveMaskingSourceSet > selectiveMaskingSourceSets() const;
949
956 void setSelectiveMaskingSourceSets( const QVector< QgsSelectiveMaskingSourceSet > &sets );
957
958 protected:
959 double mDpi = 96.0;
960 double mDpiTarget = -1;
961
962 QSize mSize;
963 float mDevicePixelRatio = 1.0;
964
966 double mExtentBuffer = 0.0;
967
968 double mRotation = 0.0;
970
973 QStringList mLayerIds;
974 bool mHasGroupLayers = false;
975
976 QMap<QString, QString> mLayerStyleOverrides;
980
983 QString mEllipsoid;
984
987
990 QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
991
994
996
997 // derived properties
999 bool mValid = false;
1003 double mScale = 1;
1004
1005 // utiity stuff
1008
1010
1012
1014
1016
1018
1020
1022
1023 double mFrameRate = -1;
1024 long long mCurrentFrame = -1;
1025
1027
1028 QHash< QString, QgsSelectiveMaskingSourceSet > mSelectiveMaskingSourceSets;
1029
1030#ifdef QGISDEBUG
1031 bool mHasTransformContext = false;
1032#endif
1033
1034 void updateDerived();
1035
1036 private:
1037 void matchRasterizedRenderingPolicyToFlags();
1038
1039 QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
1040 QList< QgsMapClippingRegion > mClippingRegions;
1041 QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
1042
1043 QgsDoubleRange mZRange;
1044};
1045
1046#endif // QGSMAPSETTINGS_H
RasterizedRenderingPolicy
Policies controlling when rasterisation of content during renders is permitted.
Definition qgis.h:2798
@ Default
Allow raster-based rendering in situations where it is required for correct rendering or where it wil...
Definition qgis.h:2799
QFlags< MapSettingsFlag > MapSettingsFlags
Map settings flags.
Definition qgis.h:2835
DistanceUnit
Units of distance.
Definition qgis.h:5170
TextRenderFormat
Options for rendering text.
Definition qgis.h:2923
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
Definition qgis.h:2924
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:5447
RendererUsage
Usage of the renderer.
Definition qgis.h:3559
@ Unknown
Renderer used for unknown usage.
Definition qgis.h:3562
MapSettingsFlag
Flags which adjust the way maps are rendered.
Definition qgis.h:2811
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:217
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.