QGIS API Documentation  2.99.0-Master (dcec6bb)
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 "qgis_core.h"
20 #include "qgis_sip.h"
21 #include <QColor>
22 #include <QImage>
23 #include <QPointer>
24 #include <QSize>
25 #include <QStringList>
26 
27 #include "qgsabstractgeometry.h"
29 #include "qgsdatumtransformstore.h"
31 #include "qgsmaptopixel.h"
32 #include "qgsrectangle.h"
33 #include "qgsscalecalculator.h"
34 #include "qgsexpressioncontext.h"
35 #include "qgsmaplayer.h"
36 
37 class QPainter;
38 
40 class QgsScaleCalculator;
41 class QgsMapRendererJob;
42 
43 
58 class CORE_EXPORT QgsMapSettings
59 {
60  public:
62 
67  QgsRectangle extent() const;
72  void setExtent( const QgsRectangle &rect, bool magnified = true );
73 
75  QSize outputSize() const;
77  void setOutputSize( QSize size );
78 
84  double rotation() const;
85 
91  void setRotation( double rotation );
92 
95  double outputDpi() const;
97  void setOutputDpi( double dpi );
98 
105  void setMagnificationFactor( double factor );
106 
110  double magnificationFactor() const;
111 
114  QStringList layerIds() const;
117  QList<QgsMapLayer *> layers() const;
120  void setLayers( const QList<QgsMapLayer *> &layers );
121 
124  QMap<QString, QString> layerStyleOverrides() const;
127  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
128 
134  QString customRenderFlags() const { return mCustomRenderFlags; }
135 
141  void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
142 
144  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
146  QgsCoordinateReferenceSystem destinationCrs() const;
147 
149  QgsUnitTypes::DistanceUnit mapUnits() const;
150 
159  bool setEllipsoid( const QString &ellipsoid );
160 
166  QString ellipsoid() const { return mEllipsoid; }
167 
169  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
171  QColor backgroundColor() const { return mBackgroundColor; }
172 
174  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
176  QColor selectionColor() const { return mSelectionColor; }
177 
179  enum Flag
180  {
181  Antialiasing = 0x01,
182  DrawEditingInfo = 0x02,
183  ForceVectorOutput = 0x04,
184  UseAdvancedEffects = 0x08,
185  DrawLabeling = 0x10,
186  UseRenderingOptimization = 0x20,
187  DrawSelection = 0x40,
188  DrawSymbolBounds = 0x80,
189  RenderMapTile = 0x100,
190  RenderPartialOutput = 0x200,
191  // TODO: ignore scale-based visibility (overview)
192  };
193  Q_DECLARE_FLAGS( Flags, Flag )
194 
195 
196  void setFlags( QgsMapSettings::Flags flags );
198  void setFlag( Flag flag, bool on = true );
200  Flags flags() const;
202  bool testFlag( Flag flag ) const;
203 
205  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
207  QImage::Format outputImageFormat() const { return mImageFormat; }
208 
210  bool hasValidSettings() const;
212  QgsRectangle visibleExtent() const;
215  QPolygonF visiblePolygon() const;
217  double mapUnitsPerPixel() const;
218 
223  double scale() const;
224 
230  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
231 
237  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
238 
239  // -- utility functions --
240 
242  const QgsDatumTransformStore &datumTransformStore() const { return mDatumTransformStore; } SIP_SKIP
243  QgsDatumTransformStore &datumTransformStore() { return mDatumTransformStore; }
244 
245  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
246 
252  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
253 
259  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
260 
266  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
267 
272  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
273 
279  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
280 
285  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
286 
292  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
293 
299  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
300 
302  QgsRectangle fullExtent() const;
303 
304  /* serialization */
305 
306  void readXml( QDomNode &node );
307 
308  void writeXml( QDomNode &node, QDomDocument &doc );
309 
312  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
314  double segmentationTolerance() const { return mSegmentationTolerance; }
315 
318  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
320  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
321 
326  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ) { mLabelingEngineSettings = settings; }
327 
332  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
333 
334  protected:
335 
336  double mDpi;
337 
338  QSize mSize;
339 
341 
342  double mRotation;
344 
347  QMap<QString, QString> mLayerStyleOverrides;
350 
353  QString mEllipsoid;
355 
358 
359  Flags mFlags;
360 
361  QImage::Format mImageFormat;
362 
365 
367 
368  // derived properties
369  bool mValid;
372  double mScale;
373 
374  // utiity stuff
377 
378  void updateDerived();
379 };
380 
381 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
382 
383 
384 #endif // QGSMAPSETTINGS_H
double mMagnificationFactor
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Base class for all map layer types.
Definition: qgsmaplayer.h:54
QgsDatumTransformStore & datumTransformStore()
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
QgsMapToPixel mMapToPixel
Abstract base class for map rendering implementations.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QgsCoordinateReferenceSystem mDestCRS
A class to represent a 2D point.
Definition: qgspointxy.h:42
QMap< QString, QString > mLayerStyleOverrides
QColor backgroundColor() const
Get the background color of the map.
void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
const QgsDatumTransformStore & datumTransformStore() const
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
QgsLabelingEngineSettings mLabelingEngineSettings
The QgsMapSettings class contains configuration for rendering of the map.
QString customRenderFlags() const
Get custom rendering flags.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:35
QImage::Format mImageFormat
bool mValid
Whether the actual settings are valid (set in updateDerived())
QgsRectangle mExtent
Flag
Enumeration of flags that adjust the way the map is rendered.
#define SIP_SKIP
Definition: qgis_sip.h:119
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
QgsExpressionContext mExpressionContext
QgsScaleCalculator mScaleCalculator
const QgsMapToPixel & mapToPixel() const
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
void setBackgroundColor(const QColor &color)
Set the background color of the map.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets global configuration of the labeling engine.
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
double mMapUnitsPerPixel
double mSegmentationTolerance
void setSelectionColor(const QColor &color)
Set color that is used for drawing of selected vector features.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1105
The QgsDatumTransformStore class keeps track of datum transformations as chosen by the user...
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
Stores global configuration for labeling engine.
This class represents a coordinate reference system (CRS).
QColor mBackgroundColor
Class for doing transforms between two map coordinate systems.
QColor selectionColor() const
Get color that is used for drawing of selected vector features.
QColor mSelectionColor
QgsDatumTransformStore mDatumTransformStore
QString mCustomRenderFlags
QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns global configuration of the labeling engine.