QGIS API Documentation  2.99.0-Master (b698612)
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 
35 class QPainter;
37 class QgsLabelingEngine;
38 class QgsMapSettings;
39 
40 
47 class CORE_EXPORT QgsRenderContext
48 {
49  public:
51 
53  QgsRenderContext &operator=( const QgsRenderContext &rh );
54 
58  enum Flag
59  {
60  DrawEditingInfo = 0x01,
61  ForceVectorOutput = 0x02,
62  UseAdvancedEffects = 0x04,
63  UseRenderingOptimization = 0x08,
64  DrawSelection = 0x10,
65  DrawSymbolBounds = 0x20,
66  RenderMapTile = 0x40,
67  Antialiasing = 0x80,
68  RenderPartialOutput = 0x100,
69  };
70  Q_DECLARE_FLAGS( Flags, Flag )
71 
72 
75  void setFlags( QgsRenderContext::Flags flags );
76 
80  void setFlag( Flag flag, bool on = true );
81 
85  Flags flags() const;
86 
90  bool testFlag( Flag flag ) const;
91 
94  static QgsRenderContext fromMapSettings( const QgsMapSettings &mapSettings );
95 
102  static QgsRenderContext fromQPainter( QPainter *painter );
103 
104  //getters
105 
110  QPainter *painter() {return mPainter;}
111 
115  QgsCoordinateTransform coordinateTransform() const {return mCoordTransform;}
116 
117  const QgsRectangle &extent() const {return mExtent;}
118 
119  const QgsMapToPixel &mapToPixel() const {return mMapToPixel;}
120 
127  double scaleFactor() const {return mScaleFactor;}
128 
129  bool renderingStopped() const {return mRenderingStopped;}
130 
131  bool forceVectorOutput() const;
132 
135  bool useAdvancedEffects() const;
136 
139  void setUseAdvancedEffects( bool enabled );
140 
141  bool drawEditingInformation() const;
142 
148  double rendererScale() const {return mRendererScale;}
149 
152  QgsLabelingEngine *labelingEngine() const { return mLabelingEngine; } SIP_SKIP
153 
154  QColor selectionColor() const { return mSelectionColor; }
155 
162  bool showSelection() const;
163 
164  //setters
165 
167  void setCoordinateTransform( const QgsCoordinateTransform &t );
168  void setMapToPixel( const QgsMapToPixel &mtp ) {mMapToPixel = mtp;}
169  void setExtent( const QgsRectangle &extent ) {mExtent = extent;}
170 
171  void setDrawEditingInformation( bool b );
172 
173  void setRenderingStopped( bool stopped ) {mRenderingStopped = stopped;}
174 
181  void setScaleFactor( double factor ) {mScaleFactor = factor;}
182 
188  void setRendererScale( double scale ) {mRendererScale = scale;}
189 
196  void setPainter( QPainter *p ) {mPainter = p;}
197 
198  void setForceVectorOutput( bool force );
199 
202  void setLabelingEngine( QgsLabelingEngine *engine2 ) { mLabelingEngine = engine2; } SIP_SKIP
203  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
204 
211  void setShowSelection( const bool showSelection );
212 
215  bool useRenderingOptimization() const;
216 
217  void setUseRenderingOptimization( bool enabled );
218 
220  const QgsVectorSimplifyMethod &vectorSimplifyMethod() const { return mVectorSimplifyMethod; }
221  void setVectorSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mVectorSimplifyMethod = simplifyMethod; }
222 
228  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
229 
235  QgsExpressionContext &expressionContext() { return mExpressionContext; }
236 
243  const QgsExpressionContext &expressionContext() const { return mExpressionContext; } SIP_SKIP
244 
246  const QgsAbstractGeometry *geometry() const { return mGeometry; }
248  void setGeometry( const QgsAbstractGeometry *geometry ) { mGeometry = geometry; }
249 
255  void setFeatureFilterProvider( const QgsFeatureFilterProvider *ffp );
256 
262  const QgsFeatureFilterProvider *featureFilterProvider() const;
263 
266  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
268  double segmentationTolerance() const { return mSegmentationTolerance; }
269 
272  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
274  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
275 
276  // Conversions
277 
284  double convertToPainterUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
285 
292  double convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
293 
299  double convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const;
300 
301  private:
302 
303  Flags mFlags;
304 
306  QPainter *mPainter = nullptr;
307 
309  QgsCoordinateTransform mCoordTransform;
310 
311  QgsRectangle mExtent;
312 
313  QgsMapToPixel mMapToPixel;
314 
316  bool mRenderingStopped = false;
317 
319  double mScaleFactor = 1.0;
320 
322  double mRendererScale = 1.0;
323 
325  QgsLabelingEngine *mLabelingEngine = nullptr;
326 
328  QColor mSelectionColor;
329 
331  QgsVectorSimplifyMethod mVectorSimplifyMethod;
332 
334  QgsExpressionContext mExpressionContext;
335 
337  const QgsAbstractGeometry *mGeometry = nullptr;
338 
340  std::unique_ptr< QgsFeatureFilterProvider > mFeatureFilterProvider;
341 
342  double mSegmentationTolerance = M_PI_2 / 90;
343 
345 };
346 
347 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )
348 
349 #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)
#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:107
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
Struct for storing maximum and minimum scales for measurements in map units.
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.