QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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;
161  QPolygonF visiblePolygon() const;
163  double mapUnitsPerPixel() const;
165  double scale() const;
166 
167 
168  // -- utility functions --
169 
170  const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
171  QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
172 
173  const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
174 
180  QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
181 
187  QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
188 
193  QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
194 
200  QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
201 
206  QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
207 
213  QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
214 
220  const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
221 
223  QgsRectangle fullExtent() const;
224 
225  /* serialization */
226 
227  void readXML( QDomNode& theNode );
228 
229  void writeXML( QDomNode& theNode, QDomDocument& theDoc );
230 
231  protected:
232 
233  int mDpi;
234 
235  QSize mSize;
236 
238 
239  double mRotation;
240 
241  QStringList mLayers;
242  QMap<QString, QString> mLayerStyleOverrides;
243 
247 
250 
251  Flags mFlags;
252 
253  QImage::Format mImageFormat;
254 
255  // derived properties
256  bool mValid;
259  double mScale;
260 
261 
262  // utiity stuff
265 
266  void updateDerived();
267 };
268 
269 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
270 
271 
272 #endif // QGSMAPSETTINGS_H