QGIS API Documentation  2.12.0-Lyon
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( const 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  // TODO: ignore scale-based visibility (overview)
139  };
140  Q_DECLARE_FLAGS( Flags, Flag )
141 
142 
143  void setFlags( const QgsMapSettings::Flags& flags );
145  void setFlag( Flag flag, bool on = true );
147  Flags flags() const;
149  bool testFlag( Flag flag ) const;
150 
152  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
154  QImage::Format outputImageFormat() const { return mImageFormat; }
155 
157  bool hasValidSettings() const;
159  QgsRectangle visibleExtent() const;
162  QPolygonF visiblePolygon() const;
164  double mapUnitsPerPixel() const;
166  double scale() const;
167 
173  void setExpressionContext( const QgsExpressionContext& context ) { mExpressionContext = context; }
174 
180  const QgsExpressionContext& expressionContext() const { return mExpressionContext; }
181 
182  // -- utility functions --
183 
184  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
185  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
186 
187  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
188 
194  double layerToMapUnits( QgsMapLayer* theLayer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
195 
201  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
202 
208  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
209 
214  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
215 
221  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
222 
227  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
228 
234  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
235 
241  const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
242 
244  QgsRectangle fullExtent() const;
245 
246  /* serialization */
247 
248  void readXML( QDomNode& theNode );
249 
250  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
251 
252  protected:
253 
254  int mDpi;
255 
257 
259 
260  double mRotation;
261 
265 
269 
272 
273  Flags mFlags;
274 
275  QImage::Format mImageFormat;
276 
277  // derived properties
278  bool mValid;
281  double mScale;
282 
283 
284  // utiity stuff
287 
288  void updateDerived();
289 };
290 
291 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
292 
293 
294 #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.
UnitType
Map units that qgis supports.
Definition: qgis.h:147
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:63
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.
QStringList mLayers
QColor mSelectionColor
QgsDatumTransformStore mDatumTransformStore
const QgsExpressionContext & expressionContext() const
Gets the expression context.