Skip to content
Permalink
Browse files

Recursive fix

  • Loading branch information
pblottiere committed Mar 27, 2018
1 parent dd6f98f commit 0b5c2aeecc06061c80dabd48ffb700b697ac0141
@@ -324,7 +324,7 @@ Returns which legend keys match the feature
.. versionadded:: 2.14
%End

QgsRuleBasedRenderer::RuleList rulesForFeature( QgsFeature &feat, QgsRenderContext *context = 0, bool withElse = true, bool onlyActive = true );
QgsRuleBasedRenderer::RuleList rulesForFeature( QgsFeature &feat, QgsRenderContext *context = 0, bool onlyActive = true );
%Docstring
tell which rules will be used to render the feature
%End
@@ -541,13 +541,24 @@ bool QgsRuleBasedRenderer::Rule::willRenderFeature( QgsFeature &feat, QgsRenderC
{
if ( !isFilterOK( feat, context ) )
return false;

if ( mSymbol )
return true;

Q_FOREACH ( Rule *rule, mActiveChildren )
{
if ( rule->willRenderFeature( feat, context ) )
if ( rule->isElse() )
{
RuleList lst = rulesForFeature( feat, context, false );
lst.removeOne( rule );

if ( lst.empty() )
return true;
}
else if ( !rule->isElse( ) && rule->willRenderFeature( feat, context ) )
{
return true;
}
}
return false;
}
@@ -581,7 +592,7 @@ QSet<QString> QgsRuleBasedRenderer::Rule::legendKeysForFeature( QgsFeature &feat
return lst;
}

QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::rulesForFeature( QgsFeature &feat, QgsRenderContext *context, bool withElse, bool onlyActive )
QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::rulesForFeature( QgsFeature &feat, QgsRenderContext *context, bool onlyActive )
{
RuleList lst;
if ( !isFilterOK( feat, context ) )
@@ -596,10 +607,7 @@ QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::rulesForFeature( QgsF

Q_FOREACH ( Rule *rule, listChildren )
{
if ( rule->isElse() && !withElse )
continue;

lst += rule->rulesForFeature( feat, context, withElse, onlyActive );
lst += rule->rulesForFeature( feat, context, onlyActive );
}
return lst;
}
@@ -1148,24 +1156,7 @@ QString QgsRuleBasedRenderer::dump() const

bool QgsRuleBasedRenderer::willRenderFeature( QgsFeature &feat, QgsRenderContext &context )
{
for ( Rule *rule : mRootRule->children() )
{
if ( ! rule->active() )
continue;

// a feature already rendered by another rule shouldn't be considered in a
// 'else' statement for rendering
if ( rule->isElse() && mRootRule->rulesForFeature( feat, &context, false, false ).empty() )
{
return true;
}
else if ( !rule->isElse( ) && rule->willRenderFeature( feat, &context ) )
{
return true;
}
}

return false;
return mRootRule->willRenderFeature( feat, &context );
}

QgsSymbolList QgsRuleBasedRenderer::symbolsForFeature( QgsFeature &feat, QgsRenderContext &context )
@@ -343,7 +343,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
QSet< QString > legendKeysForFeature( QgsFeature &feat, QgsRenderContext *context = nullptr );

//! tell which rules will be used to render the feature
QgsRuleBasedRenderer::RuleList rulesForFeature( QgsFeature &feat, QgsRenderContext *context = nullptr, bool withElse = true, bool onlyActive = true );
QgsRuleBasedRenderer::RuleList rulesForFeature( QgsFeature &feat, QgsRenderContext *context = nullptr, bool onlyActive = true );

/**
* Stop a rendering process. Used to clean up the internal state of this rule
@@ -115,12 +115,14 @@ def testWillRenderFeature(self):
renderer.rootRule().children()[2].setActive(True)

renderer.startRender(ctx, vl.fields()) # build mActiveChlidren

rendered = renderer.willRenderFeature(ft, ctx)
renderer.stopRender(ctx)
renderer.rootRule().children()[0].setActive(True)
assert rendered == False

renderer.startRender(ctx, vl.fields()) # build mActiveChlidren
rendered = renderer.willRenderFeature(ft, ctx)
renderer.stopRender(ctx)
assert rendered == True

def testRefineWithCategories(self):

0 comments on commit 0b5c2ae

Please sign in to comment.
You can’t perform that action at this time.