QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
98  QgsRectangle extent() const;
99 
106  void setExtent( const QgsRectangle &rect, bool magnified = true );
107 
114  double extentBuffer() const;
115 
122  void setExtentBuffer( double buffer );
123 
125  QSize outputSize() const;
127  void setOutputSize( QSize size );
128 
134  float devicePixelRatio() const;
135 
141  void setDevicePixelRatio( float dpr );
142 
149  QSize deviceOutputSize() const;
150 
156  double rotation() const;
157 
163  void setRotation( double rotation );
164 
169  double outputDpi() const;
171  void setOutputDpi( double dpi );
172 
180  void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
181 
187  double magnificationFactor() const;
188 
193  QStringList layerIds() const;
194 
199  QList<QgsMapLayer *> layers() const;
200 
207  void setLayers( const QList<QgsMapLayer *> &layers );
208 
213  QMap<QString, QString> layerStyleOverrides() const;
214 
219  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
220 
228  Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
229 
237  Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
238 
245  QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
246 
254  void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
255 
262  void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
263 
265  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
267  QgsCoordinateReferenceSystem destinationCrs() const;
268 
270  QgsUnitTypes::DistanceUnit mapUnits() const;
271 
280  bool setEllipsoid( const QString &ellipsoid );
281 
288  QString ellipsoid() const { return mEllipsoid; }
289 
291  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
293  QColor backgroundColor() const { return mBackgroundColor; }
294 
296  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
298  QColor selectionColor() const { return mSelectionColor; }
299 
301  enum Flag
302  {
303  Antialiasing = 0x01,
304  DrawEditingInfo = 0x02,
305  ForceVectorOutput = 0x04,
306  UseAdvancedEffects = 0x08,
307  DrawLabeling = 0x10,
308  UseRenderingOptimization = 0x20,
309  DrawSelection = 0x40,
310  DrawSymbolBounds = 0x80,
311  RenderMapTile = 0x100,
312  RenderPartialOutput = 0x200,
313  RenderPreviewJob = 0x400,
314  RenderBlocking = 0x800,
315  LosslessImageRendering = 0x1000,
316  Render3DMap = 0x2000,
317  // TODO: ignore scale-based visibility (overview)
318  };
319  Q_DECLARE_FLAGS( Flags, Flag )
320 
321 
322  void setFlags( QgsMapSettings::Flags flags );
324  void setFlag( Flag flag, bool on = true );
326  Flags flags() const;
328  bool testFlag( Flag flag ) const;
329 
337  {
338  return mTextRenderFormat;
339  }
340 
351  {
352  mTextRenderFormat = format;
353  // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
354  // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
355  mLabelingEngineSettings.setDefaultTextRenderFormat( format );
356  }
357 
359  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
361  QImage::Format outputImageFormat() const { return mImageFormat; }
362 
364  bool hasValidSettings() const;
366  QgsRectangle visibleExtent() const;
367 
372  QPolygonF visiblePolygon() const;
374  double mapUnitsPerPixel() const;
375 
380  double scale() const;
381 
388  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
389 
396  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
397 
406  QgsCoordinateTransformContext transformContext() const;
407 
416  void setTransformContext( const QgsCoordinateTransformContext &context );
417 
425  const QgsPathResolver &pathResolver() const { return mPathResolver; }
426 
434  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
435 
436  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
437 
444  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
445 
451  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
452 
458  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
459 
464  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
465 
471  QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
472 
478  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
479 
484  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
485 
491  QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
492 
498  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
499 
504  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
505 
507  QgsRectangle fullExtent() const;
508 
509  /* serialization */
510 
511  void readXml( QDomNode &node );
512 
513  void writeXml( QDomNode &node, QDomDocument &doc );
514 
519  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
521  double segmentationTolerance() const { return mSegmentationTolerance; }
522 
527  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
529  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
530 
542  {
543  mLabelingEngineSettings = settings;
544  mTextRenderFormat = settings.defaultTextRenderFormat();
545  }
546 
554  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
555 
567  QgsGeometry labelBoundaryGeometry() const;
568 
582  void setLabelBoundaryGeometry( const QgsGeometry &boundary );
583 
590  void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
591 
598  QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
599 
608  void addClippingRegion( const QgsMapClippingRegion &region );
609 
618  void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
619 
628  QList< QgsMapClippingRegion > clippingRegions() const;
629 
646  void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
647 
659  const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
660 
670  void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
671 
677  QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
678 
679  protected:
680 
681  double mDpi;
682 
683  QSize mSize;
684  float mDevicePixelRatio = 1.0;
685 
687  double mExtentBuffer = 0.0;
688 
689  double mRotation = 0.0;
690  double mMagnificationFactor = 1.0;
691 
694  QMap<QString, QString> mLayerStyleOverrides;
698 
701  QString mEllipsoid;
702 
705 
706  Flags mFlags;
707 
708  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
709 
712 
714 
715  // derived properties
716  bool mValid = false;
718  double mMapUnitsPerPixel = 1;
719  double mScale = 1;
720 
721  // utiity stuff
724 
726 
728 
730 
732 
734 
735 #ifdef QGISDEBUG
736  bool mHasTransformContext = false;
737 #endif
738 
739  void updateDerived();
740 
741  private:
742 
743  QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
744  QList< QgsMapClippingRegion > mClippingRegions;
745  QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
746 };
747 
748 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
749 
750 
751 #endif // QGSMAPSETTINGS_H
QgsMapSettings::mSegmentationTolerance
double mSegmentationTolerance
Definition: qgsmapsettings.h:710
QgsAbstractGeometry::MaximumAngle
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices)
Definition: qgsabstractgeometry.h:121
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsMapSettings::mLayers
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
Definition: qgsmapsettings.h:693
QgsMapSettings::labelingEngineSettings
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
Definition: qgsmapsettings.h:554
QgsVectorSimplifyMethod
This class contains information how to simplify geometries fetched from a vector layer.
Definition: qgsvectorsimplifymethod.h:30
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsMapClippingRegion
A map clipping region (in map coordinates and CRS).
Definition: qgsmapclippingregion.h:32
qgsscalecalculator.h
QgsWeakMapLayerPointerList
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1695
QgsMapSettings::textRenderFormat
QgsRenderContext::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
Definition: qgsmapsettings.h:336
qgsrectangle.h
QgsMapSettings::mExpressionContext
QgsExpressionContext mExpressionContext
Definition: qgsmapsettings.h:697
QgsLabelBlockingRegion::geometry
QgsGeometry geometry
Geometry of region to avoid placing labels within (in destination map coordinates and CRS)
Definition: qgsmapsettings.h:65
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
qgsmaptopixel.h
qgstemporalrangeobject.h
QgsLabelBlockingRegion::QgsLabelBlockingRegion
QgsLabelBlockingRegion(const QgsGeometry &geometry)
Constructor for a label blocking region.
Definition: qgsmapsettings.h:60
qgslabelingenginesettings.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsMapSettings::setTextRenderFormat
void setTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
Definition: qgsmapsettings.h:350
QgsMapSettings::mSimplifyMethod
QgsVectorSimplifyMethod mSimplifyMethod
Definition: qgsmapsettings.h:733
QgsMapSettings::clearCustomRenderingFlag
void clearCustomRenderingFlag(const QString &flag)
Clears the specified custom rendering flag.
Definition: qgsmapsettings.h:262
QgsMapSettings::mCustomRenderFlags
QString mCustomRenderFlags
Definition: qgsmapsettings.h:695
QgsMapSettings::setSegmentationToleranceType
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Definition: qgsmapsettings.h:527
QgsMapSettings::ellipsoid
QString ellipsoid() const
Returns ellipsoid's acronym.
Definition: qgsmapsettings.h:288
QgsMapSettings::simplifyMethod
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
Definition: qgsmapsettings.h:659
QgsRenderContext::TextRenderFormat
TextRenderFormat
Options for rendering text.
Definition: qgsrendercontext.h:96
QgsMapSettings::outputImageFormat
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
Definition: qgsmapsettings.h:361
QgsMapSettings::customRenderingFlags
QVariantMap customRenderingFlags() const
Gets custom rendering flags.
Definition: qgsmapsettings.h:245
QgsMapSettings::mBackgroundColor
QColor mBackgroundColor
Definition: qgsmapsettings.h:703
QgsAbstractGeometry::SegmentationToleranceType
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
Definition: qgsabstractgeometry.h:115
QgsMapSettings::mSize
QSize mSize
Definition: qgsmapsettings.h:683
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
QgsMapSettings::setSegmentationTolerance
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
Definition: qgsmapsettings.h:519
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsRenderedFeatureHandlerInterface
An interface for classes which provider custom handlers for features rendered as part of a map render...
Definition: qgsrenderedfeaturehandlerinterface.h:47
QgsMapSettings::mEllipsoid
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
Definition: qgsmapsettings.h:701
QgsMapSettings::mPathResolver
QgsPathResolver mPathResolver
Definition: qgsmapsettings.h:727
qgsexpressioncontext.h
QgsMapSettings::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
Definition: qgsmapsettings.h:291
QgsMapSettings::segmentationToleranceType
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Definition: qgsmapsettings.h:529
QgsScaleCalculator
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
Definition: qgsscalecalculator.h:35
QgsLabelingEngineSettings
Stores global configuration for labeling engine.
Definition: qgslabelingenginesettings.h:31
QgsMapSettings::mTransformContext
QgsCoordinateTransformContext mTransformContext
Definition: qgsmapsettings.h:725
QgsMapSettings::Flag
Flag
Enumeration of flags that adjust the way the map is rendered.
Definition: qgsmapsettings.h:302
QgsMapSettings::mFlags
Flags mFlags
Definition: qgsmapsettings.h:706
qgsmaplayer.h
qgis_sip.h
QgsMapSettings::backgroundColor
QColor backgroundColor() const
Gets the background color of the map.
Definition: qgsmapsettings.h:293
Q_DECLARE_OPERATORS_FOR_FLAGS
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.
QgsMapSettings::setSelectionColor
void setSelectionColor(const QColor &color)
Sets color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:296
QgsMapSettings::setSimplifyMethod
void setSimplifyMethod(const QgsVectorSimplifyMethod &method)
Sets the simplification setting to use when rendering vector layers.
Definition: qgsmapsettings.h:646
QgsMapSettings::labelBlockingRegions
QList< QgsLabelBlockingRegion > labelBlockingRegions() const
Returns the list of regions to avoid placing labels within.
Definition: qgsmapsettings.h:598
QgsMapSettings::mDestCRS
QgsCoordinateReferenceSystem mDestCRS
Definition: qgsmapsettings.h:699
QgsMapSettings::mLayerStyleOverrides
QMap< QString, QString > mLayerStyleOverrides
Definition: qgsmapsettings.h:694
QgsMapSettings::mVisibleExtent
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
Definition: qgsmapsettings.h:717
QgsMapSettings::expressionContext
const QgsExpressionContext & expressionContext() const
Gets the expression context.
Definition: qgsmapsettings.h:396
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsMapSettings::selectionColor
QColor selectionColor() const
Gets color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:298
QgsMapSettings::segmentationTolerance
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
Definition: qgsmapsettings.h:521
QgsMapSettings::setLabelingEngineSettings
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
Definition: qgsmapsettings.h:541
QgsMapSettings::mDpi
double mDpi
Definition: qgsmapsettings.h:681
QgsLabelingEngineSettings::defaultTextRenderFormat
QgsRenderContext::TextRenderFormat defaultTextRenderFormat() const
Returns the default text rendering format for the labels.
Definition: qgslabelingenginesettings.h:167
QgsMapSettings::mSelectionColor
QColor mSelectionColor
Definition: qgsmapsettings.h:704
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsMapSettings::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsmapsettings.h:388
QgsMapSettings::mLabelBoundaryGeometry
QgsGeometry mLabelBoundaryGeometry
Definition: qgsmapsettings.h:731
qgsgeometry.h
QgsMapSettings::mScaleCalculator
QgsScaleCalculator mScaleCalculator
Definition: qgsmapsettings.h:722
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:696
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsMapSettings::pathResolver
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
Definition: qgsmapsettings.h:425
QgsMapRendererJob
Abstract base class for map rendering implementations.
Definition: qgsmaprendererjob.h:187
QgsMapSettings::setOutputImageFormat
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Definition: qgsmapsettings.h:359
QgsMapSettings::mMapToPixel
QgsMapToPixel mMapToPixel
Definition: qgsmapsettings.h:723
QgsMapSettings::setLabelBlockingRegions
void setLabelBlockingRegions(const QList< QgsLabelBlockingRegion > &regions)
Sets a list of regions to avoid placing labels within.
Definition: qgsmapsettings.h:590
QgsLabelBlockingRegion
Label blocking region (in map coordinates and CRS).
Definition: qgsmapsettings.h:54
QgsMapSettings::customRenderFlags
Q_DECL_DEPRECATED QString customRenderFlags() const
Gets custom rendering flags.
Definition: qgsmapsettings.h:228
QgsMapSettings::setCustomRenderFlags
Q_DECL_DEPRECATED void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
Definition: qgsmapsettings.h:237
QgsRenderContext::TextFormatAlwaysOutlines
@ TextFormatAlwaysOutlines
Always render text using path objects (AKA outlines/curves).
Definition: qgsrendercontext.h:116
QgsMapSettings::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
Definition: qgsmapsettings.h:434
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map.
Definition: qgsmapsettings.h:88
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:53
QgsMapSettings::setCustomRenderingFlag
void setCustomRenderingFlag(const QString &flag, const QVariant &value)
Sets a custom rendering flag.
Definition: qgsmapsettings.h:254
qgscoordinatereferencesystem.h
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:436
QgsPathResolver
Resolves relative paths into absolute paths and vice versa.
Definition: qgspathresolver.h:32
QgsTemporalRangeObject
Base class for objects with an associated (optional) temporal range.
Definition: qgstemporalrangeobject.h:34
qgsmapclippingregion.h
QgsMapSettings::mExtent
QgsRectangle mExtent
Definition: qgsmapsettings.h:686
QgsMapSettings::mLabelingEngineSettings
QgsLabelingEngineSettings mLabelingEngineSettings
Definition: qgsmapsettings.h:713