QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
32 #include "qgsexpressioncontext.h"
33 #include "qgsmaplayer.h"
34 #include "qgsgeometry.h"
35 #include "qgstemporalrangeobject.h"
36 #include "qgsmapclippingregion.h"
38 
39 class QPainter;
40 
42 class QgsScaleCalculator;
43 class QgsMapRendererJob;
45 
54 class CORE_EXPORT QgsLabelBlockingRegion
55 {
56  public:
57 
61  explicit QgsLabelBlockingRegion( const QgsGeometry &geometry )
62  : geometry( geometry )
63  {}
64 
67 
68 };
69 
70 
88 class 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; }
642  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
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
QgsMapSettings::mSegmentationTolerance
double mSegmentationTolerance
Definition: qgsmapsettings.h:899
QgsAbstractGeometry::MaximumAngle
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices)
Definition: qgsabstractgeometry.h:127
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsMapSettings::mLayers
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
Definition: qgsmapsettings.h:882
QgsMapSettings::labelingEngineSettings
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
Definition: qgsmapsettings.h:667
QgsVectorSimplifyMethod
This class contains information how to simplify geometries fetched from a vector layer.
Definition: qgsvectorsimplifymethod.h:29
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsMapClippingRegion
A map clipping region (in map coordinates and CRS).
Definition: qgsmapclippingregion.h:33
Qgis::TextRenderFormat
TextRenderFormat
Options for rendering text.
Definition: qgis.h:1331
qgsscalecalculator.h
QgsWeakMapLayerPointerList
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2153
qgsrectangle.h
QgsMapSettings::mExpressionContext
QgsExpressionContext mExpressionContext
Definition: qgsmapsettings.h:886
QgsLabelBlockingRegion::geometry
QgsGeometry geometry
Geometry of region to avoid placing labels within (in destination map coordinates and CRS)
Definition: qgsmapsettings.h:66
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
qgsmaptopixel.h
qgstemporalrangeobject.h
QgsLabelBlockingRegion::QgsLabelBlockingRegion
QgsLabelBlockingRegion(const QgsGeometry &geometry)
Constructor for a label blocking region.
Definition: qgsmapsettings.h:61
qgslabelingenginesettings.h
Qgis::MapSettingsFlag
MapSettingsFlag
Coordinate transformation flags.
Definition: qgis.h:1267
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsMapSettings::mSimplifyMethod
QgsVectorSimplifyMethod mSimplifyMethod
Definition: qgsmapsettings.h:924
QgsMapSettings::clearCustomRenderingFlag
void clearCustomRenderingFlag(const QString &flag)
Clears the specified custom rendering flag.
Definition: qgsmapsettings.h:337
QgsMapSettings::mCustomRenderFlags
QString mCustomRenderFlags
Definition: qgsmapsettings.h:884
QgsMapSettings::setSegmentationToleranceType
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Definition: qgsmapsettings.h:640
QgsMapSettings::ellipsoid
QString ellipsoid() const
Returns ellipsoid's acronym.
Definition: qgsmapsettings.h:374
QgsMapSettings::simplifyMethod
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
Definition: qgsmapsettings.h:772
QgsMapSettings::outputImageFormat
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
Definition: qgsmapsettings.h:444
QgsMapSettings::customRenderingFlags
QVariantMap customRenderingFlags() const
Returns any custom rendering flags.
Definition: qgsmapsettings.h:320
QgsMapSettings::mBackgroundColor
QColor mBackgroundColor
Definition: qgsmapsettings.h:892
QgsAbstractGeometry::SegmentationToleranceType
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
Definition: qgsabstractgeometry.h:120
QgsMapSettings::mSize
QSize mSize
Definition: qgsmapsettings.h:872
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
QgsMapSettings::setSegmentationTolerance
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
Definition: qgsmapsettings.h:632
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsRenderedFeatureHandlerInterface
An interface for classes which provider custom handlers for features rendered as part of a map render...
Definition: qgsrenderedfeaturehandlerinterface.h:46
QgsMapSettings::mEllipsoid
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
Definition: qgsmapsettings.h:890
QgsMapSettings::mPathResolver
QgsPathResolver mPathResolver
Definition: qgsmapsettings.h:918
QgsMapSettings::setTextRenderFormat
void setTextRenderFormat(Qgis::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
Definition: qgsmapsettings.h:433
QgsLabelingEngineSettings::defaultTextRenderFormat
Qgis::TextRenderFormat defaultTextRenderFormat() const
Returns the default text rendering format for the labels.
Definition: qgslabelingenginesettings.h:169
qgsexpressioncontext.h
QgsMapSettings::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
Definition: qgsmapsettings.h:381
QgsMapSettings::segmentationToleranceType
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Definition: qgsmapsettings.h:642
QgsScaleCalculator
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
Definition: qgsscalecalculator.h:34
QgsLabelingEngineSettings
Stores global configuration for labeling engine.
Definition: qgslabelingenginesettings.h:31
QgsMapSettings::mTransformContext
QgsCoordinateTransformContext mTransformContext
Definition: qgsmapsettings.h:916
qgsmaplayer.h
qgis_sip.h
QgsMapSettings::backgroundColor
QColor backgroundColor() const
Returns the background color of the map.
Definition: qgsmapsettings.h:388
QgsMapSettings::setSelectionColor
void setSelectionColor(const QColor &color)
Sets the color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:395
QgsMapSettings::setSimplifyMethod
void setSimplifyMethod(const QgsVectorSimplifyMethod &method)
Sets the simplification setting to use when rendering vector layers.
Definition: qgsmapsettings.h:759
qgsvectorsimplifymethod.h
QgsMapSettings::labelBlockingRegions
QList< QgsLabelBlockingRegion > labelBlockingRegions() const
Returns the list of regions to avoid placing labels within.
Definition: qgsmapsettings.h:711
QgsMapSettings::mDestCRS
QgsCoordinateReferenceSystem mDestCRS
Definition: qgsmapsettings.h:888
QgsMapSettings::mLayerStyleOverrides
QMap< QString, QString > mLayerStyleOverrides
Definition: qgsmapsettings.h:883
QgsMapSettings::mVisibleExtent
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
Definition: qgsmapsettings.h:908
QgsMapSettings::expressionContext
const QgsExpressionContext & expressionContext() const
Gets the expression context.
Definition: qgsmapsettings.h:487
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsMapSettings::selectionColor
QColor selectionColor() const
Returns the color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:402
Qgis::RendererUsage::Unknown
@ Unknown
Renderer used for unknown usage.
QgsMapSettings::textRenderFormat
Qgis::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
Definition: qgsmapsettings.h:419
QgsMapSettings::segmentationTolerance
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
Definition: qgsmapsettings.h:634
QgsMapSettings::setLabelingEngineSettings
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
Definition: qgsmapsettings.h:654
QgsMapSettings::mSelectionColor
QColor mSelectionColor
Definition: qgsmapsettings.h:893
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsMapSettings::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsmapsettings.h:479
QgsMapSettings::mLabelBoundaryGeometry
QgsGeometry mLabelBoundaryGeometry
Definition: qgsmapsettings.h:922
QgsDoubleRange
QgsRange which stores a range of double values.
Definition: qgsrange.h:202
qgsgeometry.h
QgsMapSettings::mScaleCalculator
QgsScaleCalculator mScaleCalculator
Definition: qgsmapsettings.h:913
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsMapToPixel
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:38
QgsMapSettings::mCustomRenderingFlags
QVariantMap mCustomRenderingFlags
Definition: qgsmapsettings.h:885
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsMapSettings::pathResolver
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
Definition: qgsmapsettings.h:516
QgsMapSettings::mFlags
Qgis::MapSettingsFlags mFlags
Definition: qgsmapsettings.h:895
QgsMapRendererJob
Abstract base class for map rendering implementations.
Definition: qgsmaprendererjob.h:269
QgsMapSettings::setOutputImageFormat
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Definition: qgsmapsettings.h:442
Qgis::RendererUsage
RendererUsage
Usage of the renderer.
Definition: qgis.h:1647
QgsMapSettings::mMapToPixel
QgsMapToPixel mMapToPixel
Definition: qgsmapsettings.h:914
QgsMapSettings::setLabelBlockingRegions
void setLabelBlockingRegions(const QList< QgsLabelBlockingRegion > &regions)
Sets a list of regions to avoid placing labels within.
Definition: qgsmapsettings.h:703
QgsLabelBlockingRegion
Label blocking region (in map coordinates and CRS).
Definition: qgsmapsettings.h:54
QgsMapSettings::customRenderFlags
Q_DECL_DEPRECATED QString customRenderFlags() const
Returns custom rendering flags.
Definition: qgsmapsettings.h:303
QgsMapSettings::setCustomRenderFlags
Q_DECL_DEPRECATED void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
Definition: qgsmapsettings.h:312
QgsMapSettings::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
Definition: qgsmapsettings.h:525
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
Definition: qgsmapsettings.h:88
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:57
QgsMapSettings::setCustomRenderingFlag
void setCustomRenderingFlag(const QString &flag, const QVariant &value)
Sets a custom rendering flag.
Definition: qgsmapsettings.h:329
qgscoordinatereferencesystem.h
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:527
QgsPathResolver
Resolves relative paths into absolute paths and vice versa. Used for writing.
Definition: qgspathresolver.h:31
QgsTemporalRangeObject
Base class for objects with an associated (optional) temporal range.
Definition: qgstemporalrangeobject.h:33
qgsmapclippingregion.h
QgsMapSettings::mExtent
QgsRectangle mExtent
Definition: qgsmapsettings.h:875
QgsMapSettings::mLabelingEngineSettings
QgsLabelingEngineSettings mLabelingEngineSettings
Definition: qgsmapsettings.h:902