QGIS API Documentation  2.14.11-Essen
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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() );
127  ctx.setRasterScaleFactor( 1.0 );
128  ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
129  ctx.setRendererScale( mapSettings.scale() );
130  ctx.setExpressionContext( mapSettings.expressionContext() );
131 
132  //this flag is only for stopping during the current rendering progress,
133  //so must be false at every new render operation
134  ctx.setRenderingStopped( false );
135 
136  return ctx;
137 }
138 
140 {
141  return mFlags.testFlag( ForceVectorOutput );
142 }
143 
145 {
146  return mFlags.testFlag( UseAdvancedEffects );
147 }
148 
150 {
151  setFlag( UseAdvancedEffects, enabled );
152 }
153 
155 {
156  return mFlags.testFlag( DrawEditingInfo );
157 }
158 
160 {
161  return mFlags.testFlag( DrawSelection );
162 }
163 
165 {
166  mCoordTransform = t;
167 }
168 
170 {
171  setFlag( DrawEditingInfo, b );
172 }
173 
175 {
176  setFlag( ForceVectorOutput, force );
177 }
178 
179 void QgsRenderContext::setShowSelection( const bool showSelection )
180 {
181  setFlag( DrawSelection, showSelection );
182 }
183 
185 {
186  return mFlags.testFlag( UseRenderingOptimization );
187 }
188 
190 {
191  setFlag( UseRenderingOptimization, enabled );
192 }
193 
195 {
196  delete mFeatureFilterProvider;
197  mFeatureFilterProvider = nullptr;
198 
199  if ( ffp )
200  {
201  mFeatureFilterProvider = ffp->clone();
202  }
203 }
void setForceVectorOutput(bool force)
void setRenderingStopped(bool stopped)
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
Use antialiasing while drawing.
Enable vector simplification and other rendering optimizations.
Enable layer transparency and blending effects.
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.
Draw bounds of symbols (for debugging/testing)
void setDrawEditingInformation(bool b)
Enable anti-aliasing for map rendering.
bool forceVectorOutput() const
Whether vector selections should be shown in the rendered map.
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)
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.
Flag
Enumeration of flags that affect rendering operations.
Enable layer transparency and blending effects.
Contains information about the context of a rendering operation.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
Enable drawing of vertex markers for layers in editing mode.
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.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Vector graphics should not be cached and drawn as raster images.
const QgsExpressionContext & expressionContext() const
Gets the expression context.