QGIS API Documentation  2.99.0-Master (6a61179)
qgsrendercontext.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendercontext.cpp
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 
19 #include "qgsrendercontext.h"
20 
21 #include "qgsmapsettings.h"
22 #include "qgsexpression.h"
23 #include "qgsvectorlayer.h"
25 
27  : mFlags( DrawEditingInfo | UseAdvancedEffects | DrawSelection | UseRenderingOptimization )
28  , mPainter( nullptr )
29  , mRenderingStopped( false )
30  , mScaleFactor( 1.0 )
31  , mRasterScaleFactor( 1.0 )
32  , mRendererScale( 1.0 )
33  , mLabelingEngine( nullptr )
34  , mLabelingEngine2( nullptr )
35  , mGeometry( nullptr )
36  , mFeatureFilterProvider( nullptr )
37  , mSegmentationTolerance( M_PI_2 / 90 )
38  , mSegmentationToleranceType( QgsAbstractGeometry::MaximumAngle )
39 {
41 }
42 
44  : mFlags( rh.mFlags )
45  , mPainter( rh.mPainter )
46  , mCoordTransform( rh.mCoordTransform )
47  , mExtent( rh.mExtent )
48  , mMapToPixel( rh.mMapToPixel )
49  , mRenderingStopped( rh.mRenderingStopped )
50  , mScaleFactor( rh.mScaleFactor )
51  , mRasterScaleFactor( rh.mRasterScaleFactor )
52  , mRendererScale( rh.mRendererScale )
53  , mLabelingEngine( rh.mLabelingEngine )
54  , mLabelingEngine2( rh.mLabelingEngine2 )
55  , mSelectionColor( rh.mSelectionColor )
56  , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
57  , mExpressionContext( rh.mExpressionContext )
58  , mGeometry( rh.mGeometry )
59  , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
60  , mSegmentationTolerance( rh.mSegmentationTolerance )
61  , mSegmentationToleranceType( rh.mSegmentationToleranceType )
62 {
63 }
64 
66 {
67  mFlags = rh.mFlags;
68  mPainter = rh.mPainter;
69  mCoordTransform = rh.mCoordTransform;
70  mExtent = rh.mExtent;
71  mMapToPixel = rh.mMapToPixel;
72  mRenderingStopped = rh.mRenderingStopped;
73  mScaleFactor = rh.mScaleFactor;
74  mRasterScaleFactor = rh.mRasterScaleFactor;
75  mRendererScale = rh.mRendererScale;
76  mLabelingEngine = rh.mLabelingEngine;
77  mLabelingEngine2 = rh.mLabelingEngine2;
78  mSelectionColor = rh.mSelectionColor;
79  mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
80  mExpressionContext = rh.mExpressionContext;
81  mGeometry = rh.mGeometry;
82  mFeatureFilterProvider = rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr;
83  mSegmentationTolerance = rh.mSegmentationTolerance;
84  mSegmentationToleranceType = rh.mSegmentationToleranceType;
85  return *this;
86 }
87 
89 {
90  delete mFeatureFilterProvider;
91  mFeatureFilterProvider = nullptr;
92 }
93 
94 void QgsRenderContext::setFlags( QgsRenderContext::Flags flags )
95 {
96  mFlags = flags;
97 }
98 
100 {
101  if ( on )
102  mFlags |= flag;
103  else
104  mFlags &= ~flag;
105 }
106 
107 QgsRenderContext::Flags QgsRenderContext::flags() const
108 {
109  return mFlags;
110 }
111 
113 {
114  return mFlags.testFlag( flag );
115 }
116 
118 {
119  QgsRenderContext ctx;
120  ctx.setMapToPixel( mapSettings.mapToPixel() );
121  ctx.setExtent( mapSettings.visibleExtent() );
127  ctx.setSelectionColor( mapSettings.selectionColor() );
133  ctx.setRasterScaleFactor( 1.0 );
134  ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
135  ctx.setRendererScale( mapSettings.scale() );
136  ctx.setExpressionContext( mapSettings.expressionContext() );
137  ctx.setSegmentationTolerance( mapSettings.segmentationTolerance() );
139 
140  //this flag is only for stopping during the current rendering progress,
141  //so must be false at every new render operation
142  ctx.setRenderingStopped( false );
143 
144  return ctx;
145 }
146 
148 {
149  return mFlags.testFlag( ForceVectorOutput );
150 }
151 
153 {
154  return mFlags.testFlag( UseAdvancedEffects );
155 }
156 
158 {
159  setFlag( UseAdvancedEffects, enabled );
160 }
161 
163 {
164  return mFlags.testFlag( DrawEditingInfo );
165 }
166 
168 {
169  return mFlags.testFlag( DrawSelection );
170 }
171 
173 {
174  mCoordTransform = t;
175 }
176 
178 {
179  setFlag( DrawEditingInfo, b );
180 }
181 
183 {
184  setFlag( ForceVectorOutput, force );
185 }
186 
188 {
189  setFlag( DrawSelection, showSelection );
190 }
191 
193 {
194  return mFlags.testFlag( UseRenderingOptimization );
195 }
196 
198 {
199  setFlag( UseRenderingOptimization, enabled );
200 }
201 
203 {
204  delete mFeatureFilterProvider;
205  mFeatureFilterProvider = nullptr;
206 
207  if ( ffp )
208  {
209  mFeatureFilterProvider = ffp->clone();
210  }
211 }
void setForceVectorOutput(bool force)
Enable layer transparency and blending effects.
void setRenderingStopped(bool stopped)
Enable vector simplification and other rendering optimizations.
virtual QgsFeatureFilterProvider * clone() const =0
Create a clone of the feature filter provider.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
void setFlags(QgsRenderContext::Flags flags)
Set combination of flags that will be used for rendering.
Use antialiasing while drawing.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets coordinate transformation.
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
void setRendererScale(double scale)
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
Flags flags() const
Return combination of flags used for rendering.
Enable layer transparency and blending effects.
Whether vector selections should be shown in the rendered map.
void setExtent(const QgsRectangle &extent)
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
#define M_PI_2
Definition: util.cpp:45
Vector graphics should not be cached and drawn as raster images.
The QgsMapSettings class contains configuration for rendering of the map.
void setSelectionColor(const QColor &color)
No simplification can be applied.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
void setScaleFactor(double factor)
QgsRenderContext & operator=(const QgsRenderContext &rh)
Whether vector selections should be shown in the rendered map.
double scale() const
Return the calculated scale of the map.
void setDrawEditingInformation(bool b)
Enable anti-aliasing for map rendering.
bool drawEditingInformation() const
Draw bounds of symbols (for debugging/testing)
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.
const QgsMapToPixel & mapToPixel() const
Draw bounds of symbols (for debugging/testing)
Vector graphics should not be cached and drawn as raster images.
Enable drawing of vertex markers for layers in editing mode.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
bool forceVectorOutput() const
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
bool useRenderingOptimization() const
Returns true if the rendering optimization (geometry simplification) can be executed.
Draw map such that there are no problems between adjacent tiles.
double outputDpi() const
Return DPI used for conversion between real world units (e.g.
Contains information about the context of a rendering operation.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
void setMapToPixel(const QgsMapToPixel &mtp)
Class for doing transforms between two map coordinate systems.
void setUseRenderingOptimization(bool enabled)
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setFeatureFilterProvider(const QgsFeatureFilterProvider *ffp)
Set a filter feature provider used for additional filtering of rendered features. ...
Enable vector simplification and other rendering optimizations.
void setRasterScaleFactor(double factor)
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QColor selectionColor() const
Get color that is used for drawing of selected vector features.
void setShowSelection(const bool showSelection)
Sets whether vector selections should be shown in the rendered map.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
Draw map such that there are no problems between adjacent tiles.
Flag
Enumeration of flags that affect rendering operations.
Enable drawing of vertex markers for layers in editing mode.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.