QGIS API Documentation  3.20.0-Odense (decaadbb31)
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"
37 
38 class QPainter;
39 
41 class QgsScaleCalculator;
42 class QgsMapRendererJob;
44 
53 class CORE_EXPORT QgsLabelBlockingRegion
54 {
55  public:
56 
60  explicit QgsLabelBlockingRegion( const QgsGeometry &geometry )
61  : geometry( geometry )
62  {}
63 
66 
67 };
68 
69 
87 class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
88 {
89  public:
91 
102  QgsRectangle extent() const;
103 
114  void setExtent( const QgsRectangle &rect, bool magnified = true );
115 
122  double extentBuffer() const;
123 
130  void setExtentBuffer( double buffer );
131 
138  QSize outputSize() const;
139 
145  void setOutputSize( QSize size );
146 
153  float devicePixelRatio() const;
154 
161  void setDevicePixelRatio( float dpr );
162 
175  QSize deviceOutputSize() const;
176 
182  double rotation() const;
183 
189  void setRotation( double rotation );
190 
198  double outputDpi() const;
199 
205  void setOutputDpi( double dpi );
206 
215  double dpiTarget() const;
216 
223  void setDpiTarget( double dpi );
224 
232  void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
233 
239  double magnificationFactor() const;
240 
249  QStringList layerIds() const;
250 
259  QList<QgsMapLayer *> layers() const;
260 
271  void setLayers( const QList<QgsMapLayer *> &layers );
272 
279  QMap<QString, QString> layerStyleOverrides() const;
280 
287  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
288 
296  Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
297 
305  Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
306 
313  QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
314 
322  void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
323 
330  void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
331 
337  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
338 
344  QgsCoordinateReferenceSystem destinationCrs() const;
345 
349  QgsUnitTypes::DistanceUnit mapUnits() const;
350 
359  bool setEllipsoid( const QString &ellipsoid );
360 
367  QString ellipsoid() const { return mEllipsoid; }
368 
374  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
375 
381  QColor backgroundColor() const { return mBackgroundColor; }
382 
388  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
389 
395  QColor selectionColor() const { return mSelectionColor; }
396 
398  enum Flag
399  {
400  Antialiasing = 0x01,
401  DrawEditingInfo = 0x02,
402  ForceVectorOutput = 0x04,
403  UseAdvancedEffects = 0x08,
404  DrawLabeling = 0x10,
405  UseRenderingOptimization = 0x20,
406  DrawSelection = 0x40,
407  DrawSymbolBounds = 0x80,
408  RenderMapTile = 0x100,
409  RenderPartialOutput = 0x200,
410  RenderPreviewJob = 0x400,
411  RenderBlocking = 0x800,
412  LosslessImageRendering = 0x1000,
413  Render3DMap = 0x2000,
414  // TODO: ignore scale-based visibility (overview)
415  };
416  Q_DECLARE_FLAGS( Flags, Flag )
417 
418 
419  void setFlags( QgsMapSettings::Flags flags );
421  void setFlag( Flag flag, bool on = true );
423  Flags flags() const;
425  bool testFlag( Flag flag ) const;
426 
434  {
435  return mTextRenderFormat;
436  }
437 
448  {
449  mTextRenderFormat = format;
450  // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
451  // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
452  mLabelingEngineSettings.setDefaultTextRenderFormat( format );
453  }
454 
456  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
458  QImage::Format outputImageFormat() const { return mImageFormat; }
459 
461  bool hasValidSettings() const;
463  QgsRectangle visibleExtent() const;
464 
469  QPolygonF visiblePolygon() const;
471  double mapUnitsPerPixel() const;
472 
477  double scale() const;
478 
485  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
486 
493  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
494 
503  QgsCoordinateTransformContext transformContext() const;
504 
513  void setTransformContext( const QgsCoordinateTransformContext &context );
514 
522  const QgsPathResolver &pathResolver() const { return mPathResolver; }
523 
531  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
532 
533  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
534 
541  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
542 
548  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
549 
555  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
556 
561  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
562 
568  QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
569 
575  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
576 
581  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
582 
588  QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
589 
595  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
596 
601  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
602 
604  QgsRectangle fullExtent() const;
605 
606  /* serialization */
607 
608  void readXml( QDomNode &node );
609 
610  void writeXml( QDomNode &node, QDomDocument &doc );
611 
616  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
618  double segmentationTolerance() const { return mSegmentationTolerance; }
619 
624  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
626  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
627 
639  {
640  mLabelingEngineSettings = settings;
641  mTextRenderFormat = settings.defaultTextRenderFormat();
642  }
643 
651  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
652 
664  QgsGeometry labelBoundaryGeometry() const;
665 
679  void setLabelBoundaryGeometry( const QgsGeometry &boundary );
680 
687  void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
688 
695  QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
696 
705  void addClippingRegion( const QgsMapClippingRegion &region );
706 
715  void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
716 
725  QList< QgsMapClippingRegion > clippingRegions() const;
726 
743  void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
744 
756  const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
757 
767  void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
768 
774  QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
775 
782  QgsDoubleRange zRange() const;
783 
790  void setZRange( const QgsDoubleRange &range );
791 
792  protected:
793 
794  double mDpi = 96.0;
795  double mDpiTarget = -1;
796 
797  QSize mSize;
798  float mDevicePixelRatio = 1.0;
799 
801  double mExtentBuffer = 0.0;
802 
803  double mRotation = 0.0;
804  double mMagnificationFactor = 1.0;
805 
808  QMap<QString, QString> mLayerStyleOverrides;
812 
815  QString mEllipsoid;
816 
819 
820  Flags mFlags;
821 
822  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
823 
826 
828 
829  // derived properties
830  bool mValid = false;
832  double mMapUnitsPerPixel = 1;
833  double mScale = 1;
834 
835  // utiity stuff
838 
840 
842 
844 
846 
848 
849 #ifdef QGISDEBUG
850  bool mHasTransformContext = false;
851 #endif
852 
853  void updateDerived();
854 
855  private:
856 
857  QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
858  QList< QgsMapClippingRegion > mClippingRegions;
859  QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
860 
861  QgsDoubleRange mZRange;
862 
863 };
864 
865 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
866 
867 
868 #endif // QGSMAPSETTINGS_H
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:124
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.
QgsRenderContext::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:70
Abstract base class for map rendering implementations.
The QgsMapSettings class contains configuration for rendering of the map.
QgsVectorSimplifyMethod mSimplifyMethod
void setTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
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.
QgsRenderContext::TextRenderFormat textRenderFormat() const
Returns 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.
QString mCustomRenderFlags
Flag
Enumeration of flags that adjust the way the map is rendered.
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.
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
TextRenderFormat
Options for rendering text.
@ TextFormatAlwaysOutlines
Always render text using path objects (AKA outlines/curves).
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.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1860
const QgsCoordinateReferenceSystem & crs