QGIS API Documentation  2.99.0-Master (6c64c5a)
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"
36 #include "qgspathresolver.h"
37 
38 class QPainter;
40 class QgsLabelingEngine;
41 class QgsMapSettings;
42 
43 
51 class CORE_EXPORT QgsRenderContext
52 {
53  public:
55 
57  QgsRenderContext &operator=( const QgsRenderContext &rh );
58 
63  enum Flag
64  {
65  DrawEditingInfo = 0x01,
66  ForceVectorOutput = 0x02,
67  UseAdvancedEffects = 0x04,
68  UseRenderingOptimization = 0x08,
69  DrawSelection = 0x10,
70  DrawSymbolBounds = 0x20,
71  RenderMapTile = 0x40,
72  Antialiasing = 0x80,
73  RenderPartialOutput = 0x100,
74  RenderPreviewJob = 0x200,
75  };
76  Q_DECLARE_FLAGS( Flags, Flag )
77 
78 
82  void setFlags( QgsRenderContext::Flags flags );
83 
88  void setFlag( Flag flag, bool on = true );
89 
94  Flags flags() const;
95 
100  bool testFlag( Flag flag ) const;
101 
106  static QgsRenderContext fromMapSettings( const QgsMapSettings &mapSettings );
107 
114  static QgsRenderContext fromQPainter( QPainter *painter );
115 
116  //getters
117 
122  QPainter *painter() {return mPainter;}
123 
128  QgsCoordinateTransform coordinateTransform() const {return mCoordTransform;}
129 
134  const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
135 
144  QgsCoordinateTransformContext transformContext() const;
145 
154  void setTransformContext( const QgsCoordinateTransformContext &context );
155 
163  const QgsPathResolver &pathResolver() const { return mPathResolver; }
164 
172  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
173 
174  const QgsRectangle &extent() const {return mExtent;}
175 
176  const QgsMapToPixel &mapToPixel() const {return mMapToPixel;}
177 
184  double scaleFactor() const {return mScaleFactor;}
185 
186  bool renderingStopped() const {return mRenderingStopped;}
187 
188  bool forceVectorOutput() const;
189 
193  bool useAdvancedEffects() const;
194 
198  void setUseAdvancedEffects( bool enabled );
199 
200  bool drawEditingInformation() const;
201 
207  double rendererScale() const {return mRendererScale;}
208 
213  QgsLabelingEngine *labelingEngine() const { return mLabelingEngine; } SIP_SKIP
214 
215  QColor selectionColor() const { return mSelectionColor; }
216 
224  bool showSelection() const;
225 
226  //setters
227 
229  void setCoordinateTransform( const QgsCoordinateTransform &t );
230  void setMapToPixel( const QgsMapToPixel &mtp ) {mMapToPixel = mtp;}
231  void setExtent( const QgsRectangle &extent ) {mExtent = extent;}
232 
233  void setDrawEditingInformation( bool b );
234 
235  void setRenderingStopped( bool stopped ) {mRenderingStopped = stopped;}
236 
242  void setDistanceArea( const QgsDistanceArea &distanceArea ) {mDistanceArea = distanceArea ;}
243 
250  void setScaleFactor( double factor ) {mScaleFactor = factor;}
251 
257  void setRendererScale( double scale ) {mRendererScale = scale;}
258 
265  void setPainter( QPainter *p ) {mPainter = p;}
266 
267  void setForceVectorOutput( bool force );
268 
273  void setLabelingEngine( QgsLabelingEngine *engine2 ) { mLabelingEngine = engine2; } SIP_SKIP
274  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
275 
283  void setShowSelection( const bool showSelection );
284 
288  bool useRenderingOptimization() const;
289 
290  void setUseRenderingOptimization( bool enabled );
291 
293  const QgsVectorSimplifyMethod &vectorSimplifyMethod() const { return mVectorSimplifyMethod; }
294  void setVectorSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mVectorSimplifyMethod = simplifyMethod; }
295 
302  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
303 
310  QgsExpressionContext &expressionContext() { return mExpressionContext; }
311 
319  const QgsExpressionContext &expressionContext() const { return mExpressionContext; } SIP_SKIP
320 
322  const QgsAbstractGeometry *geometry() const { return mGeometry; }
324  void setGeometry( const QgsAbstractGeometry *geometry ) { mGeometry = geometry; }
325 
332  void setFeatureFilterProvider( const QgsFeatureFilterProvider *ffp );
333 
340  const QgsFeatureFilterProvider *featureFilterProvider() const;
341 
345  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
347  double segmentationTolerance() const { return mSegmentationTolerance; }
348 
352  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
354  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
355 
356  // Conversions
357 
364  double convertToPainterUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
365 
372  double convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
373 
379  double convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const;
380 
387  double convertMetersToMapUnits( double meters ) const;
388 
389  private:
390 
391  Flags mFlags;
392 
394  QPainter *mPainter = nullptr;
395 
397  QgsCoordinateTransform mCoordTransform;
398 
404  QgsDistanceArea mDistanceArea;
405 
406  QgsRectangle mExtent;
407 
408  QgsMapToPixel mMapToPixel;
409 
411  bool mRenderingStopped = false;
412 
414  double mScaleFactor = 1.0;
415 
417  double mRendererScale = 1.0;
418 
420  QgsLabelingEngine *mLabelingEngine = nullptr;
421 
423  QColor mSelectionColor;
424 
426  QgsVectorSimplifyMethod mVectorSimplifyMethod;
427 
429  QgsExpressionContext mExpressionContext;
430 
432  const QgsAbstractGeometry *mGeometry = nullptr;
433 
435  std::unique_ptr< QgsFeatureFilterProvider > mFeatureFilterProvider;
436 
437  double mSegmentationTolerance = M_PI_2 / 90;
438 
440 
441  QgsCoordinateTransformContext mTransformContext;
442 
443  QgsPathResolver mPathResolver;
444 
445 #ifdef QGISDEBUG
446  bool mHasTransformContext = false;
447 #endif
448 };
449 
450 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )
451 
452 #endif
void setRenderingStopped(bool stopped)
A rectangle specified with double values.
Definition: qgsrectangle.h:39
double rendererScale() const
Returns the renderer map scale.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
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.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
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)
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
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.
Contains information about the context in which a coordinate transform is executed.
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.
void setDistanceArea(const QgsDistanceArea &distanceArea)
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
Resolves relative paths into absolute paths and vice versa.
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:100
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.