QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
30 class QPainter;
31 
33 class QgsScaleCalculator;
34 class QgsMapRendererJob;
35 class QgsMapLayer;
36 
37 
52 class CORE_EXPORT QgsMapSettings
53 {
54  public:
56 
61  QgsRectangle extent() const;
66  void setExtent( const QgsRectangle& rect );
67 
69  QSize outputSize() const;
71  void setOutputSize( const QSize& size );
72 
76  double rotation() const;
80  void setRotation( double degrees );
81 
84  int outputDpi() const;
86  void setOutputDpi( int dpi );
87 
90  QStringList layers() const;
93  void setLayers( const QStringList& layers );
94 
97  QMap<QString, QString> layerStyleOverrides() const;
100  void setLayerStyleOverrides( const QMap<QString, QString>& overrides );
101 
103  void setCrsTransformEnabled( bool enabled );
105  bool hasCrsTransformEnabled() const;
106 
108  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
110  const QgsCoordinateReferenceSystem& destinationCrs() const;
111 
113  QGis::UnitType mapUnits() const;
115  void setMapUnits( QGis::UnitType u );
116 
118  void setBackgroundColor( const QColor& color ) { mBackgroundColor = color; }
120  QColor backgroundColor() const { return mBackgroundColor; }
121 
123  void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
125  QColor selectionColor() const { return mSelectionColor; }
126 
128  enum Flag
129  {
130  Antialiasing = 0x01,
131  DrawEditingInfo = 0x02,
132  ForceVectorOutput = 0x04,
133  UseAdvancedEffects = 0x08,
134  DrawLabeling = 0x10,
135  UseRenderingOptimization = 0x20,
136  DrawSelection = 0x40,
137  // TODO: ignore scale-based visibility (overview)
138  };
139  Q_DECLARE_FLAGS( Flags, Flag )
140 
141 
142  void setFlags( Flags flags );
144  void setFlag( Flag flag, bool on = true );
146  Flags flags() const;
148  bool testFlag( Flag flag ) const;
149 
151  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
153  QImage::Format outputImageFormat() const { return mImageFormat; }
154 
156  bool hasValidSettings() const;
158  QgsRectangle visibleExtent() const;
160  double mapUnitsPerPixel() const;
162  double scale() const;
163 
164 
165  // -- utility functions --
166 
167  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
168  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
169 
170  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
171 
177  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
178 
184  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
185 
190  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
191 
197  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
198 
203  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
204 
210  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
211 
217  const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
218 
220  QgsRectangle fullExtent() const;
221 
222  /* serialization */
223 
224  void readXML( QDomNode& theNode );
225 
226  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
227 
228  protected:
229 
230  int mDpi;
231 
232  QSize mSize;
233 
235 
236  double mRotation;
237 
238  QStringList mLayers;
239  QMap<QString, QString> mLayerStyleOverrides;
240 
244 
247 
248  Flags mFlags;
249 
250  QImage::Format mImageFormat;
251 
252  // derived properties
253  bool mValid;
256  double mScale;
257 
258 
259  // utiity stuff
262 
263  void updateDerived();
264 };
265 
266 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
267 
268 
269 #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.
UnitType
Map units that qgis supports.
Definition: qgis.h:229
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.
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
double size
Definition: qgssvgcache.cpp:77