QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
827  protected:
828 
829  double mDpi = 96.0;
830  double mDpiTarget = -1;
831 
832  QSize mSize;
833  float mDevicePixelRatio = 1.0;
834 
836  double mExtentBuffer = 0.0;
837 
838  double mRotation = 0.0;
839  double mMagnificationFactor = 1.0;
840 
843  QMap<QString, QString> mLayerStyleOverrides;
847 
850  QString mEllipsoid;
851 
854 
855  Qgis::MapSettingsFlags mFlags;
856 
857  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
858 
861 
863 
864  // derived properties
866  bool mValid = false;
869  double mMapUnitsPerPixel = 1;
870  double mScale = 1;
871 
872  // utiity stuff
875 
877 
879 
880  Qgis::TextRenderFormat mTextRenderFormat = Qgis::TextRenderFormat::AlwaysOutlines;
881 
883 
885 
887 
888 #ifdef QGISDEBUG
889  bool mHasTransformContext = false;
890 #endif
891 
892  void updateDerived();
893 
894  private:
895 
896  QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
897  QList< QgsMapClippingRegion > mClippingRegions;
898  QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
899 
900  QgsDoubleRange mZRange;
901 
902 };
903 
904 #endif // QGSMAPSETTINGS_H
TextRenderFormat
Options for rendering text.
Definition: qgis.h:1003
RendererUsage
Usage of the renderer.
Definition: qgis.h:1291
@ Unknown
Renderer used for unknown usage.
MapSettingsFlag
Flags which adjust the way maps are rendered.
Definition: qgis.h:942
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:2140
const QgsCoordinateReferenceSystem & crs