QGIS API Documentation  3.2.0-Bonn (bc43194)
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"
30 #include "qgsmaptopixel.h"
31 #include "qgsrectangle.h"
32 #include "qgsscalecalculator.h"
33 #include "qgsexpressioncontext.h"
34 #include "qgsmaplayer.h"
35 
36 class QPainter;
37 
39 class QgsScaleCalculator;
40 class QgsMapRendererJob;
41 
42 
58 class CORE_EXPORT QgsMapSettings
59 {
60  public:
62 
69  QgsRectangle extent() const;
70 
77  void setExtent( const QgsRectangle &rect, bool magnified = true );
78 
80  QSize outputSize() const;
82  void setOutputSize( QSize size );
83 
89  double rotation() const;
90 
96  void setRotation( double rotation );
97 
102  double outputDpi() const;
104  void setOutputDpi( double dpi );
105 
112  void setMagnificationFactor( double factor );
113 
119  double magnificationFactor() const;
120 
125  QStringList layerIds() const;
126 
131  QList<QgsMapLayer *> layers() const;
132 
139  void setLayers( const QList<QgsMapLayer *> &layers );
140 
145  QMap<QString, QString> layerStyleOverrides() const;
146 
151  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
152 
159  QString customRenderFlags() const { return mCustomRenderFlags; }
160 
167  void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
168 
170  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
172  QgsCoordinateReferenceSystem destinationCrs() const;
173 
175  QgsUnitTypes::DistanceUnit mapUnits() const;
176 
185  bool setEllipsoid( const QString &ellipsoid );
186 
193  QString ellipsoid() const { return mEllipsoid; }
194 
196  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
198  QColor backgroundColor() const { return mBackgroundColor; }
199 
201  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
203  QColor selectionColor() const { return mSelectionColor; }
204 
206  enum Flag
207  {
208  Antialiasing = 0x01,
209  DrawEditingInfo = 0x02,
210  ForceVectorOutput = 0x04,
211  UseAdvancedEffects = 0x08,
212  DrawLabeling = 0x10,
213  UseRenderingOptimization = 0x20,
214  DrawSelection = 0x40,
215  DrawSymbolBounds = 0x80,
216  RenderMapTile = 0x100,
217  RenderPartialOutput = 0x200,
218  RenderPreviewJob = 0x400,
219  // TODO: ignore scale-based visibility (overview)
220  };
221  Q_DECLARE_FLAGS( Flags, Flag )
222 
223 
224  void setFlags( QgsMapSettings::Flags flags );
226  void setFlag( Flag flag, bool on = true );
228  Flags flags() const;
230  bool testFlag( Flag flag ) const;
231 
233  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
235  QImage::Format outputImageFormat() const { return mImageFormat; }
236 
238  bool hasValidSettings() const;
240  QgsRectangle visibleExtent() const;
241 
246  QPolygonF visiblePolygon() const;
248  double mapUnitsPerPixel() const;
249 
254  double scale() const;
255 
262  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
263 
270  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
271 
280  QgsCoordinateTransformContext transformContext() const;
281 
290  void setTransformContext( const QgsCoordinateTransformContext &context );
291 
299  const QgsPathResolver &pathResolver() const { return mPathResolver; }
300 
308  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
309 
310  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
311 
318  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
319 
325  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
326 
332  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
333 
338  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
339 
345  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
346 
351  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
352 
358  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
359 
364  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
365 
367  QgsRectangle fullExtent() const;
368 
369  /* serialization */
370 
371  void readXml( QDomNode &node );
372 
373  void writeXml( QDomNode &node, QDomDocument &doc );
374 
378  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
380  double segmentationTolerance() const { return mSegmentationTolerance; }
381 
385  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
387  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
388 
393  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ) { mLabelingEngineSettings = settings; }
394 
399  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
400 
401  protected:
402 
403  double mDpi;
404 
405  QSize mSize;
406 
408 
409  double mRotation = 0.0;
410  double mMagnificationFactor = 1.0;
411 
414  QMap<QString, QString> mLayerStyleOverrides;
417 
420  QString mEllipsoid;
421 
424 
425  Flags mFlags;
426 
427  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
428 
431 
433 
434  // derived properties
435  bool mValid = false;
437  double mMapUnitsPerPixel = 1;
438  double mScale = 1;
439 
440  // utiity stuff
443 
445 
447 
448 #ifdef QGISDEBUG
449  bool mHasTransformContext = false;
450 #endif
451 
452  void updateDerived();
453 };
454 
455 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
456 
457 
458 #endif // QGSMAPSETTINGS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Base class for all map layer types.
Definition: qgsmaplayer.h:61
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
QgsCoordinateTransformContext mTransformContext
A class to represent a 2D point.
Definition: qgspointxy.h:43
QMap< QString, QString > mLayerStyleOverrides
QColor backgroundColor() const
Gets the background color of the map.
void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
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
Gets 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.
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.
QgsPathResolver mPathResolver
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Contains information about the context in which a coordinate transform is executed.
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...
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
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)
Sets 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)
Sets color that is used for drawing of selected vector features.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1392
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.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
QColor selectionColor() const
Gets color that is used for drawing of selected vector features.
QColor mSelectionColor
Resolves relative paths into absolute paths and vice versa.
QString mCustomRenderFlags
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns global configuration of the labeling engine.