QGIS API Documentation  2.17.0-Master (3a3b9ab7)
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  // TODO: ignore scale-based visibility (overview)
169  };
170  Q_DECLARE_FLAGS( Flags, Flag )
171 
172 
173  void setFlags( const QgsMapSettings::Flags& flags );
175  void setFlag( Flag flag, bool on = true );
177  Flags flags() const;
179  bool testFlag( Flag flag ) const;
180 
182  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
184  QImage::Format outputImageFormat() const { return mImageFormat; }
185 
187  bool hasValidSettings() const;
189  QgsRectangle visibleExtent() const;
192  QPolygonF visiblePolygon() const;
194  double mapUnitsPerPixel() const;
196  double scale() const;
197 
203  void setExpressionContext( const QgsExpressionContext& context ) { mExpressionContext = context; }
204 
210  const QgsExpressionContext& expressionContext() const { return mExpressionContext; }
211 
212  // -- utility functions --
213 
215  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
216  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
217 
218  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
219 
225  double layerToMapUnits( QgsMapLayer* theLayer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
226 
232  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
233 
239  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
240 
245  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
246 
252  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
253 
258  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
259 
265  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
266 
272  const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
273 
275  QgsRectangle fullExtent() const;
276 
277  /* serialization */
278 
279  void readXML( QDomNode& theNode );
280 
281  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
282 
285  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
287  double segmentationTolerance() const { return mSegmentationTolerance; }
290  void setSegmentationToleranceType( QgsAbstractGeometryV2::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
293 
294  protected:
295 
296  double mDpi;
297 
299 
301 
302  double mRotation;
304 
309 
313 
316 
317  Flags mFlags;
318 
319  QImage::Format mImageFormat;
320 
323 
324 
325  // derived properties
326  bool mValid;
329  double mScale;
330 
331  // utiity stuff
334 
335  void updateDerived();
336 };
337 
338 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
339 
340 
341 #endif // QGSMAPSETTINGS_H
const QgsDatumTransformStore & datumTransformStore() const
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.
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
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
const QgsMapToPixel & mapToPixel() const
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:117
QgsAbstractGeometryV2::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.
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.
The QgsDatumTransformStore class keeps track of datum transformations as chosen by the user...
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
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
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
const QgsExpressionContext & expressionContext() const
Gets the expression context.