QGIS API Documentation  2.99.0-Master (19b062c)
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 
59 class CORE_EXPORT QgsMapSettings
60 {
61  public:
63 
70  QgsRectangle extent() const;
71 
78  void setExtent( const QgsRectangle &rect, bool magnified = true );
79 
81  QSize outputSize() const;
83  void setOutputSize( QSize size );
84 
90  double rotation() const;
91 
97  void setRotation( double rotation );
98 
103  double outputDpi() const;
105  void setOutputDpi( double dpi );
106 
113  void setMagnificationFactor( double factor );
114 
120  double magnificationFactor() const;
121 
126  QStringList layerIds() const;
127 
132  QList<QgsMapLayer *> layers() const;
133 
138  void setLayers( const QList<QgsMapLayer *> &layers );
139 
144  QMap<QString, QString> layerStyleOverrides() const;
145 
150  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
151 
158  QString customRenderFlags() const { return mCustomRenderFlags; }
159 
166  void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
167 
169  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
171  QgsCoordinateReferenceSystem destinationCrs() const;
172 
174  QgsUnitTypes::DistanceUnit mapUnits() const;
175 
184  bool setEllipsoid( const QString &ellipsoid );
185 
192  QString ellipsoid() const { return mEllipsoid; }
193 
195  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
197  QColor backgroundColor() const { return mBackgroundColor; }
198 
200  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
202  QColor selectionColor() const { return mSelectionColor; }
203 
205  enum Flag
206  {
207  Antialiasing = 0x01,
208  DrawEditingInfo = 0x02,
209  ForceVectorOutput = 0x04,
210  UseAdvancedEffects = 0x08,
211  DrawLabeling = 0x10,
212  UseRenderingOptimization = 0x20,
213  DrawSelection = 0x40,
214  DrawSymbolBounds = 0x80,
215  RenderMapTile = 0x100,
216  RenderPartialOutput = 0x200,
217  RenderPreviewJob = 0x400,
218  // TODO: ignore scale-based visibility (overview)
219  };
220  Q_DECLARE_FLAGS( Flags, Flag )
221 
222 
223  void setFlags( QgsMapSettings::Flags flags );
225  void setFlag( Flag flag, bool on = true );
227  Flags flags() const;
229  bool testFlag( Flag flag ) const;
230 
232  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
234  QImage::Format outputImageFormat() const { return mImageFormat; }
235 
237  bool hasValidSettings() const;
239  QgsRectangle visibleExtent() const;
240 
245  QPolygonF visiblePolygon() const;
247  double mapUnitsPerPixel() const;
248 
253  double scale() const;
254 
261  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
262 
269  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
270 
271  // -- utility functions --
272 
274  const QgsDatumTransformStore &datumTransformStore() const { return mDatumTransformStore; } SIP_SKIP
275  QgsDatumTransformStore &datumTransformStore() { return mDatumTransformStore; }
276 
277  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
278 
285  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
286 
292  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
293 
299  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
300 
305  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
306 
312  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
313 
318  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
319 
325  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
326 
332  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
333 
335  QgsRectangle fullExtent() const;
336 
337  /* serialization */
338 
339  void readXml( QDomNode &node );
340 
341  void writeXml( QDomNode &node, QDomDocument &doc );
342 
346  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
348  double segmentationTolerance() const { return mSegmentationTolerance; }
349 
353  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
355  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
356 
361  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ) { mLabelingEngineSettings = settings; }
362 
367  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
368 
369  protected:
370 
371  double mDpi;
372 
373  QSize mSize;
374 
376 
377  double mRotation = 0.0;
378  double mMagnificationFactor = 1.0;
379 
382  QMap<QString, QString> mLayerStyleOverrides;
385 
388  QString mEllipsoid;
390 
393 
394  Flags mFlags;
395 
396  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
397 
400 
402 
403  // derived properties
404  bool mValid = false;
406  double mMapUnitsPerPixel = 1;
407  double mScale = 1;
408 
409  // utiity stuff
412 
413  void updateDerived();
414 };
415 
416 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
417 
418 
419 #endif // QGSMAPSETTINGS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:39
Base class for all map layer types.
Definition: qgsmaplayer.h:56
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.
Maximum angle between generating radii (lines from arc center to output vertices) ...
QgsCoordinateReferenceSystem mDestCRS
A class to represent a 2D point.
Definition: qgspointxy.h:43
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:36
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:43
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 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:1230
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
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns global configuration of the labeling engine.