QGIS API Documentation  3.17.0-Master (a035f434f4)
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
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
QgsMapToPixel mMapToPixel
Abstract base class for map rendering implementations.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Maximum angle between generating radii (lines from arc center to output vertices) ...
QgsRenderContext::TextRenderFormat defaultTextRenderFormat() const
Returns the default text rendering format for the labels.
QgsCoordinateReferenceSystem mDestCRS
QgsCoordinateTransformContext mTransformContext
A class to represent a 2D point.
Definition: qgspointxy.h:43
QMap< QString, QString > mLayerStyleOverrides
QColor backgroundColor() const
Gets the background color of the map.
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.
QgsGeometry mLabelBoundaryGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:123
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
const QgsCoordinateReferenceSystem & crs
QgsLabelingEngineSettings mLabelingEngineSettings
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:37
Q_DECL_DEPRECATED QString customRenderFlags() const
Gets custom rendering flags.
Q_DECL_DEPRECATED void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
QgsRectangle mExtent
void setTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
Flag
Enumeration of flags that adjust the way the map is rendered.
void clearCustomRenderingFlag(const QString &flag)
Clears the specified custom rendering flag.
A map clipping region (in map coordinates and CRS).
Always render text using path objects (AKA outlines/curves).
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
An interface for classes which provider custom handlers for features rendered as part of a map render...
QgsPathResolver mPathResolver
QgsVectorSimplifyMethod mSimplifyMethod
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
void setCustomRenderingFlag(const QString &flag, const QVariant &value)
Sets a custom rendering flag.
void setSimplifyMethod(const QgsVectorSimplifyMethod &method)
Sets the simplification setting to use when rendering vector layers.
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Label blocking region (in map coordinates and CRS).
Contains information about the context in which a coordinate transform is executed.
QgsExpressionContext mExpressionContext
TextRenderFormat
Options for rendering text.
QgsScaleCalculator mScaleCalculator
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
const QgsMapToPixel & mapToPixel() const
QVariantMap mCustomRenderingFlags
QVariantMap customRenderingFlags() const
Gets custom rendering flags.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
Base class for objects with an associated (optional) temporal range.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
This class contains information how to simplify geometries fetched from a vector layer.
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
double mSegmentationTolerance
void setSelectionColor(const QColor &color)
Sets color that is used for drawing of selected vector features.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1744
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
Stores global configuration for labeling engine.
This class represents a coordinate reference system (CRS).
QColor mBackgroundColor
Class for doing transforms between two map coordinate systems.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
QgsLabelBlockingRegion(const QgsGeometry &geometry)
Constructor for a label blocking region.
QgsGeometry geometry
Geometry of region to avoid placing labels within (in destination map coordinates and CRS) ...
QgsRenderContext::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
QColor selectionColor() const
Gets color that is used for drawing of selected vector features.
QColor mSelectionColor
Resolves relative paths into absolute paths and vice versa.
QList< QgsLabelBlockingRegion > labelBlockingRegions() const
Returns the list of regions to avoid placing labels within.
QString mCustomRenderFlags
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
void setLabelBlockingRegions(const QList< QgsLabelBlockingRegion > &regions)
Sets a list of regions to avoid placing labels within.