QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
36 class QPainter;
37 
39 class QgsScaleCalculator;
40 class QgsMapRendererJob;
42 
51 class CORE_EXPORT QgsLabelBlockingRegion
52 {
53  public:
54 
58  explicit QgsLabelBlockingRegion( const QgsGeometry &geometry )
59  : geometry( geometry )
60  {}
61 
64 
65 };
66 
67 
85 class CORE_EXPORT QgsMapSettings
86 {
87  public:
89 
96  QgsRectangle extent() const;
97 
104  void setExtent( const QgsRectangle &rect, bool magnified = true );
105 
112  double extentBuffer() const;
113 
120  void setExtentBuffer( double buffer );
121 
123  QSize outputSize() const;
125  void setOutputSize( QSize size );
126 
132  float devicePixelRatio() const;
133 
139  void setDevicePixelRatio( float dpr );
140 
147  QSize deviceOutputSize() const;
148 
154  double rotation() const;
155 
161  void setRotation( double rotation );
162 
167  double outputDpi() const;
169  void setOutputDpi( double dpi );
170 
177  void setMagnificationFactor( double factor );
178 
184  double magnificationFactor() const;
185 
190  QStringList layerIds() const;
191 
196  QList<QgsMapLayer *> layers() const;
197 
204  void setLayers( const QList<QgsMapLayer *> &layers );
205 
210  QMap<QString, QString> layerStyleOverrides() const;
211 
216  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
217 
225  Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
226 
234  Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
235 
242  QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
243 
251  void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
252 
259  void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
260 
262  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
264  QgsCoordinateReferenceSystem destinationCrs() const;
265 
267  QgsUnitTypes::DistanceUnit mapUnits() const;
268 
277  bool setEllipsoid( const QString &ellipsoid );
278 
285  QString ellipsoid() const { return mEllipsoid; }
286 
288  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
290  QColor backgroundColor() const { return mBackgroundColor; }
291 
293  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
295  QColor selectionColor() const { return mSelectionColor; }
296 
298  enum Flag
299  {
300  Antialiasing = 0x01,
301  DrawEditingInfo = 0x02,
302  ForceVectorOutput = 0x04,
303  UseAdvancedEffects = 0x08,
304  DrawLabeling = 0x10,
305  UseRenderingOptimization = 0x20,
306  DrawSelection = 0x40,
307  DrawSymbolBounds = 0x80,
308  RenderMapTile = 0x100,
309  RenderPartialOutput = 0x200,
310  RenderPreviewJob = 0x400,
311  RenderBlocking = 0x800,
312  // TODO: ignore scale-based visibility (overview)
313  };
314  Q_DECLARE_FLAGS( Flags, Flag )
315 
316 
317  void setFlags( QgsMapSettings::Flags flags );
319  void setFlag( Flag flag, bool on = true );
321  Flags flags() const;
323  bool testFlag( Flag flag ) const;
324 
332  {
333  return mTextRenderFormat;
334  }
335 
346  {
347  mTextRenderFormat = format;
348  // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
349  // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
350  mLabelingEngineSettings.setDefaultTextRenderFormat( format );
351  }
352 
354  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
356  QImage::Format outputImageFormat() const { return mImageFormat; }
357 
359  bool hasValidSettings() const;
361  QgsRectangle visibleExtent() const;
362 
367  QPolygonF visiblePolygon() const;
369  double mapUnitsPerPixel() const;
370 
375  double scale() const;
376 
383  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
384 
391  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
392 
401  QgsCoordinateTransformContext transformContext() const;
402 
411  void setTransformContext( const QgsCoordinateTransformContext &context );
412 
420  const QgsPathResolver &pathResolver() const { return mPathResolver; }
421 
429  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
430 
431  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
432 
439  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
440 
446  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
447 
453  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
454 
459  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
460 
466  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
467 
472  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
473 
479  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
480 
485  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
486 
488  QgsRectangle fullExtent() const;
489 
490  /* serialization */
491 
492  void readXml( QDomNode &node );
493 
494  void writeXml( QDomNode &node, QDomDocument &doc );
495 
499  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
501  double segmentationTolerance() const { return mSegmentationTolerance; }
502 
506  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
508  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
509 
521  {
522  mLabelingEngineSettings = settings;
523  mTextRenderFormat = settings.defaultTextRenderFormat();
524  }
525 
533  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
534 
546  QgsGeometry labelBoundaryGeometry() const;
547 
561  void setLabelBoundaryGeometry( const QgsGeometry &boundary );
562 
569  void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
570 
577  QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
578 
595  void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
596 
608  const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
609 
619  void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
620 
626  QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
627 
628  protected:
629 
630  double mDpi;
631 
632  QSize mSize;
633  float mDevicePixelRatio = 1.0;
634 
636  double mExtentBuffer = 0.0;
637 
638  double mRotation = 0.0;
639  double mMagnificationFactor = 1.0;
640 
643  QMap<QString, QString> mLayerStyleOverrides;
647 
650  QString mEllipsoid;
651 
654 
655  Flags mFlags;
656 
657  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
658 
661 
663 
664  // derived properties
665  bool mValid = false;
667  double mMapUnitsPerPixel = 1;
668  double mScale = 1;
669 
670  // utiity stuff
673 
675 
677 
679 
681 
683 
684 #ifdef QGISDEBUG
685  bool mHasTransformContext = false;
686 #endif
687 
688  void updateDerived();
689 
690  private:
691 
692  QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
693  QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
694 };
695 
696 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
697 
698 
699 #endif // QGSMAPSETTINGS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:79
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.
QgsGeometry mLabelBoundaryGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
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.
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
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:66
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
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:1657
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.