QGIS API Documentation  2.13.0-Master
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 {
40 }
41 
43  : mFlags( rh.mFlags )
44  , mPainter( rh.mPainter )
45  , mCoordTransform( rh.mCoordTransform )
46  , mExtent( rh.mExtent )
47  , mMapToPixel( rh.mMapToPixel )
48  , mRenderingStopped( rh.mRenderingStopped )
49  , mScaleFactor( rh.mScaleFactor )
50  , mRasterScaleFactor( rh.mRasterScaleFactor )
51  , mRendererScale( rh.mRendererScale )
52  , mLabelingEngine( rh.mLabelingEngine )
53  , mLabelingEngine2( rh.mLabelingEngine2 )
54  , mSelectionColor( rh.mSelectionColor )
55  , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
56  , mExpressionContext( rh.mExpressionContext )
57  , mGeometry( rh.mGeometry )
58  , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
59 {
60 }
61 
63 {
64  mFlags = rh.mFlags;
65  mPainter = rh.mPainter;
66  mCoordTransform = rh.mCoordTransform;
67  mExtent = rh.mExtent;
68  mMapToPixel = rh.mMapToPixel;
69  mRenderingStopped = rh.mRenderingStopped;
70  mScaleFactor = rh.mScaleFactor;
71  mRasterScaleFactor = rh.mRasterScaleFactor;
72  mRendererScale = rh.mRendererScale;
73  mLabelingEngine = rh.mLabelingEngine;
74  mLabelingEngine2 = rh.mLabelingEngine2;
75  mSelectionColor = rh.mSelectionColor;
76  mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
77  mExpressionContext = rh.mExpressionContext;
78  mGeometry = rh.mGeometry;
79  mFeatureFilterProvider = rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr;
80  return *this;
81 }
82 
84 {
85  delete mFeatureFilterProvider;
86  mFeatureFilterProvider = nullptr;
87 }
88 
89 void QgsRenderContext::setFlags( const QgsRenderContext::Flags& flags )
90 {
91  mFlags = flags;
92 }
93 
95 {
96  if ( on )
97  mFlags |= flag;
98  else
99  mFlags &= ~flag;
100 }
101 
102 QgsRenderContext::Flags QgsRenderContext::flags() const
103 {
104  return mFlags;
105 }
106 
108 {
109  return mFlags.testFlag( flag );
110 }
111 
113 {
114  QgsRenderContext ctx;
115  ctx.setMapToPixel( mapSettings.mapToPixel() );
116  ctx.setExtent( mapSettings.visibleExtent() );
121  ctx.setCoordinateTransform( nullptr );
122  ctx.setSelectionColor( mapSettings.selectionColor() );
126  ctx.setRasterScaleFactor( 1.0 );
127  ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
128  ctx.setRendererScale( mapSettings.scale() );
129  ctx.setExpressionContext( mapSettings.expressionContext() );
130 
131  //this flag is only for stopping during the current rendering progress,
132  //so must be false at every new render operation
133  ctx.setRenderingStopped( false );
134 
135  return ctx;
136 }
137 
139 {
140  return mFlags.testFlag( ForceVectorOutput );
141 }
142 
144 {
145  return mFlags.testFlag( UseAdvancedEffects );
146 }
147 
149 {
150  setFlag( UseAdvancedEffects, enabled );
151 }
152 
154 {
155  return mFlags.testFlag( DrawEditingInfo );
156 }
157 
159 {
160  return mFlags.testFlag( DrawSelection );
161 }
162 
164 {
165  mCoordTransform = t;
166 }
167 
169 {
170  setFlag( DrawEditingInfo, b );
171 }
172 
174 {
175  setFlag( ForceVectorOutput, force );
176 }
177 
179 {
180  setFlag( DrawSelection, showSelection );
181 }
182 
184 {
185  return mFlags.testFlag( UseRenderingOptimization );
186 }
187 
189 {
190  setFlag( UseRenderingOptimization, enabled );
191 }
192 
194 {
195  delete mFeatureFilterProvider;
196  mFeatureFilterProvider = nullptr;
197 
198  if ( ffp )
199  {
200  mFeatureFilterProvider = ffp->clone();
201  }
202 }
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...
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)
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)
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)
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.
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 setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
const QgsExpressionContext & expressionContext() const
Gets the expression context.