QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
60 class CORE_EXPORT QgsMapSettings
61 {
62  public:
64 
71  QgsRectangle extent() const;
72 
79  void setExtent( const QgsRectangle &rect, bool magnified = true );
80 
82  QSize outputSize() const;
84  void setOutputSize( QSize size );
85 
91  float devicePixelRatio() const;
92 
98  void setDevicePixelRatio( float dpr );
99 
106  QSize deviceOutputSize() const;
107 
113  double rotation() const;
114 
120  void setRotation( double rotation );
121 
126  double outputDpi() const;
128  void setOutputDpi( double dpi );
129 
136  void setMagnificationFactor( double factor );
137 
143  double magnificationFactor() const;
144 
149  QStringList layerIds() const;
150 
155  QList<QgsMapLayer *> layers() const;
156 
163  void setLayers( const QList<QgsMapLayer *> &layers );
164 
169  QMap<QString, QString> layerStyleOverrides() const;
170 
175  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
176 
183  QString customRenderFlags() const { return mCustomRenderFlags; }
184 
191  void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
192 
194  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
196  QgsCoordinateReferenceSystem destinationCrs() const;
197 
199  QgsUnitTypes::DistanceUnit mapUnits() const;
200 
209  bool setEllipsoid( const QString &ellipsoid );
210 
217  QString ellipsoid() const { return mEllipsoid; }
218 
220  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
222  QColor backgroundColor() const { return mBackgroundColor; }
223 
225  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
227  QColor selectionColor() const { return mSelectionColor; }
228 
230  enum Flag
231  {
232  Antialiasing = 0x01,
233  DrawEditingInfo = 0x02,
234  ForceVectorOutput = 0x04,
235  UseAdvancedEffects = 0x08,
236  DrawLabeling = 0x10,
237  UseRenderingOptimization = 0x20,
238  DrawSelection = 0x40,
239  DrawSymbolBounds = 0x80,
240  RenderMapTile = 0x100,
241  RenderPartialOutput = 0x200,
242  RenderPreviewJob = 0x400,
243  // TODO: ignore scale-based visibility (overview)
244  };
245  Q_DECLARE_FLAGS( Flags, Flag )
246 
247 
248  void setFlags( QgsMapSettings::Flags flags );
250  void setFlag( Flag flag, bool on = true );
252  Flags flags() const;
254  bool testFlag( Flag flag ) const;
255 
262  QgsRenderContext::TextRenderFormat textRenderFormat() const
263  {
264  return mTextRenderFormat;
265  }
266 
277  {
278  mTextRenderFormat = format;
279  // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
280  // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
281  mLabelingEngineSettings.setDefaultTextRenderFormat( format );
282  }
283 
285  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
287  QImage::Format outputImageFormat() const { return mImageFormat; }
288 
290  bool hasValidSettings() const;
292  QgsRectangle visibleExtent() const;
293 
298  QPolygonF visiblePolygon() const;
300  double mapUnitsPerPixel() const;
301 
306  double scale() const;
307 
314  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
315 
322  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
323 
332  QgsCoordinateTransformContext transformContext() const;
333 
342  void setTransformContext( const QgsCoordinateTransformContext &context );
343 
351  const QgsPathResolver &pathResolver() const { return mPathResolver; }
352 
360  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
361 
362  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
363 
370  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
371 
377  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
378 
384  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
385 
390  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
391 
397  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
398 
403  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
404 
410  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
411 
416  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
417 
419  QgsRectangle fullExtent() const;
420 
421  /* serialization */
422 
423  void readXml( QDomNode &node );
424 
425  void writeXml( QDomNode &node, QDomDocument &doc );
426 
430  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
432  double segmentationTolerance() const { return mSegmentationTolerance; }
433 
437  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
439  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
440 
452  {
453  mLabelingEngineSettings = settings;
454  mTextRenderFormat = settings.defaultTextRenderFormat();
455  }
456 
464  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
465 
466  protected:
467 
468  double mDpi;
469 
470  QSize mSize;
471  float mDevicePixelRatio = 1.0;
472 
474 
475  double mRotation = 0.0;
476  double mMagnificationFactor = 1.0;
477 
480  QMap<QString, QString> mLayerStyleOverrides;
483 
486  QString mEllipsoid;
487 
490 
491  Flags mFlags;
492 
493  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
494 
497 
499 
500  // derived properties
501  bool mValid = false;
503  double mMapUnitsPerPixel = 1;
504  double mScale = 1;
505 
506  // utiity stuff
509 
511 
513 
515 
516 #ifdef QGISDEBUG
517  bool mHasTransformContext = false;
518 #endif
519 
520  void updateDerived();
521 };
522 
523 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
524 
525 
526 #endif // QGSMAPSETTINGS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Base class for all map layer types.
Definition: qgsmaplayer.h:63
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
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.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Maximum angle between generating radii (lines from arc center to output vertices) ...
QColor selectionColor() const
Gets color that is used for drawing of selected vector features.
QgsCoordinateReferenceSystem mDestCRS
QgsCoordinateTransformContext mTransformContext
A class to represent a 2D point.
Definition: qgspointxy.h:43
QMap< QString, QString > mLayerStyleOverrides
void setCustomRenderFlags(const QString &customRenderFlags)
Sets the custom rendering flags.
const QgsMapToPixel & mapToPixel() const
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
const QgsCoordinateReferenceSystem & crs
QgsRenderContext::TextRenderFormat defaultTextRenderFormat() const
Returns the default text rendering format for the labels.
QgsLabelingEngineSettings mLabelingEngineSettings
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
QgsRectangle mExtent
void setTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
Flag
Enumeration of flags that adjust the way the map is rendered.
Always render text using path objects (AKA outlines/curves).
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
QString customRenderFlags() const
Gets custom rendering flags.
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Contains information about the context in which a coordinate transform is executed.
QgsExpressionContext mExpressionContext
TextRenderFormat
Options for rendering text.
QgsScaleCalculator mScaleCalculator
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
QColor backgroundColor() const
Gets the background color of the map.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:53
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
Contains information about the context of a rendering operation.
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
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:1489
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
Stores global configuration for labeling engine.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
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 mSelectionColor
Resolves relative paths into absolute paths and vice versa.
QString mCustomRenderFlags
const QgsExpressionContext & expressionContext() const
Gets the expression context.