QGIS API Documentation  2.5.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 
75  int outputDpi() const;
77  void setOutputDpi( int dpi );
78 
81  QStringList layers() const;
84  void setLayers( const QStringList& layers );
85 
87  void setCrsTransformEnabled( bool enabled );
89  bool hasCrsTransformEnabled() const;
90 
92  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
94  const QgsCoordinateReferenceSystem& destinationCrs() const;
95 
97  QGis::UnitType mapUnits() const;
99  void setMapUnits( QGis::UnitType u );
100 
102  void setBackgroundColor( const QColor& color ) { mBackgroundColor = color; }
104  QColor backgroundColor() const { return mBackgroundColor; }
105 
107  void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
109  QColor selectionColor() const { return mSelectionColor; }
110 
112  enum Flag
113  {
114  Antialiasing = 0x01,
115  DrawEditingInfo = 0x02,
116  ForceVectorOutput = 0x04,
117  UseAdvancedEffects = 0x08,
118  DrawLabeling = 0x10,
119  UseRenderingOptimization = 0x20,
120  DrawSelection = 0x40,
121  // TODO: ignore scale-based visibility (overview)
122  };
123  Q_DECLARE_FLAGS( Flags, Flag )
124 
125 
126  void setFlags( Flags flags );
128  void setFlag( Flag flag, bool on = true );
130  Flags flags() const;
132  bool testFlag( Flag flag ) const;
133 
135  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
137  QImage::Format outputImageFormat() const { return mImageFormat; }
138 
140  bool hasValidSettings() const;
142  QgsRectangle visibleExtent() const;
144  double mapUnitsPerPixel() const;
146  double scale() const;
147 
148 
149  // -- utility functions --
150 
151  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
152  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
153 
154  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
155 
161  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
162 
168  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
169 
174  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
175 
181  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
182 
187  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
188 
194  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
195 
201  const QgsCoordinateTransform* layerTransfrom( QgsMapLayer *layer ) const;
202 
204  QgsRectangle fullExtent() const;
205 
206  /* serialization */
207 
208  void readXML( QDomNode& theNode );
209 
210  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
211 
212  protected:
213 
214  int mDpi;
215 
216  QSize mSize;
217 
219 
220  QStringList mLayers;
221 
225 
228 
229  Flags mFlags;
230 
231  QImage::Format mImageFormat;
232 
233  // derived properties
234  bool mValid;
237  double mScale;
238 
239 
240  // utiity stuff
243 
244  void updateDerived();
245 };
246 
247 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
248 
249 
250 #endif // QGSMAPSETTINGS_H
const QgsDatumTransformStore & datumTransformStore() const
Definition: qgsmapsettings.h:151
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
QgsDatumTransformStore & datumTransformStore()
Definition: qgsmapsettings.h:152
QgsRectangle mVisibleExtent
extent with some additional white space that matches the output aspect ratio
Definition: qgsmapsettings.h:235
QgsMapToPixel mMapToPixel
Definition: qgsmapsettings.h:242
Abstract base class for map rendering implementations.
Definition: qgsmaprendererjob.h:78
UnitType
Map units that qgis supports.
Definition: qgis.h:229
QColor selectionColor() const
Get color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:109
QgsCoordinateReferenceSystem mDestCRS
Definition: qgsmapsettings.h:223
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:154
The QgsMapSettings class contains configuration for rendering of the map.
Definition: qgsmapsettings.h:52
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
QImage::Format mImageFormat
Definition: qgsmapsettings.h:231
bool mValid
whether the actual settings are valid (set in updateDerived())
Definition: qgsmapsettings.h:234
QgsRectangle mExtent
Definition: qgsmapsettings.h:218
int mDpi
Definition: qgsmapsettings.h:214
Flag
Enumeration of flags that adjust the way how map is rendered.
Definition: qgsmapsettings.h:112
QgsScaleCalculator mScaleCalculator
Definition: qgsmapsettings.h:241
A class to represent a point geometry.
Definition: qgspoint.h:63
QColor backgroundColor() const
Get the background color of the map.
Definition: qgsmapsettings.h:104
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
Definition: qgsscalecalculator.h:31
double mScale
Definition: qgsmapsettings.h:237
void setBackgroundColor(const QColor &color)
Set the background color of the map.
Definition: qgsmapsettings.h:102
double mMapUnitsPerPixel
Definition: qgsmapsettings.h:236
void setSelectionColor(const QColor &color)
Set color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:107
The QgsDatumTransformStore class keeps track of datum transformations as chosen by the user...
Definition: qgsdatumtransformstore.h:32
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
Definition: qgsmapsettings.h:137
Class for storing a coordinate reference system (CRS)
Definition: qgscoordinatereferencesystem.h:50
QColor mBackgroundColor
Definition: qgsmapsettings.h:226
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:52
QSize mSize
Definition: qgsmapsettings.h:216
QStringList mLayers
Definition: qgsmapsettings.h:220
QColor mSelectionColor
Definition: qgsmapsettings.h:227
QgsDatumTransformStore mDatumTransformStore
Definition: qgsmapsettings.h:224
Flags mFlags
Definition: qgsmapsettings.h:229
double size
Definition: qgssvgcache.cpp:77
bool mProjectionsEnabled
Definition: qgsmapsettings.h:222