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 
96  void setCrsTransformEnabled( bool enabled );
98  bool hasCrsTransformEnabled() const;
99 
101  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
103  const QgsCoordinateReferenceSystem& destinationCrs() const;
104 
106  QGis::UnitType mapUnits() const;
108  void setMapUnits( QGis::UnitType u );
109 
111  void setBackgroundColor( const QColor& color ) { mBackgroundColor = color; }
113  QColor backgroundColor() const { return mBackgroundColor; }
114 
116  void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
118  QColor selectionColor() const { return mSelectionColor; }
119 
121  enum Flag
122  {
123  Antialiasing = 0x01,
124  DrawEditingInfo = 0x02,
125  ForceVectorOutput = 0x04,
126  UseAdvancedEffects = 0x08,
127  DrawLabeling = 0x10,
128  UseRenderingOptimization = 0x20,
129  DrawSelection = 0x40,
130  // TODO: ignore scale-based visibility (overview)
131  };
132  Q_DECLARE_FLAGS( Flags, Flag )
133 
134 
135  void setFlags( Flags flags );
137  void setFlag( Flag flag, bool on = true );
139  Flags flags() const;
141  bool testFlag( Flag flag ) const;
142 
144  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
146  QImage::Format outputImageFormat() const { return mImageFormat; }
147 
149  bool hasValidSettings() const;
151  QgsRectangle visibleExtent() const;
153  double mapUnitsPerPixel() const;
155  double scale() const;
156 
157 
158  // -- utility functions --
159 
160  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
161  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
162 
163  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
164 
170  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
171 
177  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
178 
183  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
184 
190  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
191 
196  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
197 
203  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
204 
210  const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
211 
213  QgsRectangle fullExtent() const;
214 
215  /* serialization */
216 
217  void readXML( QDomNode& theNode );
218 
219  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
220 
221  protected:
222 
223  int mDpi;
224 
225  QSize mSize;
226 
228 
229  double mRotation;
230 
231  QStringList mLayers;
232 
236 
239 
240  Flags mFlags;
241 
242  QImage::Format mImageFormat;
243 
244  // derived properties
245  bool mValid;
248  double mScale;
249 
250 
251  // utiity stuff
254 
255  void updateDerived();
256 };
257 
258 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
259 
260 
261 #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:48
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
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