QGIS API Documentation  2.99.0-Master (7d4f81d)
qgsrendercontext.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendercontext.h
3  ------------------
4  begin : March 16, 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : marco dot hugentobler at karto dot baug dot ethz dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSRENDERCONTEXT_H
19 #define QGSRENDERCONTEXT_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include <QColor>
24 #include <memory>
25 
26 #include "qgsabstractgeometry.h"
27 #include "qgscoordinatetransform.h"
28 #include "qgsexpressioncontext.h"
30 #include "qgsmaptopixel.h"
31 #include "qgsmapunitscale.h"
32 #include "qgsrectangle.h"
34 #include "qgsdistancearea.h"
35 
36 class QPainter;
38 class QgsLabelingEngine;
39 class QgsMapSettings;
40 
41 
48 class CORE_EXPORT QgsRenderContext
49 {
50  public:
52 
54  QgsRenderContext &operator=( const QgsRenderContext &rh );
55 
59  enum Flag
60  {
61  DrawEditingInfo = 0x01,
62  ForceVectorOutput = 0x02,
63  UseAdvancedEffects = 0x04,
64  UseRenderingOptimization = 0x08,
65  DrawSelection = 0x10,
66  DrawSymbolBounds = 0x20,
67  RenderMapTile = 0x40,
68  Antialiasing = 0x80,
69  RenderPartialOutput = 0x100,
70  };
71  Q_DECLARE_FLAGS( Flags, Flag )
72 
73 
76  void setFlags( QgsRenderContext::Flags flags );
77 
81  void setFlag( Flag flag, bool on = true );
82 
86  Flags flags() const;
87 
91  bool testFlag( Flag flag ) const;
92 
95  static QgsRenderContext fromMapSettings( const QgsMapSettings &mapSettings );
96 
103  static QgsRenderContext fromQPainter( QPainter *painter );
104 
105  //getters
106 
111  QPainter *painter() {return mPainter;}
112 
116  QgsCoordinateTransform coordinateTransform() const {return mCoordTransform;}
117 
122  const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
123 
124  const QgsRectangle &extent() const {return mExtent;}
125 
126  const QgsMapToPixel &mapToPixel() const {return mMapToPixel;}
127 
134  double scaleFactor() const {return mScaleFactor;}
135 
136  bool renderingStopped() const {return mRenderingStopped;}
137 
138  bool forceVectorOutput() const;
139 
142  bool useAdvancedEffects() const;
143 
146  void setUseAdvancedEffects( bool enabled );
147 
148  bool drawEditingInformation() const;
149 
155  double rendererScale() const {return mRendererScale;}
156 
159  QgsLabelingEngine *labelingEngine() const { return mLabelingEngine; } SIP_SKIP
160 
161  QColor selectionColor() const { return mSelectionColor; }
162 
169  bool showSelection() const;
170 
171  //setters
172 
174  void setCoordinateTransform( const QgsCoordinateTransform &t );
175  void setMapToPixel( const QgsMapToPixel &mtp ) {mMapToPixel = mtp;}
176  void setExtent( const QgsRectangle &extent ) {mExtent = extent;}
177 
178  void setDrawEditingInformation( bool b );
179 
180  void setRenderingStopped( bool stopped ) {mRenderingStopped = stopped;}
181 
187  void setDistanceArea( const QgsDistanceArea distanceArea ) {mDistanceArea = distanceArea ;}
188 
195  void setScaleFactor( double factor ) {mScaleFactor = factor;}
196 
202  void setRendererScale( double scale ) {mRendererScale = scale;}
203 
210  void setPainter( QPainter *p ) {mPainter = p;}
211 
212  void setForceVectorOutput( bool force );
213 
216  void setLabelingEngine( QgsLabelingEngine *engine2 ) { mLabelingEngine = engine2; } SIP_SKIP
217  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
218 
225  void setShowSelection( const bool showSelection );
226 
229  bool useRenderingOptimization() const;
230 
231  void setUseRenderingOptimization( bool enabled );
232 
234  const QgsVectorSimplifyMethod &vectorSimplifyMethod() const { return mVectorSimplifyMethod; }
235  void setVectorSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mVectorSimplifyMethod = simplifyMethod; }
236 
242  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
243 
249  QgsExpressionContext &expressionContext() { return mExpressionContext; }
250 
257  const QgsExpressionContext &expressionContext() const { return mExpressionContext; } SIP_SKIP
258 
260  const QgsAbstractGeometry *geometry() const { return mGeometry; }
262  void setGeometry( const QgsAbstractGeometry *geometry ) { mGeometry = geometry; }
263 
269  void setFeatureFilterProvider( const QgsFeatureFilterProvider *ffp );
270 
276  const QgsFeatureFilterProvider *featureFilterProvider() const;
277 
280  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
282  double segmentationTolerance() const { return mSegmentationTolerance; }
283 
286  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
288  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
289 
290  // Conversions
291 
298  double convertToPainterUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
299 
306  double convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
307 
313  double convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const;
314 
321  double convertMetersToMapUnits( double meters ) const;
322 
323  private:
324 
325  Flags mFlags;
326 
328  QPainter *mPainter = nullptr;
329 
331  QgsCoordinateTransform mCoordTransform;
332 
338  QgsDistanceArea mDistanceArea;
339 
340  QgsRectangle mExtent;
341 
342  QgsMapToPixel mMapToPixel;
343 
345  bool mRenderingStopped = false;
346 
348  double mScaleFactor = 1.0;
349 
351  double mRendererScale = 1.0;
352 
354  QgsLabelingEngine *mLabelingEngine = nullptr;
355 
357  QColor mSelectionColor;
358 
360  QgsVectorSimplifyMethod mVectorSimplifyMethod;
361 
363  QgsExpressionContext mExpressionContext;
364 
366  const QgsAbstractGeometry *mGeometry = nullptr;
367 
369  std::unique_ptr< QgsFeatureFilterProvider > mFeatureFilterProvider;
370 
371  double mSegmentationTolerance = M_PI_2 / 90;
372 
374 };
375 
376 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )
377 
378 #endif
void setRenderingStopped(bool stopped)
A rectangle specified with double values.
Definition: qgsrectangle.h:38
double rendererScale() const
Returns the renderer map scale.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
void setLabelingEngine(QgsLabelingEngine *engine2)
Assign new labeling engine.
Maximum angle between generating radii (lines from arc center to output vertices) ...
QgsLabelingEngine * labelingEngine() const
Get access to new labeling engine (may be nullptr)
void setRendererScale(double scale)
Sets the renderer map scale.
bool renderingStopped() const
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
void setExtent(const QgsRectangle &extent)
void setDistanceArea(const QgsDistanceArea distanceArea)
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
#define M_PI_2
Definition: util.cpp:45
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:35
void setSelectionColor(const QColor &color)
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void setGeometry(const QgsAbstractGeometry *geometry)
Sets pointer to original (unsegmentized) geometry.
const QgsRectangle & extent() const
#define SIP_SKIP
Definition: qgis_sip.h:119
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QColor selectionColor() const
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context, or an invalid transform is no coordinate tr...
Abstract interface for use by classes that filter the features of a layer.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Abstract base class for all geometries.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
The QgsLabelingEngine class provides map labeling functionality.
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Struct for storing maximum and minimum scales for measurements in map units.
const QgsDistanceArea & distanceArea() const
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
void setMapToPixel(const QgsMapToPixel &mtp)
Class for doing transforms between two map coordinate systems.
Flag
Enumeration of flags that affect rendering operations.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
const QgsExpressionContext & expressionContext() const
Gets the expression context (const version).
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:95
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.