QGIS API Documentation  2.99.0-Master (ba079d8)
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"
29 #include "qgsdatumtransformstore.h"
31 #include "qgsmaptopixel.h"
32 #include "qgsrectangle.h"
33 #include "qgsscalecalculator.h"
34 #include "qgsexpressioncontext.h"
35 #include "qgsmaplayer.h"
36 
37 class QPainter;
38 
40 class QgsScaleCalculator;
41 class QgsMapRendererJob;
42 
43 
58 class CORE_EXPORT QgsMapSettings
59 {
60  public:
62 
67  QgsRectangle extent() const;
72  void setExtent( const QgsRectangle &rect, bool magnified = true );
73 
75  QSize outputSize() const;
77  void setOutputSize( QSize size );
78 
82  double rotation() const;
86  void setRotation( double degrees );
87 
90  double outputDpi() const;
92  void setOutputDpi( double dpi );
93 
100  void setMagnificationFactor( double factor );
101 
105  double magnificationFactor() const;
106 
109  QStringList layerIds() const;
112  QList<QgsMapLayer *> layers() const;
115  void setLayers( const QList<QgsMapLayer *> &layers );
116 
119  QMap<QString, QString> layerStyleOverrides() const;
122  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
123 
129  QString customRenderFlags() const { return mCustomRenderFlags; }
130 
136  void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
137 
139  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
141  QgsCoordinateReferenceSystem destinationCrs() const;
142 
144  QgsUnitTypes::DistanceUnit mapUnits() const;
145 
147  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
149  QColor backgroundColor() const { return mBackgroundColor; }
150 
152  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
154  QColor selectionColor() const { return mSelectionColor; }
155 
157  enum Flag
158  {
159  Antialiasing = 0x01,
160  DrawEditingInfo = 0x02,
161  ForceVectorOutput = 0x04,
162  UseAdvancedEffects = 0x08,
163  DrawLabeling = 0x10,
164  UseRenderingOptimization = 0x20,
165  DrawSelection = 0x40,
166  DrawSymbolBounds = 0x80,
167  RenderMapTile = 0x100,
168  RenderPartialOutput = 0x200,
169  // TODO: ignore scale-based visibility (overview)
170  };
171  Q_DECLARE_FLAGS( Flags, Flag )
172 
173 
174  void setFlags( QgsMapSettings::Flags flags );
176  void setFlag( Flag flag, bool on = true );
178  Flags flags() const;
180  bool testFlag( Flag flag ) const;
181 
183  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
185  QImage::Format outputImageFormat() const { return mImageFormat; }
186 
188  bool hasValidSettings() const;
190  QgsRectangle visibleExtent() const;
193  QPolygonF visiblePolygon() const;
195  double mapUnitsPerPixel() const;
197  double scale() const;
198 
204  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
205 
211  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
212 
213  // -- utility functions --
214 
216  const QgsDatumTransformStore &datumTransformStore() const { return mDatumTransformStore; } SIP_SKIP
217  QgsDatumTransformStore &datumTransformStore() { return mDatumTransformStore; }
218 
219  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
220 
226  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
227 
233  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
234 
240  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
241 
246  QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, QgsPoint point ) const;
247 
253  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
254 
259  QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, QgsPoint point ) const;
260 
266  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
267 
273  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
274 
276  QgsRectangle fullExtent() const;
277 
278  /* serialization */
279 
280  void readXml( QDomNode &node );
281 
282  void writeXml( QDomNode &node, QDomDocument &doc );
283 
286  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
288  double segmentationTolerance() const { return mSegmentationTolerance; }
289 
292  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
294  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
295 
300  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ) { mLabelingEngineSettings = settings; }
301 
306  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
307 
308  protected:
309 
310  double mDpi;
311 
312  QSize mSize;
313 
315 
316  double mRotation;
318 
321  QMap<QString, QString> mLayerStyleOverrides;
324 
327 
330 
331  Flags mFlags;
332 
333  QImage::Format mImageFormat;
334 
337 
339 
340  // derived properties
341  bool mValid;
344  double mScale;
345 
346  // utiity stuff
349 
350  void updateDerived();
351 };
352 
353 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
354 
355 
356 #endif // QGSMAPSETTINGS_H
double mMagnificationFactor
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Base class for all map layer types.
Definition: qgsmaplayer.h:54
QgsDatumTransformStore & datumTransformStore()
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.
QgsCoordinateReferenceSystem mDestCRS
QMap< QString, QString > mLayerStyleOverrides
QColor backgroundColor() const
Get the background color of the map.
void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
const QgsDatumTransformStore & datumTransformStore() const
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:35
QImage::Format mImageFormat
bool mValid
Whether the actual settings are valid (set in updateDerived())
QgsRectangle mExtent
Flag
Enumeration of flags that adjust the way the map is rendered.
#define SIP_SKIP
Definition: qgis_sip.h:102
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.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
QgsExpressionContext mExpressionContext
QgsScaleCalculator mScaleCalculator
A class to represent a point.
Definition: qgspoint.h:37
const QgsMapToPixel & mapToPixel() const
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
void setBackgroundColor(const QColor &color)
Set the background color of the map.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets global configuration of the labeling engine.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
double mMapUnitsPerPixel
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:1097
The QgsDatumTransformStore class keeps track of datum transformations as chosen by the user...
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.
QColor selectionColor() const
Get color that is used for drawing of selected vector features.
QColor mSelectionColor
QgsDatumTransformStore mDatumTransformStore
QString mCustomRenderFlags
QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns global configuration of the labeling engine.