QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
214  void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
215 
221  double magnificationFactor() const;
222 
231  QStringList layerIds() const;
232 
241  QList<QgsMapLayer *> layers() const;
242 
253  void setLayers( const QList<QgsMapLayer *> &layers );
254 
261  QMap<QString, QString> layerStyleOverrides() const;
262 
269  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
270 
278  Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
279 
287  Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
288 
295  QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
296 
304  void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
305 
312  void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
313 
319  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
320 
326  QgsCoordinateReferenceSystem destinationCrs() const;
327 
331  QgsUnitTypes::DistanceUnit mapUnits() const;
332 
341  bool setEllipsoid( const QString &ellipsoid );
342 
349  QString ellipsoid() const { return mEllipsoid; }
350 
356  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
357 
363  QColor backgroundColor() const { return mBackgroundColor; }
364 
370  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
371 
377  QColor selectionColor() const { return mSelectionColor; }
378 
380  enum Flag
381  {
382  Antialiasing = 0x01,
383  DrawEditingInfo = 0x02,
384  ForceVectorOutput = 0x04,
385  UseAdvancedEffects = 0x08,
386  DrawLabeling = 0x10,
387  UseRenderingOptimization = 0x20,
388  DrawSelection = 0x40,
389  DrawSymbolBounds = 0x80,
390  RenderMapTile = 0x100,
391  RenderPartialOutput = 0x200,
392  RenderPreviewJob = 0x400,
393  RenderBlocking = 0x800,
394  LosslessImageRendering = 0x1000,
395  Render3DMap = 0x2000,
396  // TODO: ignore scale-based visibility (overview)
397  };
398  Q_DECLARE_FLAGS( Flags, Flag )
399 
400 
401  void setFlags( QgsMapSettings::Flags flags );
403  void setFlag( Flag flag, bool on = true );
405  Flags flags() const;
407  bool testFlag( Flag flag ) const;
408 
416  {
417  return mTextRenderFormat;
418  }
419 
430  {
431  mTextRenderFormat = format;
432  // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
433  // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
434  mLabelingEngineSettings.setDefaultTextRenderFormat( format );
435  }
436 
438  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
440  QImage::Format outputImageFormat() const { return mImageFormat; }
441 
443  bool hasValidSettings() const;
445  QgsRectangle visibleExtent() const;
446 
451  QPolygonF visiblePolygon() const;
453  double mapUnitsPerPixel() const;
454 
459  double scale() const;
460 
467  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
468 
475  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
476 
485  QgsCoordinateTransformContext transformContext() const;
486 
495  void setTransformContext( const QgsCoordinateTransformContext &context );
496 
504  const QgsPathResolver &pathResolver() const { return mPathResolver; }
505 
513  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
514 
515  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
516 
523  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
524 
530  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
531 
537  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
538 
543  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
544 
550  QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
551 
557  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
558 
563  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
564 
570  QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
571 
577  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
578 
583  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
584 
586  QgsRectangle fullExtent() const;
587 
588  /* serialization */
589 
590  void readXml( QDomNode &node );
591 
592  void writeXml( QDomNode &node, QDomDocument &doc );
593 
598  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
600  double segmentationTolerance() const { return mSegmentationTolerance; }
601 
606  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
608  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
609 
621  {
622  mLabelingEngineSettings = settings;
623  mTextRenderFormat = settings.defaultTextRenderFormat();
624  }
625 
633  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
634 
646  QgsGeometry labelBoundaryGeometry() const;
647 
661  void setLabelBoundaryGeometry( const QgsGeometry &boundary );
662 
669  void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
670 
677  QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
678 
687  void addClippingRegion( const QgsMapClippingRegion &region );
688 
697  void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
698 
707  QList< QgsMapClippingRegion > clippingRegions() const;
708 
725  void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
726 
738  const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
739 
749  void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
750 
756  QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
757 
764  QgsDoubleRange zRange() const;
765 
772  void setZRange( const QgsDoubleRange &range );
773 
774  protected:
775 
776  double mDpi;
777 
778  QSize mSize;
779  float mDevicePixelRatio = 1.0;
780 
782  double mExtentBuffer = 0.0;
783 
784  double mRotation = 0.0;
785  double mMagnificationFactor = 1.0;
786 
789  QMap<QString, QString> mLayerStyleOverrides;
793 
796  QString mEllipsoid;
797 
800 
801  Flags mFlags;
802 
803  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
804 
807 
809 
810  // derived properties
811  bool mValid = false;
813  double mMapUnitsPerPixel = 1;
814  double mScale = 1;
815 
816  // utiity stuff
819 
821 
823 
825 
827 
829 
830 #ifdef QGISDEBUG
831  bool mHasTransformContext = false;
832 #endif
833 
834  void updateDerived();
835 
836  private:
837 
838  QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
839  QList< QgsMapClippingRegion > mClippingRegions;
840  QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
841 
842  QgsDoubleRange mZRange;
843 
844 };
845 
846 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
847 
848 
849 #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:85
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:44
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
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:1776
const QgsCoordinateReferenceSystem & crs