QGIS API Documentation  2.99.0-Master (08c2e66)
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 <QColor>
21 #include <QImage>
22 #include <QPointer>
23 #include <QSize>
24 #include <QStringList>
25 
26 #include "qgsabstractgeometry.h"
28 #include "qgsdatumtransformstore.h"
29 #include "qgsmaptopixel.h"
30 #include "qgsrectangle.h"
31 #include "qgsscalecalculator.h"
32 #include "qgsexpressioncontext.h"
33 #include "qgsmaplayer.h"
34 
35 class QPainter;
36 
38 class QgsScaleCalculator;
39 class QgsMapRendererJob;
40 
41 
56 class CORE_EXPORT QgsMapSettings
57 {
58  public:
60 
65  QgsRectangle extent() const;
70  void setExtent( const QgsRectangle& rect, bool magnified = true );
71 
73  QSize outputSize() const;
75  void setOutputSize( QSize size );
76 
80  double rotation() const;
84  void setRotation( double degrees );
85 
88  double outputDpi() const;
90  void setOutputDpi( double dpi );
91 
98  void setMagnificationFactor( double factor );
99 
103  double magnificationFactor() const;
104 
107  QStringList layerIds() const;
110  QList<QgsMapLayer*> layers() const;
113  void setLayers( const QList<QgsMapLayer*>& layers );
114 
117  QMap<QString, QString> layerStyleOverrides() const;
120  void setLayerStyleOverrides( const QMap<QString, QString>& overrides );
121 
127  QString customRenderFlags() const { return mCustomRenderFlags; }
128 
134  void setCustomRenderFlags( const QString& customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
135 
137  void setCrsTransformEnabled( bool enabled );
139  bool hasCrsTransformEnabled() const;
140 
142  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
144  QgsCoordinateReferenceSystem destinationCrs() const;
145 
147  QgsUnitTypes::DistanceUnit mapUnits() const;
149  void setMapUnits( QgsUnitTypes::DistanceUnit u );
150 
152  void setBackgroundColor( const QColor& color ) { mBackgroundColor = color; }
154  QColor backgroundColor() const { return mBackgroundColor; }
155 
157  void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
159  QColor selectionColor() const { return mSelectionColor; }
160 
162  enum Flag
163  {
164  Antialiasing = 0x01,
165  DrawEditingInfo = 0x02,
166  ForceVectorOutput = 0x04,
167  UseAdvancedEffects = 0x08,
168  DrawLabeling = 0x10,
169  UseRenderingOptimization = 0x20,
170  DrawSelection = 0x40,
171  DrawSymbolBounds = 0x80,
172  RenderMapTile = 0x100,
173  RenderPartialOutput = 0x200,
174  // TODO: ignore scale-based visibility (overview)
175  };
176  Q_DECLARE_FLAGS( Flags, Flag )
177 
178 
179  void setFlags( QgsMapSettings::Flags flags );
181  void setFlag( Flag flag, bool on = true );
183  Flags flags() const;
185  bool testFlag( Flag flag ) const;
186 
188  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
190  QImage::Format outputImageFormat() const { return mImageFormat; }
191 
193  bool hasValidSettings() const;
195  QgsRectangle visibleExtent() const;
198  QPolygonF visiblePolygon() const;
200  double mapUnitsPerPixel() const;
202  double scale() const;
203 
209  void setExpressionContext( const QgsExpressionContext& context ) { mExpressionContext = context; }
210 
216  const QgsExpressionContext& expressionContext() const { return mExpressionContext; }
217 
218  // -- utility functions --
219 
221  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
222  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
223 
224  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
225 
231  double layerToMapUnits( QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
232 
238  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* layer, QgsRectangle extent ) const;
239 
245  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* layer, QgsRectangle extent ) const;
246 
251  QgsPoint layerToMapCoordinates( QgsMapLayer* layer, QgsPoint point ) const;
252 
258  QgsRectangle layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const;
259 
264  QgsPoint mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint point ) const;
265 
271  QgsRectangle mapToLayerCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const;
272 
278  QgsCoordinateTransform layerTransform( QgsMapLayer *layer ) const;
279 
281  QgsRectangle fullExtent() const;
282 
283  /* serialization */
284 
285  void readXml( QDomNode& node );
286 
287  void writeXml( QDomNode& node, QDomDocument& doc );
288 
291  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
293  double segmentationTolerance() const { return mSegmentationTolerance; }
294 
297  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
299  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
300 
301  protected:
302 
303  double mDpi;
304 
305  QSize mSize;
306 
308 
309  double mRotation;
311 
314  QMap<QString, QString> mLayerStyleOverrides;
317 
321 
324 
325  Flags mFlags;
326 
327  QImage::Format mImageFormat;
328 
331 
332 
333  // derived properties
334  bool mValid;
337  double mScale;
338 
339  // utiity stuff
342 
343  void updateDerived();
344 };
345 
346 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
347 
348 
349 #endif // QGSMAPSETTINGS_H
const QgsDatumTransformStore & datumTransformStore() const
double mMagnificationFactor
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Base class for all map layer types.
Definition: qgsmaplayer.h:52
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.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QColor selectionColor() const
Get color that is used for drawing of selected vector features.
QgsCoordinateReferenceSystem mDestCRS
QMap< QString, QString > mLayerStyleOverrides
void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
const QgsMapToPixel & mapToPixel() const
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
QImage::Format mImageFormat
bool mValid
Whether the actual settings are valid (set in updateDerived())
QgsRectangle mExtent
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
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.
QString customRenderFlags() const
Get custom rendering flags.
QgsExpressionContext mExpressionContext
QgsScaleCalculator mScaleCalculator
A class to represent a point.
Definition: qgspoint.h:143
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
QColor backgroundColor() const
Get the background color of the map.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
void setBackgroundColor(const QColor &color)
Set the background color of the map.
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:983
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)
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
This class represents a coordinate reference system (CRS).
QColor mBackgroundColor
Class for doing transforms between two map coordinate systems.
QColor mSelectionColor
QgsDatumTransformStore mDatumTransformStore
QString mCustomRenderFlags
QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType
const QgsExpressionContext & expressionContext() const
Gets the expression context.