QGIS API Documentation  2.13.0-Master
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 
186  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
187  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
188 
189  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
190 
196  double layerToMapUnits( QgsMapLayer* theLayer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
197 
203  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
204 
210  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
211 
216  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
217 
223  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
224 
229  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
230 
236  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
237 
243  const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
244 
246  QgsRectangle fullExtent() const;
247 
248  /* serialization */
249 
250  void readXML( QDomNode& theNode );
251 
252  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
253 
254  protected:
255 
256  int mDpi;
257 
259 
261 
262  double mRotation;
263 
267 
271 
274 
275  Flags mFlags;
276 
277  QImage::Format mImageFormat;
278 
279  // derived properties
280  bool mValid;
283  double mScale;
284 
285 
286  // utiity stuff
289 
290  void updateDerived();
291 };
292 
293 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
294 
295 
296 #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:65
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.