QGIS API Documentation  2.4.0-Chugiak
 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 
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
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:47
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.
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:33
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 geometry.
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.
UnitType
Map units that qgis supports.
Definition: qgis.h:229
QStringList mLayers
QColor mSelectionColor
QgsDatumTransformStore mDatumTransformStore
double size
Definition: qgssvgcache.cpp:77