QGIS API Documentation  2.99.0-Master (6c64c5a)
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 
27 #include "qgsabstractgeometry.h"
30 #include "qgsmaptopixel.h"
31 #include "qgsrectangle.h"
32 #include "qgsscalecalculator.h"
33 #include "qgsexpressioncontext.h"
34 #include "qgsmaplayer.h"
35 
36 class QPainter;
37 
39 class QgsScaleCalculator;
40 class QgsMapRendererJob;
41 
42 
58 class CORE_EXPORT QgsMapSettings
59 {
60  public:
62 
69  QgsRectangle extent() const;
70 
77  void setExtent( const QgsRectangle &rect, bool magnified = true );
78 
80  QSize outputSize() const;
82  void setOutputSize( QSize size );
83 
89  double rotation() const;
90 
96  void setRotation( double rotation );
97 
102  double outputDpi() const;
104  void setOutputDpi( double dpi );
105 
112  void setMagnificationFactor( double factor );
113 
119  double magnificationFactor() const;
120 
125  QStringList layerIds() const;
126 
131  QList<QgsMapLayer *> layers() const;
132 
137  void setLayers( const QList<QgsMapLayer *> &layers );
138 
143  QMap<QString, QString> layerStyleOverrides() const;
144 
149  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
150 
157  QString customRenderFlags() const { return mCustomRenderFlags; }
158 
165  void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
166 
168  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
170  QgsCoordinateReferenceSystem destinationCrs() const;
171 
173  QgsUnitTypes::DistanceUnit mapUnits() const;
174 
183  bool setEllipsoid( const QString &ellipsoid );
184 
191  QString ellipsoid() const { return mEllipsoid; }
192 
194  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
196  QColor backgroundColor() const { return mBackgroundColor; }
197 
199  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
201  QColor selectionColor() const { return mSelectionColor; }
202 
204  enum Flag
205  {
206  Antialiasing = 0x01,
207  DrawEditingInfo = 0x02,
208  ForceVectorOutput = 0x04,
209  UseAdvancedEffects = 0x08,
210  DrawLabeling = 0x10,
211  UseRenderingOptimization = 0x20,
212  DrawSelection = 0x40,
213  DrawSymbolBounds = 0x80,
214  RenderMapTile = 0x100,
215  RenderPartialOutput = 0x200,
216  RenderPreviewJob = 0x400,
217  // TODO: ignore scale-based visibility (overview)
218  };
219  Q_DECLARE_FLAGS( Flags, Flag )
220 
221 
222  void setFlags( QgsMapSettings::Flags flags );
224  void setFlag( Flag flag, bool on = true );
226  Flags flags() const;
228  bool testFlag( Flag flag ) const;
229 
231  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
233  QImage::Format outputImageFormat() const { return mImageFormat; }
234 
236  bool hasValidSettings() const;
238  QgsRectangle visibleExtent() const;
239 
244  QPolygonF visiblePolygon() const;
246  double mapUnitsPerPixel() const;
247 
252  double scale() const;
253 
260  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
261 
268  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
269 
278  QgsCoordinateTransformContext transformContext() const;
279 
288  void setTransformContext( const QgsCoordinateTransformContext &context );
289 
297  const QgsPathResolver &pathResolver() const { return mPathResolver; }
298 
306  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
307 
308  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
309 
316  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
317 
323  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
324 
330  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
331 
336  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
337 
343  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
344 
349  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
350 
356  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
357 
363  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
364 
366  QgsRectangle fullExtent() const;
367 
368  /* serialization */
369 
370  void readXml( QDomNode &node );
371 
372  void writeXml( QDomNode &node, QDomDocument &doc );
373 
377  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
379  double segmentationTolerance() const { return mSegmentationTolerance; }
380 
384  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
386  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
387 
392  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ) { mLabelingEngineSettings = settings; }
393 
398  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
399 
400  protected:
401 
402  double mDpi;
403 
404  QSize mSize;
405 
407 
408  double mRotation = 0.0;
409  double mMagnificationFactor = 1.0;
410 
413  QMap<QString, QString> mLayerStyleOverrides;
416 
419  QString mEllipsoid;
420 
423 
424  Flags mFlags;
425 
426  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
427 
430 
432 
433  // derived properties
434  bool mValid = false;
436  double mMapUnitsPerPixel = 1;
437  double mScale = 1;
438 
439  // utiity stuff
442 
444 
446 
447 #ifdef QGISDEBUG
448  bool mHasTransformContext = false;
449 #endif
450 
451  void updateDerived();
452 };
453 
454 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
455 
456 
457 #endif // QGSMAPSETTINGS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:39
Base class for all map layer types.
Definition: qgsmaplayer.h:56
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) ...
QgsCoordinateReferenceSystem mDestCRS
QgsCoordinateTransformContext mTransformContext
A class to represent a 2D point.
Definition: qgspointxy.h:43
QMap< QString, QString > mLayerStyleOverrides
QColor backgroundColor() const
Get the background color of the map.
void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
QgsLabelingEngineSettings mLabelingEngineSettings
The QgsMapSettings class contains configuration for rendering of the map.
QString customRenderFlags() const
Get custom rendering flags.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
QgsRectangle mExtent
Flag
Enumeration of flags that adjust the way the map is rendered.
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.
QgsPathResolver mPathResolver
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Contains information about the context in which a coordinate transform is executed.
QgsExpressionContext mExpressionContext
QgsScaleCalculator mScaleCalculator
const QgsMapToPixel & mapToPixel() const
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:43
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
void setBackgroundColor(const QColor &color)
Set the background color of the map.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets global configuration of the labeling engine.
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)
Set color that is used for drawing of selected vector features.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1356
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...
QColor selectionColor() const
Get color that is used for drawing of selected vector features.
QColor mSelectionColor
Resolves relative paths into absolute paths and vice versa.
QString mCustomRenderFlags
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns global configuration of the labeling engine.