QGIS API Documentation  2.99.0-Master (7fe5405)
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 <QColor>
23 
24 #include "qgsabstractgeometry.h"
25 #include "qgscoordinatetransform.h"
26 #include "qgsmaptopixel.h"
27 #include "qgsrectangle.h"
29 #include "qgsexpressioncontext.h"
31 
32 class QPainter;
34 class QgsLabelingEngine;
35 class QgsMapSettings;
36 
37 
44 class CORE_EXPORT QgsRenderContext
45 {
46  public:
48 
50  QgsRenderContext& operator=( const QgsRenderContext& rh );
51 
55  enum Flag
56  {
57  DrawEditingInfo = 0x01,
58  ForceVectorOutput = 0x02,
59  UseAdvancedEffects = 0x04,
60  UseRenderingOptimization = 0x08,
61  DrawSelection = 0x10,
62  DrawSymbolBounds = 0x20,
63  RenderMapTile = 0x40,
64  Antialiasing = 0x80,
65  RenderPartialOutput = 0x100,
66  };
67  Q_DECLARE_FLAGS( Flags, Flag )
68 
69 
72  void setFlags( QgsRenderContext::Flags flags );
73 
77  void setFlag( Flag flag, bool on = true );
78 
82  Flags flags() const;
83 
87  bool testFlag( Flag flag ) const;
88 
91  static QgsRenderContext fromMapSettings( const QgsMapSettings& mapSettings );
92 
99  static QgsRenderContext fromQPainter( QPainter* painter );
100 
101  //getters
102 
107  QPainter* painter() {return mPainter;}
108 
112  QgsCoordinateTransform coordinateTransform() const {return mCoordTransform;}
113 
114  const QgsRectangle& extent() const {return mExtent;}
115 
116  const QgsMapToPixel& mapToPixel() const {return mMapToPixel;}
117 
124  double scaleFactor() const {return mScaleFactor;}
125 
126  bool renderingStopped() const {return mRenderingStopped;}
127 
128  bool forceVectorOutput() const;
129 
132  bool useAdvancedEffects() const;
133 
136  void setUseAdvancedEffects( bool enabled );
137 
138  bool drawEditingInformation() const;
139 
145  double rendererScale() const {return mRendererScale;}
146 
149  QgsLabelingEngine* labelingEngine() const { return mLabelingEngine; }
150 
151  QColor selectionColor() const { return mSelectionColor; }
152 
159  bool showSelection() const;
160 
161  //setters
162 
164  void setCoordinateTransform( const QgsCoordinateTransform& t );
165  void setMapToPixel( const QgsMapToPixel& mtp ) {mMapToPixel = mtp;}
166  void setExtent( const QgsRectangle& extent ) {mExtent = extent;}
167 
168  void setDrawEditingInformation( bool b );
169 
170  void setRenderingStopped( bool stopped ) {mRenderingStopped = stopped;}
171 
178  void setScaleFactor( double factor ) {mScaleFactor = factor;}
179 
185  void setRendererScale( double scale ) {mRendererScale = scale;}
186 
193  void setPainter( QPainter* p ) {mPainter = p;}
194 
195  void setForceVectorOutput( bool force );
196 
199  void setLabelingEngine( QgsLabelingEngine* engine2 ) { mLabelingEngine = engine2; }
200  void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
201 
208  void setShowSelection( const bool showSelection );
209 
212  bool useRenderingOptimization() const;
213 
214  void setUseRenderingOptimization( bool enabled );
215 
217  const QgsVectorSimplifyMethod& vectorSimplifyMethod() const { return mVectorSimplifyMethod; }
218  void setVectorSimplifyMethod( const QgsVectorSimplifyMethod& simplifyMethod ) { mVectorSimplifyMethod = simplifyMethod; }
219 
225  void setExpressionContext( const QgsExpressionContext& context ) { mExpressionContext = context; }
226 
232  QgsExpressionContext& expressionContext() { return mExpressionContext; }
233 
240  const QgsExpressionContext& expressionContext() const { return mExpressionContext; }
241 
243  const QgsAbstractGeometry* geometry() const { return mGeometry; }
245  void setGeometry( const QgsAbstractGeometry* geometry ) { mGeometry = geometry; }
246 
252  void setFeatureFilterProvider( const QgsFeatureFilterProvider* ffp );
253 
259  const QgsFeatureFilterProvider* featureFilterProvider() const;
260 
263  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
265  double segmentationTolerance() const { return mSegmentationTolerance; }
266 
269  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
271  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
272 
273  private:
274 
275  Flags mFlags;
276 
278  QPainter* mPainter = nullptr;
279 
281  QgsCoordinateTransform mCoordTransform;
282 
283  QgsRectangle mExtent;
284 
285  QgsMapToPixel mMapToPixel;
286 
288  bool mRenderingStopped = false;
289 
291  double mScaleFactor = 1.0;
292 
294  double mRendererScale = 1.0;
295 
297  QgsLabelingEngine* mLabelingEngine = nullptr;
298 
300  QColor mSelectionColor;
301 
303  QgsVectorSimplifyMethod mVectorSimplifyMethod;
304 
306  QgsExpressionContext mExpressionContext;
307 
309  const QgsAbstractGeometry* mGeometry = nullptr;
310 
312  QScopedPointer< QgsFeatureFilterProvider > mFeatureFilterProvider;
313 
314  double mSegmentationTolerance = M_PI_2 / 90;
315 
317 };
318 
319 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )
320 
321 #endif
void setRenderingStopped(bool stopped)
A rectangle specified with double values.
Definition: qgsrectangle.h:36
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.
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)
#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:34
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
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.
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
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).
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.