QGIS API Documentation  2.15.0-Master (af20121)
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() );
132  ctx.setRasterScaleFactor( 1.0 );
133  ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
134  ctx.setRendererScale( mapSettings.scale() );
135  ctx.setExpressionContext( mapSettings.expressionContext() );
136  ctx.setSegmentationTolerance( mapSettings.segmentationTolerance() );
138 
139  //this flag is only for stopping during the current rendering progress,
140  //so must be false at every new render operation
141  ctx.setRenderingStopped( false );
142 
143  return ctx;
144 }
145 
147 {
148  return mFlags.testFlag( ForceVectorOutput );
149 }
150 
152 {
153  return mFlags.testFlag( UseAdvancedEffects );
154 }
155 
157 {
158  setFlag( UseAdvancedEffects, enabled );
159 }
160 
162 {
163  return mFlags.testFlag( DrawEditingInfo );
164 }
165 
167 {
168  return mFlags.testFlag( DrawSelection );
169 }
170 
172 {
173  mCoordTransform = t;
174 }
175 
177 {
178  setFlag( DrawEditingInfo, b );
179 }
180 
182 {
183  setFlag( ForceVectorOutput, force );
184 }
185 
187 {
188  setFlag( DrawSelection, showSelection );
189 }
190 
192 {
193  return mFlags.testFlag( UseRenderingOptimization );
194 }
195 
197 {
198  setFlag( UseRenderingOptimization, enabled );
199 }
200 
202 {
203  delete mFeatureFilterProvider;
204  mFeatureFilterProvider = nullptr;
205 
206  if ( ffp )
207  {
208  mFeatureFilterProvider = ffp->clone();
209  }
210 }
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.
double scale() const
Return the calculated scale of the map.
QColor selectionColor() const
Get color that is used for drawing of selected vector features.
void setRendererScale(double scale)
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
Abstract base class for all geometries.
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
const QgsMapToPixel & mapToPixel() const
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)
#define M_PI_2
Definition: util.cpp:43
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.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
void setSelectionColor(const QColor &color)
No simplification can be applied.
int outputDpi() const
Return DPI used for conversion between real world units (e.g.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
void setScaleFactor(double factor)
QgsRenderContext & operator=(const QgsRenderContext &rh)
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
Whether vector selections should be shown in the rendered map.
void setDrawEditingInformation(bool b)
bool forceVectorOutput() const
Draw bounds of symbols (for debugging/testing)
Abstract interface for use by classes that filter the features of a layer.
bool useRenderingOptimization() const
Returns true if the rendering optimization (geometry simplification) can be executed.
Draw bounds of symbols (for debugging/testing)
QgsAbstractGeometryV2::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Vector graphics should not be cached and drawn as raster images.
bool drawEditingInformation() const
Enable drawing of vertex markers for layers in editing mode.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
Draw map such that there are no problems between adjacent tiles.
Contains information about the context of a rendering operation.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
void setMapToPixel(const QgsMapToPixel &mtp)
Flags flags() const
Return combination of flags used for rendering.
Class for doing transforms between two map coordinate systems.
void setUseRenderingOptimization(bool enabled)
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
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)
void setShowSelection(const bool showSelection)
Sets whether vector selections should be shown in the rendered map.
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.
const QgsExpressionContext & expressionContext() const
Gets the expression context.