QGIS API Documentation  2.17.0-Master (0497e4a)
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 "qgsabstractgeometryv2.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  const QgsCoordinateReferenceSystem& destinationCrs() const;
140 
142  QGis::UnitType mapUnits() const;
144  void setMapUnits( QGis::UnitType 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( const 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  const 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; }
291  void setSegmentationToleranceType( QgsAbstractGeometryV2::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
294 
295  protected:
296 
297  double mDpi;
298 
300 
302 
303  double mRotation;
305 
310 
314 
317 
318  Flags mFlags;
319 
320  QImage::Format mImageFormat;
321 
324 
325 
326  // derived properties
327  bool mValid;
330  double mScale;
331 
332  // utiity stuff
335 
336  void updateDerived();
337 };
338 
339 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
340 
341 
342 #endif // QGSMAPSETTINGS_H
QgsAbstractGeometryV2::SegmentationToleranceType mSegmentationToleranceType
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
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
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
QColor backgroundColor() const
Get the background color of the map.
void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
const QgsDatumTransformStore & datumTransformStore() const
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:34
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:117
const QgsMapToPixel & mapToPixel() const
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
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...
QgsAbstractGeometryV2::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Class for storing a coordinate reference system (CRS)
QColor mBackgroundColor
Class for doing transforms between two map coordinate systems.
UnitType
Map units that qgis supports.
Definition: qgis.h:159
QColor selectionColor() const
Get color that is used for drawing of selected vector features.
QStringList mLayers
QColor mSelectionColor
QgsDatumTransformStore mDatumTransformStore
void setSegmentationToleranceType(QgsAbstractGeometryV2::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
QString mCustomRenderFlags