Skip to content

Commit 57669e7

Browse files
committed
Make QgsRenderContext available to more renderer methods
1 parent 86ace24 commit 57669e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+380
-202
lines changed

python/core/symbology-ng/qgscategorizedsymbolrendererv2.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2
4545

4646
virtual ~QgsCategorizedSymbolRendererV2();
4747

48-
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
48+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
4949

50-
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
50+
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
5151

5252
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
5353

@@ -64,7 +64,7 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2
6464
//! returns bitwise OR-ed capabilities of the renderer
6565
virtual int capabilities();
6666

67-
virtual QgsSymbolV2List symbols();
67+
virtual QgsSymbolV2List symbols( QgsRenderContext& context );
6868
void updateSymbols( QgsSymbolV2 * sym );
6969

7070
const QgsCategoryList& categories() const;

python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
8787

8888
virtual ~QgsGraduatedSymbolRendererV2();
8989

90-
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
90+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
9191

92-
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
92+
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
9393

9494
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
9595

@@ -106,7 +106,7 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
106106
//! returns bitwise OR-ed capabilities of the renderer
107107
virtual int capabilities();
108108

109-
virtual QgsSymbolV2List symbols();
109+
virtual QgsSymbolV2List symbols( QgsRenderContext& context );
110110

111111
QString classAttribute() const;
112112
void setClassAttribute( QString attr );

python/core/symbology-ng/qgsheatmaprenderer.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class QgsHeatmapRenderer : QgsFeatureRendererV2
1313
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
1414
virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
1515
virtual void stopRender( QgsRenderContext& context );
16-
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
17-
virtual QgsSymbolV2List symbols();
16+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
17+
virtual QgsSymbolV2List symbols( QgsRenderContext& context );
1818
virtual QString dump() const;
1919
virtual QList<QString> usedAttributes();
2020
static QgsFeatureRendererV2* create( QDomElement& element ) /Factory/;

python/core/symbology-ng/qgsinvertedpolygonrenderer.sip

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ class QgsInvertedPolygonRenderer : QgsFeatureRendererV2
4141
/** Proxy that will call this method on the embedded renderer. */
4242
virtual int capabilities();
4343
/** Proxy that will call this method on the embedded renderer. */
44-
virtual QgsSymbolV2List symbols();
44+
virtual QgsSymbolV2List symbols( QgsRenderContext& context );
4545
/** Proxy that will call this method on the embedded renderer. */
46-
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
46+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
4747
/** Proxy that will call this method on the embedded renderer. */
48-
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feat );
48+
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feat, QgsRenderContext& context );
4949
/** Proxy that will call this method on the embedded renderer. */
50-
virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
50+
virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
5151
/** Proxy that will call this method on the embedded renderer. */
52-
virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
52+
virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
5353
/** Proxy that will call this method on the embedded renderer. */
5454
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
5555
/** Proxy that will call this method on the embedded renderer.
5656
@note not available in python bindings
5757
*/
5858
// virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
5959
/** Proxy that will call this method on the embedded renderer. */
60-
virtual bool willRenderFeature( QgsFeature& feat );
60+
virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
6161

6262
/** Creates a renderer out of an XML, for loading*/
6363
static QgsFeatureRendererV2* create( QDomElement& element ) /Factory/;

python/core/symbology-ng/qgspointdisplacementrenderer.sip

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,27 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2
1414
/** Reimplemented from QgsFeatureRendererV2*/
1515
bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
1616

17-
QgsSymbolV2* symbolForFeature( QgsFeature& feature );
17+
/** Partial proxy that will call this method on the embedded renderer. */
18+
virtual QList<QString> usedAttributes();
19+
/** Proxy that will call this method on the embedded renderer. */
20+
virtual int capabilities();
21+
/** Proxy that will call this method on the embedded renderer. */
22+
virtual QgsSymbolV2List symbols( QgsRenderContext& context );
23+
/** Proxy that will call this method on the embedded renderer. */
24+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
25+
/** Proxy that will call this method on the embedded renderer. */
26+
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feat, QgsRenderContext& context );
27+
/** Proxy that will call this method on the embedded renderer. */
28+
virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
29+
/** Proxy that will call this method on the embedded renderer. */
30+
virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
31+
/** Proxy that will call this method on the embedded renderer. */
32+
virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
1833

1934
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
2035

2136
void stopRender( QgsRenderContext& context );
2237

23-
QList<QString> usedAttributes();
24-
QgsSymbolV2List symbols();
25-
2638
//! create a renderer from XML element
2739
static QgsFeatureRendererV2* create( QDomElement& symbologyElem ) /Factory/;
2840
QDomElement save( QDomDocument& doc );

python/core/symbology-ng/qgsrendererv2.sip

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,32 @@ class QgsFeatureRendererV2
6565
* @param feature feature
6666
* @return returns pointer to symbol or 0 if symbol was not found
6767
*/
68-
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;
68+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) /Deprecated/;
69+
70+
/** To be overridden
71+
* @param feature feature
72+
* @param context render context
73+
* @return returns pointer to symbol or 0 if symbol was not found
74+
* @note added in QGIS 2.12
75+
*/
76+
//TODO - make pure virtual when above method is removed
77+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
6978

7079
/**
7180
* Return symbol for feature. The difference compared to symbolForFeature() is that it returns original
7281
* symbol which can be used as an identifier for renderer's rule - the former may return a temporary replacement
7382
* of a symbol for use in rendering.
7483
* @note added in 2.6
7584
*/
76-
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
85+
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature ) /Deprecated/;
86+
87+
/**
88+
* Return symbol for feature. The difference compared to symbolForFeature() is that it returns original
89+
* symbol which can be used as an identifier for renderer's rule - the former may return a temporary replacement
90+
* of a symbol for use in rendering.
91+
* @note added in 2.12
92+
*/
93+
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
7794

7895
virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
7996

@@ -108,7 +125,7 @@ class QgsFeatureRendererV2
108125
virtual int capabilities();
109126

110127
//! for symbol levels
111-
virtual QgsSymbolV2List symbols() = 0;
128+
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) = 0;
112129

113130
bool usingSymbolLevels() const;
114131
void setUsingSymbolLevels( bool usingSymbolLevels );
@@ -180,17 +197,34 @@ class QgsFeatureRendererV2
180197
//! return whether the renderer will render a feature or not.
181198
//! Must be called between startRender() and stopRender() calls.
182199
//! Default implementation uses symbolForFeature().
183-
virtual bool willRenderFeature( QgsFeature& feat );
200+
virtual bool willRenderFeature( QgsFeature& feat ) /Deprecated/;
201+
202+
/** Returns whether the renderer will render a feature or not.
203+
* Must be called between startRender() and stopRender() calls.
204+
* Default implementation uses symbolForFeature().
205+
* @note added in QGIS 2.12
206+
*/
207+
virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
208+
209+
//! return list of symbols used for rendering the feature.
210+
//! For renderers that do not support MoreSymbolsPerFeature it is more efficient
211+
//! to use symbolForFeature()
212+
virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat ) /Deprecated/;
184213

185214
//! return list of symbols used for rendering the feature.
186215
//! For renderers that do not support MoreSymbolsPerFeature it is more efficient
187216
//! to use symbolForFeature()
188-
virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
217+
virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
218+
219+
//! Equivalent of originalSymbolsForFeature() call
220+
//! extended to support renderers that may use more symbols per feature - similar to symbolsForFeature()
221+
//! @note added in 2.6
222+
virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat ) /Deprecated/;
189223

190224
//! Equivalent of originalSymbolsForFeature() call
191225
//! extended to support renderers that may use more symbols per feature - similar to symbolsForFeature()
192226
//! @note added in 2.6
193-
virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
227+
virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
194228

195229
/** Allows for a renderer to modify the extent of a feature request prior to rendering
196230
* @param extent reference to request's filter extent. Modify extent to change the

python/core/symbology-ng/qgsrulebasedrendererv2.sip

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
6060
~Rule();
6161
QString dump( int offset = 0 ) const;
6262
QSet<QString> usedAttributes();
63-
QgsSymbolV2List symbols();
63+
QgsSymbolV2List symbols( const QgsRenderContext& context = QgsRenderContext() );
6464
//! @note not available in python bindings
6565
// QgsLegendSymbolList legendSymbolItems();
6666
//! @note added in 2.6
6767
QgsLegendSymbolListV2 legendSymbolItemsV2( int currentLevel = -1 ) const;
68-
bool isFilterOK( QgsFeature& f ) const;
68+
bool isFilterOK( QgsFeature& f, QgsRenderContext* context = 0 ) const;
6969
bool isScaleOK( double scale ) const;
7070

7171
QgsSymbolV2* symbol();
@@ -117,13 +117,13 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
117117
bool renderFeature( QgsRuleBasedRendererV2::FeatureToRender& featToRender, QgsRenderContext& context, QgsRuleBasedRendererV2::RenderQueue& renderQueue );
118118

119119
//! only tell whether a feature will be rendered without actually rendering it
120-
bool willRenderFeature( QgsFeature& feat );
120+
bool willRenderFeature( QgsFeature& feat, QgsRenderContext* context = 0);
121121

122122
//! tell which symbols will be used to render the feature
123-
QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
123+
QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext* context = 0 );
124124

125125
//! tell which rules will be used to render the feature
126-
QList<QgsRuleBasedRendererV2::Rule*> rulesForFeature( QgsFeature& feat );
126+
QList<QgsRuleBasedRendererV2::Rule*> rulesForFeature( QgsFeature& feat, QgsRenderContext* context = 0 );
127127

128128
void stopRender( QgsRenderContext& context );
129129

@@ -171,7 +171,7 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
171171
~QgsRuleBasedRendererV2();
172172

173173
//! return symbol for current feature. Should not be used individually: there could be more symbols for a feature
174-
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
174+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext &context );
175175

176176
virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
177177

@@ -189,7 +189,7 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
189189

190190
static QgsFeatureRendererV2* createFromSld( QDomElement& element, QGis::GeometryType geomType ) /Factory/;
191191

192-
virtual QgsSymbolV2List symbols();
192+
virtual QgsSymbolV2List symbols( QgsRenderContext &context );
193193

194194
//! store renderer info to XML element
195195
virtual QDomElement save( QDomDocument& doc );
@@ -223,14 +223,14 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
223223

224224
//! return whether the renderer will render a feature or not.
225225
//! Must be called between startRender() and stopRender() calls.
226-
virtual bool willRenderFeature( QgsFeature& feat );
226+
virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext &context );
227227

228228
//! return list of symbols used for rendering the feature.
229229
//! For renderers that do not support MoreSymbolsPerFeature it is more efficient
230230
//! to use symbolForFeature()
231-
virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
231+
virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext &context );
232232

233-
virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
233+
virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext &context );
234234

235235
//! returns bitwise OR-ed capabilities of the renderer
236236
virtual int capabilities();

python/core/symbology-ng/qgssinglesymbolrendererv2.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2
99

1010
virtual ~QgsSingleSymbolRendererV2();
1111

12-
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
12+
virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
1313

14-
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
14+
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
1515

1616
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
1717

@@ -41,7 +41,7 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2
4141
//! returns bitwise OR-ed capabilities of the renderer
4242
virtual int capabilities();
4343

44-
virtual QgsSymbolV2List symbols();
44+
virtual QgsSymbolV2List symbols( QgsRenderContext& context );
4545

4646
//! create renderer from XML element
4747
static QgsFeatureRendererV2* create( QDomElement& element ) /Factory/;

src/app/qgsmaptoolrotatepointsymbols.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent *e )
117117
if ( renderer->capabilities() & QgsFeatureRendererV2::MoreSymbolsPerFeature )
118118
{
119119
//could be multiple symbols for this feature, so check them all
120-
foreach ( QgsSymbolV2* s, renderer->originalSymbolsForFeature( pointFeature ) )
120+
foreach ( QgsSymbolV2* s, renderer->originalSymbolsForFeature( pointFeature, context ) )
121121
{
122122
if ( s && s->type() == QgsSymbolV2::Marker )
123123
{
@@ -135,7 +135,7 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent *e )
135135
}
136136
else
137137
{
138-
QgsSymbolV2* s = renderer->originalSymbolForFeature( pointFeature );
138+
QgsSymbolV2* s = renderer->originalSymbolForFeature( pointFeature, context );
139139
if ( s && s->type() == QgsSymbolV2::Marker )
140140
{
141141
markerSymbol = static_cast< QgsMarkerSymbolV2* >( s );

src/app/qgsmaptoolselectutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
159159
while ( fit.nextFeature( f ) )
160160
{
161161
// make sure to only use features that are visible
162-
if ( r && !r->willRenderFeature( f ) )
162+
if ( r && !r->willRenderFeature( f, context ) )
163163
continue;
164164

165165
const QgsGeometry* g = f.constGeometry();

0 commit comments

Comments
 (0)