QGIS API Documentation  3.6.0-Noosa (5873452)
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 
29 #include "qgsmaptopixel.h"
30 #include "qgsrectangle.h"
31 #include "qgsscalecalculator.h"
32 #include "qgsexpressioncontext.h"
33 #include "qgsmaplayer.h"
34 #include "qgsgeometry.h"
35 
36 class QPainter;
37 
39 class QgsScaleCalculator;
40 class QgsMapRendererJob;
41 
50 class CORE_EXPORT QgsLabelBlockingRegion
51 {
52  public:
53 
57  explicit QgsLabelBlockingRegion( const QgsGeometry &geometry )
58  : geometry( geometry )
59  {}
60 
63 
64 };
65 
66 
84 class CORE_EXPORT QgsMapSettings
85 {
86  public:
88 
95  QgsRectangle extent() const;
96 
103  void setExtent( const QgsRectangle &rect, bool magnified = true );
104 
106  QSize outputSize() const;
108  void setOutputSize( QSize size );
109 
115  float devicePixelRatio() const;
116 
122  void setDevicePixelRatio( float dpr );
123 
130  QSize deviceOutputSize() const;
131 
137  double rotation() const;
138 
144  void setRotation( double rotation );
145 
150  double outputDpi() const;
152  void setOutputDpi( double dpi );
153 
160  void setMagnificationFactor( double factor );
161 
167  double magnificationFactor() const;
168 
173  QStringList layerIds() const;
174 
179  QList<QgsMapLayer *> layers() const;
180 
187  void setLayers( const QList<QgsMapLayer *> &layers );
188 
193  QMap<QString, QString> layerStyleOverrides() const;
194 
199  void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
200 
207  QString customRenderFlags() const { return mCustomRenderFlags; }
208 
215  void setCustomRenderFlags( const QString &customRenderFlags ) { mCustomRenderFlags = customRenderFlags; }
216 
218  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
220  QgsCoordinateReferenceSystem destinationCrs() const;
221 
223  QgsUnitTypes::DistanceUnit mapUnits() const;
224 
233  bool setEllipsoid( const QString &ellipsoid );
234 
241  QString ellipsoid() const { return mEllipsoid; }
242 
244  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
246  QColor backgroundColor() const { return mBackgroundColor; }
247 
249  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
251  QColor selectionColor() const { return mSelectionColor; }
252 
254  enum Flag
255  {
256  Antialiasing = 0x01,
257  DrawEditingInfo = 0x02,
258  ForceVectorOutput = 0x04,
259  UseAdvancedEffects = 0x08,
260  DrawLabeling = 0x10,
261  UseRenderingOptimization = 0x20,
262  DrawSelection = 0x40,
263  DrawSymbolBounds = 0x80,
264  RenderMapTile = 0x100,
265  RenderPartialOutput = 0x200,
266  RenderPreviewJob = 0x400,
267  // TODO: ignore scale-based visibility (overview)
268  };
269  Q_DECLARE_FLAGS( Flags, Flag )
270 
271 
272  void setFlags( QgsMapSettings::Flags flags );
274  void setFlag( Flag flag, bool on = true );
276  Flags flags() const;
278  bool testFlag( Flag flag ) const;
279 
287  {
288  return mTextRenderFormat;
289  }
290 
301  {
302  mTextRenderFormat = format;
303  // ensure labeling engine setting is also kept in sync, just in case anyone accesses QgsMapSettings::labelingEngineSettings().defaultTextRenderFormat()
304  // instead of correctly calling QgsMapSettings::textRenderFormat(). It can't hurt to be consistent!
305  mLabelingEngineSettings.setDefaultTextRenderFormat( format );
306  }
307 
309  void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
311  QImage::Format outputImageFormat() const { return mImageFormat; }
312 
314  bool hasValidSettings() const;
316  QgsRectangle visibleExtent() const;
317 
322  QPolygonF visiblePolygon() const;
324  double mapUnitsPerPixel() const;
325 
330  double scale() const;
331 
338  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
339 
346  const QgsExpressionContext &expressionContext() const { return mExpressionContext; }
347 
356  QgsCoordinateTransformContext transformContext() const;
357 
366  void setTransformContext( const QgsCoordinateTransformContext &context );
367 
375  const QgsPathResolver &pathResolver() const { return mPathResolver; }
376 
384  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
385 
386  const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
387 
394  double layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent = QgsRectangle() ) const;
395 
401  QgsRectangle layerExtentToOutputExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
402 
408  QgsRectangle outputExtentToLayerExtent( const QgsMapLayer *layer, QgsRectangle extent ) const;
409 
414  QgsPointXY layerToMapCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
415 
421  QgsRectangle layerToMapCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
422 
427  QgsPointXY mapToLayerCoordinates( const QgsMapLayer *layer, QgsPointXY point ) const;
428 
434  QgsRectangle mapToLayerCoordinates( const QgsMapLayer *layer, QgsRectangle rect ) const;
435 
440  QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
441 
443  QgsRectangle fullExtent() const;
444 
445  /* serialization */
446 
447  void readXml( QDomNode &node );
448 
449  void writeXml( QDomNode &node, QDomDocument &doc );
450 
454  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
456  double segmentationTolerance() const { return mSegmentationTolerance; }
457 
461  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
463  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
464 
476  {
477  mLabelingEngineSettings = settings;
478  mTextRenderFormat = settings.defaultTextRenderFormat();
479  }
480 
488  const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; }
489 
501  QgsGeometry labelBoundaryGeometry() const;
502 
516  void setLabelBoundaryGeometry( const QgsGeometry &boundary );
517 
524  void setLabelBlockingRegions( const QList< QgsLabelBlockingRegion > &regions ) { mLabelBlockingRegions = regions; }
525 
532  QList< QgsLabelBlockingRegion > labelBlockingRegions() const { return mLabelBlockingRegions; }
533 
534  protected:
535 
536  double mDpi;
537 
538  QSize mSize;
539  float mDevicePixelRatio = 1.0;
540 
542 
543  double mRotation = 0.0;
544  double mMagnificationFactor = 1.0;
545 
548  QMap<QString, QString> mLayerStyleOverrides;
551 
554  QString mEllipsoid;
555 
558 
559  Flags mFlags;
560 
561  QImage::Format mImageFormat = QImage::Format_ARGB32_Premultiplied;
562 
565 
567 
568  // derived properties
569  bool mValid = false;
571  double mMapUnitsPerPixel = 1;
572  double mScale = 1;
573 
574  // utiity stuff
577 
579 
581 
583 
585 
586 #ifdef QGISDEBUG
587  bool mHasTransformContext = false;
588 #endif
589 
590  void updateDerived();
591 
592  private:
593 
594  QList< QgsLabelBlockingRegion > mLabelBlockingRegions;
595 };
596 
597 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
598 
599 
600 #endif // QGSMAPSETTINGS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:64
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) ...
QgsRenderContext::TextRenderFormat defaultTextRenderFormat() const
Returns the default text rendering format for the labels.
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.
QgsGeometry mLabelBoundaryGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
const QgsCoordinateReferenceSystem & crs
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:37
QgsRectangle mExtent
void setTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
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
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Label blocking region (in map coordinates and CRS).
Contains information about the context in which a coordinate transform is executed.
QgsExpressionContext mExpressionContext
TextRenderFormat
Options for rendering text.
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:54
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 the 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:1555
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...
QgsLabelBlockingRegion(const QgsGeometry &geometry)
Constructor for a label blocking region.
QgsGeometry geometry
Geometry of region to avoid placing labels within (in destination map coordinates and CRS) ...
QgsRenderContext::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
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.
QList< QgsLabelBlockingRegion > labelBlockingRegions() const
Returns the list of regions to avoid placing labels within.
QString mCustomRenderFlags
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
void setLabelBlockingRegions(const QList< QgsLabelBlockingRegion > &regions)
Sets a list of regions to avoid placing labels within.