QGIS API Documentation
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 
25 #include "qgsdatumtransformstore.h"
26 #include "qgsmaptopixel.h"
27 #include "qgsrectangle.h"
28 #include "qgsscalecalculator.h"
29 #include "qgsexpressioncontext.h"
30 
31 class QPainter;
32 
34 class QgsScaleCalculator;
35 class QgsMapRendererJob;
36 class QgsMapLayer;
37 
38 
53 class CORE_EXPORT QgsMapSettings
54 {
55  public:
57 
62  QgsRectangle extent() const;
67  void setExtent( const QgsRectangle& rect );
68 
70  QSize outputSize() const;
72  void setOutputSize( QSize size );
73 
77  double rotation() const;
81  void setRotation( double degrees );
82 
85  int outputDpi() const;
87  void setOutputDpi( int dpi );
88 
91  QStringList layers() const;
94  void setLayers( const QStringList& layers );
95 
98  QMap<QString, QString> layerStyleOverrides() const;
101  void setLayerStyleOverrides( const QMap<QString, QString>& overrides );
102 
104  void setCrsTransformEnabled( bool enabled );
106  bool hasCrsTransformEnabled() const;
107 
109  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
111  const QgsCoordinateReferenceSystem& destinationCrs() const;
112 
114  QGis::UnitType mapUnits() const;
116  void setMapUnits( QGis::UnitType u );
117 
119  void setBackgroundColor( const QColor& color ) { mBackgroundColor = color; }
121  QColor backgroundColor() const { return mBackgroundColor; }
122 
124  void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
126  QColor selectionColor() const { return mSelectionColor; }
127 
129  enum Flag
130  {
131  Antialiasing = 0x01,
132  DrawEditingInfo = 0x02,
133  ForceVectorOutput = 0x04,
134  UseAdvancedEffects = 0x08,
135  DrawLabeling = 0x10,
136  UseRenderingOptimization = 0x20,
137  DrawSelection = 0x40,
138  DrawSymbolBounds = 0x80,
139  RenderMapTile = 0x100
140  // TODO: ignore scale-based visibility (overview)
141  };
142  Q_DECLARE_FLAGS( Flags, Flag )
143 
144 
145  void setFlags( const QgsMapSettings::Flags& flags );
147  void setFlag( Flag flag, bool on = true );
149  Flags flags() const;
151  bool testFlag( Flag flag ) const;
152 
154  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
156  QImage::Format outputImageFormat() const { return mImageFormat; }
157 
159  bool hasValidSettings() const;
161  QgsRectangle visibleExtent() const;
164  QPolygonF visiblePolygon() const;
166  double mapUnitsPerPixel() const;
168  double scale() const;
169 
175  void setExpressionContext( const QgsExpressionContext& context ) { mExpressionContext = context; }
176 
182  const QgsExpressionContext& expressionContext() const { return mExpressionContext; }
183 
184  // -- utility functions --
185 
187  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
188  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
189 
190  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
191 
197  double layerToMapUnits( QgsMapLayer* theLayer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
198 
204  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
205 
211  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
212 
217  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
218 
224  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
225 
230  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
231 
237  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
238 
244  const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
245 
247  QgsRectangle fullExtent() const;
248 
249  /* serialization */
250 
251  void readXML( QDomNode& theNode );
252 
253  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
254 
255  protected:
256 
257  int mDpi;
258 
260 
262 
263  double mRotation;
264 
268 
272 
275 
276  Flags mFlags;
277 
278  QImage::Format mImageFormat;
279 
280  // derived properties
281  bool mValid;
284  double mScale;
285 
286 
287  // utiity stuff
290 
291  void updateDerived();
292 };
293 
294 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
295 
296 
297 #endif // QGSMAPSETTINGS_H
const QgsDatumTransformStore & datumTransformStore() const
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
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
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...
QgsExpressionContext mExpressionContext
QgsScaleCalculator mScaleCalculator
A class to represent a point.
Definition: qgspoint.h:117
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
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:155
QStringList mLayers
QColor mSelectionColor
QgsDatumTransformStore mDatumTransformStore
const QgsExpressionContext & expressionContext() const
Gets the expression context.