QGIS API Documentation  2.99.0-Master (37c43df)
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 <QColor>
20 #include <QImage>
21 #include <QSize>
22 #include <QStringList>
23 
24 #include "qgsabstractgeometry.h"
26 #include "qgsdatumtransformstore.h"
27 #include "qgsmaptopixel.h"
28 #include "qgsrectangle.h"
29 #include "qgsscalecalculator.h"
30 #include "qgsexpressioncontext.h"
31 
32 class QPainter;
33 
35 class QgsScaleCalculator;
36 class QgsMapRendererJob;
37 class QgsMapLayer;
38 
39 
54 class CORE_EXPORT QgsMapSettings
55 {
56  public:
58 
63  QgsRectangle extent() const;
68  void setExtent( const QgsRectangle& rect, bool magnified = true );
69 
71  QSize outputSize() const;
73  void setOutputSize( QSize size );
74 
78  double rotation() const;
82  void setRotation( double degrees );
83 
86  double outputDpi() const;
88  void setOutputDpi( double dpi );
89 
96  void setMagnificationFactor( double factor );
97 
101  double magnificationFactor() const;
102 
105  QStringList layers() const;
108  void setLayers( const QStringList& layers );
109 
112  QMap<QString, QString> layerStyleOverrides() const;
115  void setLayerStyleOverrides( const QMap<QString, QString>& overrides );
116 
122  QString customRenderFlags() const { return mCustomRenderFlags; }
123 
129  void setCustomRenderFlags( const QString& customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
130 
132  void setCrsTransformEnabled( bool enabled );
134  bool hasCrsTransformEnabled() const;
135 
137  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
139  QgsCoordinateReferenceSystem destinationCrs() const;
140 
142  QgsUnitTypes::DistanceUnit mapUnits() const;
144  void setMapUnits( QgsUnitTypes::DistanceUnit u );
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; }
217  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
218 
219  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
220 
226  double layerToMapUnits( QgsMapLayer* theLayer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
227 
233  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
234 
240  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
241 
246  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
247 
253  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
254 
259  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
260 
266  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
267 
273  QgsCoordinateTransform layerTransform( QgsMapLayer *layer ) const;
274 
276  QgsRectangle fullExtent() const;
277 
278  /* serialization */
279 
280  void readXml( QDomNode& theNode );
281 
282  void writeXml( QDomNode& theNode, QDomDocument& theDoc );
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 
296  protected:
297 
298  double mDpi;
299 
300  QSize mSize;
301 
303 
304  double mRotation;
306 
307  QStringList mLayers;
308  QMap<QString, QString> mLayerStyleOverrides;
311 
315 
318 
319  Flags mFlags;
320 
321  QImage::Format mImageFormat;
322 
325 
326 
327  // derived properties
328  bool mValid;
331  double mScale;
332 
333  // utiity stuff
336 
337  void updateDerived();
338 };
339 
340 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
341 
342 
343 #endif // QGSMAPSETTINGS_H
double mMagnificationFactor
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
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...
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:33
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.
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
QgsExpressionContext mExpressionContext
QgsScaleCalculator mScaleCalculator
A class to represent a point.
Definition: qgspoint.h:111
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.
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.
The QgsDatumTransformStore class keeps track of datum transformations as chosen by the user...
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.
QStringList mLayers
QColor mSelectionColor
QgsDatumTransformStore mDatumTransformStore
QString mCustomRenderFlags
QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType