QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  , mCoordTransform( nullptr )
30  , mRenderingStopped( false )
31  , mScaleFactor( 1.0 )
32  , mRasterScaleFactor( 1.0 )
33  , mRendererScale( 1.0 )
34  , mLabelingEngine( nullptr )
35  , mLabelingEngine2( nullptr )
36  , mGeometry( nullptr )
37  , mFeatureFilterProvider( nullptr )
38  , mSegmentationTolerance( M_PI_2 / 90 )
39  , mSegmentationToleranceType( QgsAbstractGeometryV2::MaximumAngle )
40 {
42 }
43 
45  : mFlags( rh.mFlags )
46  , mPainter( rh.mPainter )
47  , mCoordTransform( rh.mCoordTransform )
48  , mExtent( rh.mExtent )
49  , mMapToPixel( rh.mMapToPixel )
50  , mRenderingStopped( rh.mRenderingStopped )
51  , mScaleFactor( rh.mScaleFactor )
52  , mRasterScaleFactor( rh.mRasterScaleFactor )
53  , mRendererScale( rh.mRendererScale )
54  , mLabelingEngine( rh.mLabelingEngine )
55  , mLabelingEngine2( rh.mLabelingEngine2 )
56  , mSelectionColor( rh.mSelectionColor )
57  , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
58  , mExpressionContext( rh.mExpressionContext )
59  , mGeometry( rh.mGeometry )
60  , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
61  , mSegmentationTolerance( rh.mSegmentationTolerance )
62  , mSegmentationToleranceType( rh.mSegmentationToleranceType )
63 {
64 }
65 
67 {
68  mFlags = rh.mFlags;
69  mPainter = rh.mPainter;
70  mCoordTransform = rh.mCoordTransform;
71  mExtent = rh.mExtent;
72  mMapToPixel = rh.mMapToPixel;
73  mRenderingStopped = rh.mRenderingStopped;
74  mScaleFactor = rh.mScaleFactor;
75  mRasterScaleFactor = rh.mRasterScaleFactor;
76  mRendererScale = rh.mRendererScale;
77  mLabelingEngine = rh.mLabelingEngine;
78  mLabelingEngine2 = rh.mLabelingEngine2;
79  mSelectionColor = rh.mSelectionColor;
80  mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
81  mExpressionContext = rh.mExpressionContext;
82  mGeometry = rh.mGeometry;
83  mFeatureFilterProvider = rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr;
84  mSegmentationTolerance = rh.mSegmentationTolerance;
85  mSegmentationToleranceType = rh.mSegmentationToleranceType;
86  return *this;
87 }
88 
90 {
91  delete mFeatureFilterProvider;
92  mFeatureFilterProvider = nullptr;
93 }
94 
95 void QgsRenderContext::setFlags( const QgsRenderContext::Flags& flags )
96 {
97  mFlags = flags;
98 }
99 
101 {
102  if ( on )
103  mFlags |= flag;
104  else
105  mFlags &= ~flag;
106 }
107 
108 QgsRenderContext::Flags QgsRenderContext::flags() const
109 {
110  return mFlags;
111 }
112 
114 {
115  return mFlags.testFlag( flag );
116 }
117 
119 {
120  QgsRenderContext ctx;
121  ctx.setMapToPixel( mapSettings.mapToPixel() );
122  ctx.setExtent( mapSettings.visibleExtent() );
127  ctx.setCoordinateTransform( nullptr );
128  ctx.setSelectionColor( mapSettings.selectionColor() );
134  ctx.setRasterScaleFactor( 1.0 );
135  ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
136  ctx.setRendererScale( mapSettings.scale() );
137  ctx.setExpressionContext( mapSettings.expressionContext() );
138  ctx.setSegmentationTolerance( mapSettings.segmentationTolerance() );
140 
141  //this flag is only for stopping during the current rendering progress,
142  //so must be false at every new render operation
143  ctx.setRenderingStopped( false );
144 
145  return ctx;
146 }
147 
149 {
150  return mFlags.testFlag( ForceVectorOutput );
151 }
152 
154 {
155  return mFlags.testFlag( UseAdvancedEffects );
156 }
157 
159 {
160  setFlag( UseAdvancedEffects, enabled );
161 }
162 
164 {
165  return mFlags.testFlag( DrawEditingInfo );
166 }
167 
169 {
170  return mFlags.testFlag( DrawSelection );
171 }
172 
174 {
175  mCoordTransform = t;
176 }
177 
179 {
180  setFlag( DrawEditingInfo, b );
181 }
182 
184 {
185  setFlag( ForceVectorOutput, force );
186 }
187 
189 {
190  setFlag( DrawSelection, showSelection );
191 }
192 
194 {
195  return mFlags.testFlag( UseRenderingOptimization );
196 }
197 
199 {
200  setFlag( UseRenderingOptimization, enabled );
201 }
202 
204 {
205  delete mFeatureFilterProvider;
206  mFeatureFilterProvider = nullptr;
207 
208  if ( ffp )
209  {
210  mFeatureFilterProvider = ffp->clone();
211  }
212 }
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.
Use antialiasing while drawing.
void setRendererScale(double scale)
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
Abstract base class for all geometries.
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 setSimplifyHints(const SimplifyHints &simplifyHints)
Sets the simplification hints of the vector layer managed.
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 setCoordinateTransform(const QgsCoordinateTransform *t)
Sets coordinate transformation.
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.
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.
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...
QgsAbstractGeometryV2::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
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. ...
void setFlags(const QgsRenderContext::Flags &flags)
Set combination of flags that will be used for rendering.
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 setSegmentationToleranceType(QgsAbstractGeometryV2::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.