QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
37 class QPainter;
38 
40 class QgsScaleCalculator;
41 class QgsMapRendererJob;
43 
52 class CORE_EXPORT QgsLabelBlockingRegion
53 {
54  public:
55 
59  explicit QgsLabelBlockingRegion( const QgsGeometry &geometry )
60  : geometry( geometry )
61  {}
62 
65 
66 };
67 
68 
86 class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
87 {
88  public:
90 
97  QgsRectangle extent() const;
98 
105  void setExtent( const QgsRectangle &rect, bool magnified = true );
106 
113  double extentBuffer() const;
114 
121  void setExtentBuffer( double buffer );
122 
124  QSize outputSize() const;
126  void setOutputSize( QSize size );
127 
133  float devicePixelRatio() const;
134 
140  void setDevicePixelRatio( float dpr );
141 
148  QSize deviceOutputSize() const;
149 
155  double rotation() const;
156 
162  void setRotation( double rotation );
163 
168  double outputDpi() const;
170  void setOutputDpi( double dpi );
171 
179  void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
180 
186  double magnificationFactor() const;
187 
192  QStringList layerIds() const;
193 
198  QList<QgsMapLayer *> layers() const;
199 
206  void setLayers( const QList<QgsMapLayer *> &layers );
207 
212  QMap<QString, QString> layerStyleOverrides() const;
213 
218  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
219 
227  Q_DECL_DEPRECATED QString customRenderFlags() const { return mCustomRenderFlags; }
228 
236  Q_DECL_DEPRECATED void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
237 
244  QVariantMap customRenderingFlags() const { return mCustomRenderingFlags; }
245 
253  void setCustomRenderingFlag( const QString &flag, const QVariant &value ) { mCustomRenderingFlags[flag] = value; }
254 
261  void clearCustomRenderingFlag( const QString &flag ) { mCustomRenderingFlags.remove( flag ); }
262 
264  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
266  QgsCoordinateReferenceSystem destinationCrs() const;
267 
269  QgsUnitTypes::DistanceUnit mapUnits() const;
270 
279  bool setEllipsoid( const QString &ellipsoid );
280 
287  QString ellipsoid() const { return mEllipsoid; }
288 
290  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
292  QColor backgroundColor() const { return mBackgroundColor; }
293 
295  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
297  QColor selectionColor() const { return mSelectionColor; }
298 
300  enum Flag
301  {
302  Antialiasing = 0x01,
303  DrawEditingInfo = 0x02,
304  ForceVectorOutput = 0x04,
305  UseAdvancedEffects = 0x08,
306  DrawLabeling = 0x10,
307  UseRenderingOptimization = 0x20,
308  DrawSelection = 0x40,
309  DrawSymbolBounds = 0x80,
310  RenderMapTile = 0x100,
311  RenderPartialOutput = 0x200,
312  RenderPreviewJob = 0x400,
313  RenderBlocking = 0x800,
314  // TODO: ignore scale-based visibility (overview)
315  };
316  Q_DECLARE_FLAGS( Flags, Flag )
317 
318 
319  void setFlags( QgsMapSettings::Flags flags );
321  void setFlag( Flag flag, bool on = true );
323  Flags flags() const;
325  bool testFlag( Flag flag ) const;
326 
334  {
335  return mTextRenderFormat;
336  }
337 
348  {
349  mTextRenderFormat = format;
350  // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
351  // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
352  mLabelingEngineSettings.setDefaultTextRenderFormat( format );
353  }
354 
356  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
358  QImage::Format outputImageFormat() const { return mImageFormat; }
359 
361  bool hasValidSettings() const;
363  QgsRectangle visibleExtent() const;
364 
369  QPolygonF visiblePolygon() const;
371  double mapUnitsPerPixel() const;
372 
377  double scale() const;
378 
385  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
386 
393  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
394 
403  QgsCoordinateTransformContext transformContext() const;
404 
413  void setTransformContext( const QgsCoordinateTransformContext &context );
414 
422  const QgsPathResolver &pathResolver() const { return mPathResolver; }
423 
431  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
432 
433  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
434 
441  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
442 
448  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
449 
455  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
456 
461  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
462 
468  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
469 
474  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
475 
481  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
482 
487  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
488 
490  QgsRectangle fullExtent() const;
491 
492  /* serialization */
493 
494  void readXml( QDomNode &node );
495 
496  void writeXml( QDomNode &node, QDomDocument &doc );
497 
501  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
503  double segmentationTolerance() const { return mSegmentationTolerance; }
504 
508  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
510  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
511 
523  {
524  mLabelingEngineSettings = settings;
525  mTextRenderFormat = settings.defaultTextRenderFormat();
526  }
527 
535  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
536 
548  QgsGeometry labelBoundaryGeometry() const;
549 
563  void setLabelBoundaryGeometry( const QgsGeometry &boundary );
564 
571  void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
572 
579  QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
580 
597  void setSimplifyMethod( const QgsVectorSimplifyMethod &method ) { mSimplifyMethod = method; }
598 
610  const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
611 
621  void addRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler );
622 
628  QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const;
629 
630  protected:
631 
632  double mDpi;
633 
634  QSize mSize;
635  float mDevicePixelRatio = 1.0;
636 
638  double mExtentBuffer = 0.0;
639 
640  double mRotation = 0.0;
641  double mMagnificationFactor = 1.0;
642 
645  QMap<QString, QString> mLayerStyleOverrides;
649 
652  QString mEllipsoid;
653 
656 
657  Flags mFlags;
658 
659  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
660 
663 
665 
666  // derived properties
667  bool mValid = false;
669  double mMapUnitsPerPixel = 1;
670  double mScale = 1;
671 
672  // utiity stuff
675 
677 
679 
681 
683 
685 
686 #ifdef QGISDEBUG
687  bool mHasTransformContext = false;
688 #endif
689 
690  void updateDerived();
691 
692  private:
693 
694  QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
695  QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
696 };
697 
698 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
699 
700 
701 #endif // QGSMAPSETTINGS_H
QgsMapSettings::mSegmentationTolerance
double mSegmentationTolerance
Definition: qgsmapsettings.h:661
QgsAbstractGeometry::MaximumAngle
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices)
Definition: qgsabstractgeometry.h:118
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsMapSettings::mLayers
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
Definition: qgsmapsettings.h:644
QgsMapSettings::labelingEngineSettings
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
Definition: qgsmapsettings.h:535
QgsVectorSimplifyMethod
Definition: qgsvectorsimplifymethod.h:29
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
qgsscalecalculator.h
QgsWeakMapLayerPointerList
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1677
QgsMapSettings::textRenderFormat
QgsRenderContext::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
Definition: qgsmapsettings.h:333
qgsrectangle.h
QgsMapSettings::mExpressionContext
QgsExpressionContext mExpressionContext
Definition: qgsmapsettings.h:648
QgsLabelBlockingRegion::geometry
QgsGeometry geometry
Geometry of region to avoid placing labels within (in destination map coordinates and CRS)
Definition: qgsmapsettings.h:64
qgsmaptopixel.h
qgstemporalrangeobject.h
QgsLabelBlockingRegion::QgsLabelBlockingRegion
QgsLabelBlockingRegion(const QgsGeometry &geometry)
Constructor for a label blocking region.
Definition: qgsmapsettings.h:59
qgslabelingenginesettings.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsMapSettings::setTextRenderFormat
void setTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
Definition: qgsmapsettings.h:347
QgsMapSettings::mSimplifyMethod
QgsVectorSimplifyMethod mSimplifyMethod
Definition: qgsmapsettings.h:684
QgsMapSettings::clearCustomRenderingFlag
void clearCustomRenderingFlag(const QString &flag)
Clears the specified custom rendering flag.
Definition: qgsmapsettings.h:261
QgsMapSettings::mCustomRenderFlags
QString mCustomRenderFlags
Definition: qgsmapsettings.h:646
QgsMapSettings::setSegmentationToleranceType
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Definition: qgsmapsettings.h:508
QgsMapSettings::ellipsoid
QString ellipsoid() const
Returns ellipsoid's acronym.
Definition: qgsmapsettings.h:287
QgsMapSettings::simplifyMethod
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
Definition: qgsmapsettings.h:610
QgsRenderContext::TextRenderFormat
TextRenderFormat
Options for rendering text.
Definition: qgsrendercontext.h:90
QgsMapSettings::outputImageFormat
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
Definition: qgsmapsettings.h:358
QgsMapSettings::customRenderingFlags
QVariantMap customRenderingFlags() const
Gets custom rendering flags.
Definition: qgsmapsettings.h:244
QgsMapSettings::mBackgroundColor
QColor mBackgroundColor
Definition: qgsmapsettings.h:654
QgsAbstractGeometry::SegmentationToleranceType
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
Definition: qgsabstractgeometry.h:112
QgsMapSettings::mSize
QSize mSize
Definition: qgsmapsettings.h:634
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
QgsMapSettings::setSegmentationTolerance
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
Definition: qgsmapsettings.h:501
QgsRectangle
Definition: qgsrectangle.h:41
QgsRenderedFeatureHandlerInterface
Definition: qgsrenderedfeaturehandlerinterface.h:46
QgsMapSettings::mEllipsoid
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
Definition: qgsmapsettings.h:652
QgsMapSettings::mPathResolver
QgsPathResolver mPathResolver
Definition: qgsmapsettings.h:678
qgsexpressioncontext.h
QgsMapSettings::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
Definition: qgsmapsettings.h:290
QgsMapSettings::segmentationToleranceType
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Definition: qgsmapsettings.h:510
QgsScaleCalculator
Definition: qgsscalecalculator.h:34
QgsLabelingEngineSettings
Definition: qgslabelingenginesettings.h:30
QgsMapSettings::mTransformContext
QgsCoordinateTransformContext mTransformContext
Definition: qgsmapsettings.h:676
QgsMapSettings::Flag
Flag
Enumeration of flags that adjust the way the map is rendered.
Definition: qgsmapsettings.h:300
QgsMapSettings::mFlags
Flags mFlags
Definition: qgsmapsettings.h:657
qgsmaplayer.h
qgis_sip.h
QgsMapSettings::backgroundColor
QColor backgroundColor() const
Gets the background color of the map.
Definition: qgsmapsettings.h:292
QgsMapSettings::setSelectionColor
void setSelectionColor(const QColor &color)
Sets color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:295
QgsMapSettings::setSimplifyMethod
void setSimplifyMethod(const QgsVectorSimplifyMethod &method)
Sets the simplification setting to use when rendering vector layers.
Definition: qgsmapsettings.h:597
QgsMapSettings::labelBlockingRegions
QList< QgsLabelBlockingRegion > labelBlockingRegions() const
Returns the list of regions to avoid placing labels within.
Definition: qgsmapsettings.h:579
QgsMapSettings::mDestCRS
QgsCoordinateReferenceSystem mDestCRS
Definition: qgsmapsettings.h:650
QgsMapSettings::mLayerStyleOverrides
QMap< QString, QString > mLayerStyleOverrides
Definition: qgsmapsettings.h:645
QgsMapSettings::mVisibleExtent
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
Definition: qgsmapsettings.h:668
QgsMapSettings::expressionContext
const QgsExpressionContext & expressionContext() const
Gets the expression context.
Definition: qgsmapsettings.h:393
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsMapSettings::selectionColor
QColor selectionColor() const
Gets color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:297
QgsMapSettings::segmentationTolerance
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
Definition: qgsmapsettings.h:503
QgsMapSettings::setLabelingEngineSettings
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
Definition: qgsmapsettings.h:522
QgsMapSettings::mDpi
double mDpi
Definition: qgsmapsettings.h:632
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:655
QgsPointXY
Definition: qgspointxy.h:43
QgsMapSettings::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsmapsettings.h:385
QgsMapSettings::mLabelBoundaryGeometry
QgsGeometry mLabelBoundaryGeometry
Definition: qgsmapsettings.h:682
qgsgeometry.h
QgsMapSettings::mScaleCalculator
QgsScaleCalculator mScaleCalculator
Definition: qgsmapsettings.h:673
QgsGeometry
Definition: qgsgeometry.h:122
QgsMapToPixel
Definition: qgsmaptopixel.h:37
QgsMapSettings::mCustomRenderingFlags
QVariantMap mCustomRenderingFlags
Definition: qgsmapsettings.h:647
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsMapSettings::pathResolver
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
Definition: qgsmapsettings.h:422
QgsMapRendererJob
Definition: qgsmaprendererjob.h:186
QgsMapSettings::setOutputImageFormat
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Definition: qgsmapsettings.h:356
QgsMapSettings::mMapToPixel
QgsMapToPixel mMapToPixel
Definition: qgsmapsettings.h:674
QgsMapSettings::setLabelBlockingRegions
void setLabelBlockingRegions(const QList< QgsLabelBlockingRegion > &regions)
Sets a list of regions to avoid placing labels within.
Definition: qgsmapsettings.h:571
QgsLabelBlockingRegion
Definition: qgsmapsettings.h:52
QgsMapSettings::customRenderFlags
Q_DECL_DEPRECATED QString customRenderFlags() const
Gets custom rendering flags.
Definition: qgsmapsettings.h:227
QgsMapSettings::setCustomRenderFlags
Q_DECL_DEPRECATED void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
Definition: qgsmapsettings.h:236
QgsRenderContext::TextFormatAlwaysOutlines
@ TextFormatAlwaysOutlines
Always render text using path objects (AKA outlines/curves).
Definition: qgsrendercontext.h:111
QgsMapSettings::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
Definition: qgsmapsettings.h:431
QgsMapSettings
Definition: qgsmapsettings.h:86
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52
QgsMapSettings::setCustomRenderingFlag
void setCustomRenderingFlag(const QString &flag, const QVariant &value)
Sets a custom rendering flag.
Definition: qgsmapsettings.h:253
qgscoordinatereferencesystem.h
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:433
QgsPathResolver
Definition: qgspathresolver.h:31
QgsTemporalRangeObject
Definition: qgstemporalrangeobject.h:33
QgsMapSettings::mExtent
QgsRectangle mExtent
Definition: qgsmapsettings.h:637
QgsMapSettings::mLabelingEngineSettings
QgsLabelingEngineSettings mLabelingEngineSettings
Definition: qgsmapsettings.h:664