QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 
250  QStringList layerIds() const;
251 
260  QList<QgsMapLayer *> layers() const;
261 
272  void setLayers( const QList<QgsMapLayer *> &layers );
273 
280  QMap<QString, QString> layerStyleOverrides() const;
281 
288  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
289 
297  Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
298 
306  Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
307 
314  QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
315 
323  void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
324 
331  void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
332 
338  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
339 
345  QgsCoordinateReferenceSystem destinationCrs() const;
346 
350  QgsUnitTypes::DistanceUnit mapUnits() const;
351 
360  bool setEllipsoid( const QString &ellipsoid );
361 
368  QString ellipsoid() const { return mEllipsoid; }
369 
375  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
376 
382  QColor backgroundColor() const { return mBackgroundColor; }
383 
389  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
390 
396  QColor selectionColor() const { return mSelectionColor; }
397 
399  void setFlags( Qgis::MapSettingsFlags flags );
401  void setFlag( Qgis::MapSettingsFlag flag, bool on = true );
403  Qgis::MapSettingsFlags flags() const;
405  bool testFlag( Qgis::MapSettingsFlag flag ) const;
406 
414  {
415  return mTextRenderFormat;
416  }
417 
428  {
429  mTextRenderFormat = format;
430  // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
431  // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
432  mLabelingEngineSettings.setDefaultTextRenderFormat( format );
433  }
434 
436  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
438  QImage::Format outputImageFormat() const { return mImageFormat; }
439 
441  bool hasValidSettings() const;
443  QgsRectangle visibleExtent() const;
444 
449  QPolygonF visiblePolygon() const;
450 
456  QPolygonF visiblePolygonWithBuffer() const;
457 
459  double mapUnitsPerPixel() const;
460 
465  double scale() const;
466 
473  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
474 
481  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
482 
491  QgsCoordinateTransformContext transformContext() const;
492 
501  void setTransformContext( const QgsCoordinateTransformContext &context );
502 
510  const QgsPathResolver &pathResolver() const { return mPathResolver; }
511 
519  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
520 
521  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
522 
529  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
530 
536  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
537 
543  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
544 
549  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
550 
556  QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
557 
563  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
564 
569  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
570 
576  QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
577 
583  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
584 
589  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
590 
601  QgsRectangle computeExtentForScale( const QgsPointXY &center, double scale ) const;
602 
611  double computeScaleForExtent( const QgsRectangle &extent ) const;
612 
614  QgsRectangle fullExtent() const;
615 
616  /* serialization */
617 
618  void readXml( QDomNode &node );
619 
620  void writeXml( QDomNode &node, QDomDocument &doc );
621 
626  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
628  double segmentationTolerance() const { return mSegmentationTolerance; }
629 
634  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
636  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
637 
649  {
650  mLabelingEngineSettings = settings;
651  mTextRenderFormat = settings.defaultTextRenderFormat();
652  }
653 
661  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
662 
674  QgsGeometry labelBoundaryGeometry() const;
675 
689  void setLabelBoundaryGeometry( const QgsGeometry &boundary );
690 
697  void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
698 
705  QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
706 
715  void addClippingRegion( const QgsMapClippingRegion &region );
716 
725  void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
726 
735  QList< QgsMapClippingRegion > clippingRegions() const;
736 
753  void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
754 
766  const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
767 
777  void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
778 
784  QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
785 
792  QgsDoubleRange zRange() const;
793 
800  void setZRange( const QgsDoubleRange &range );
801 
802  protected:
803 
804  double mDpi = 96.0;
805  double mDpiTarget = -1;
806 
807  QSize mSize;
808  float mDevicePixelRatio = 1.0;
809 
811  double mExtentBuffer = 0.0;
812 
813  double mRotation = 0.0;
814  double mMagnificationFactor = 1.0;
815 
818  QMap<QString, QString> mLayerStyleOverrides;
822 
825  QString mEllipsoid;
826 
829 
830  Qgis::MapSettingsFlags mFlags;
831 
832  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
833 
836 
838 
839  // derived properties
841  bool mValid = false;
844  double mMapUnitsPerPixel = 1;
845  double mScale = 1;
846 
847  // utiity stuff
850 
852 
854 
855  Qgis::TextRenderFormat mTextRenderFormat = Qgis::TextRenderFormat::AlwaysOutlines;
856 
858 
860 
861 #ifdef QGISDEBUG
862  bool mHasTransformContext = false;
863 #endif
864 
865  void updateDerived();
866 
867  private:
868 
869  QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
870  QList< QgsMapClippingRegion > mClippingRegions;
871  QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
872 
873  QgsDoubleRange mZRange;
874 
875 };
876 
877 #endif // QGSMAPSETTINGS_H
TextRenderFormat
Options for rendering text.
Definition: qgis.h:965
MapSettingsFlag
Flags which adjust the way maps are rendered.
Definition: qgis.h:908
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:203
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:125
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:73
Abstract base class for map rendering implementations.
The QgsMapSettings class contains configuration for rendering of the map.
QgsVectorSimplifyMethod mSimplifyMethod
QColor mBackgroundColor
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
QgsLabelingEngineSettings mLabelingEngineSettings
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
QColor backgroundColor() const
Returns the background color of the map.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
void setCustomRenderingFlag(const QString &flag, const QVariant &value)
Sets a custom rendering flag.
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
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
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
const QgsMapToPixel & mapToPixel() const
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...
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
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...
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
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.
QColor mSelectionColor
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...
double mSegmentationTolerance
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
Resolves relative paths into absolute paths and vice versa.
A class to represent a 2D point.
Definition: qgspointxy.h:59
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
A rectangle specified with double values.
Definition: qgsrectangle.h:42
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.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
This class contains information how to simplify geometries fetched from a vector layer.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2137
const QgsCoordinateReferenceSystem & crs