QGIS API Documentation  2.15.0-Master (af20121)
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  int outputDpi() const;
88  void setOutputDpi( int dpi );
89 
92  void setMagnificationFactor( double factor );
95  double magnificationFactor() const;
96 
99  QStringList layers() const;
102  void setLayers( const QStringList& layers );
103 
106  QMap<QString, QString> layerStyleOverrides() const;
109  void setLayerStyleOverrides( const QMap<QString, QString>& overrides );
110 
112  void setCrsTransformEnabled( bool enabled );
114  bool hasCrsTransformEnabled() const;
115 
117  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
119  const QgsCoordinateReferenceSystem& destinationCrs() const;
120 
122  QGis::UnitType mapUnits() const;
124  void setMapUnits( QGis::UnitType u );
125 
127  void setBackgroundColor( const QColor& color ) { mBackgroundColor = color; }
129  QColor backgroundColor() const { return mBackgroundColor; }
130 
132  void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
134  QColor selectionColor() const { return mSelectionColor; }
135 
137  enum Flag
138  {
139  Antialiasing = 0x01,
140  DrawEditingInfo = 0x02,
141  ForceVectorOutput = 0x04,
142  UseAdvancedEffects = 0x08,
143  DrawLabeling = 0x10,
144  UseRenderingOptimization = 0x20,
145  DrawSelection = 0x40,
146  DrawSymbolBounds = 0x80,
147  RenderMapTile = 0x100
148  // TODO: ignore scale-based visibility (overview)
149  };
150  Q_DECLARE_FLAGS( Flags, Flag )
151 
152 
153  void setFlags( const QgsMapSettings::Flags& flags );
155  void setFlag( Flag flag, bool on = true );
157  Flags flags() const;
159  bool testFlag( Flag flag ) const;
160 
162  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
164  QImage::Format outputImageFormat() const { return mImageFormat; }
165 
167  bool hasValidSettings() const;
169  QgsRectangle visibleExtent() const;
172  QPolygonF visiblePolygon() const;
174  double mapUnitsPerPixel() const;
176  double scale() const;
177 
183  void setExpressionContext( const QgsExpressionContext& context ) { mExpressionContext = context; }
184 
190  const QgsExpressionContext& expressionContext() const { return mExpressionContext; }
191 
192  // -- utility functions --
193 
195  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
196  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
197 
198  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
199 
205  double layerToMapUnits( QgsMapLayer* theLayer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
206 
212  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
213 
219  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
220 
225  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
226 
232  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
233 
238  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
239 
245  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
246 
252  const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
253 
255  QgsRectangle fullExtent() const;
256 
257  /* serialization */
258 
259  void readXML( QDomNode& theNode );
260 
261  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
262 
265  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
267  double segmentationTolerance() const { return mSegmentationTolerance; }
270  void setSegmentationToleranceType( QgsAbstractGeometryV2::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
273 
274  protected:
275 
276  int mDpi;
277 
279 
281 
282  double mRotation;
284 
288 
292 
295 
296  Flags mFlags;
297 
298  QImage::Format mImageFormat;
299 
302 
303 
304  // derived properties
305  bool mValid;
308  double mScale;
309 
310  // utiity stuff
313 
314  void updateDerived();
315 };
316 
317 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
318 
319 
320 #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...
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 how 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.
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...
const QgsExpressionContext & expressionContext() const
Gets the expression context.