Skip to content
Permalink
Browse files

[bugfix] Fixes willRenderFeature method for QgsRuledBasedRenderer

  • Loading branch information
pblottiere committed Mar 27, 2018
1 parent 7b8603c commit d6331a6d3d2e9b8a9075ca097176e361ccc8d701
Showing with 30 additions and 6 deletions.
  1. +28 −4 src/core/symbology/qgsrulebasedrenderer.cpp
  2. +2 −2 src/core/symbology/qgsrulebasedrenderer.h
@@ -581,7 +581,7 @@ QSet<QString> QgsRuleBasedRenderer::Rule::legendKeysForFeature( QgsFeature &feat
return lst;
}

QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::rulesForFeature( QgsFeature &feat, QgsRenderContext *context )
QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::rulesForFeature( QgsFeature &feat, QgsRenderContext *context, bool withElse, bool onlyActive )
{
RuleList lst;
if ( !isFilterOK( feat, context ) )
@@ -590,9 +590,16 @@ QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::rulesForFeature( QgsF
if ( mSymbol )
lst.append( this );

Q_FOREACH ( Rule *rule, mActiveChildren )
RuleList listChildren = children();
if ( onlyActive )
listChildren = mActiveChildren;

Q_FOREACH ( Rule *rule, listChildren )
{
lst += rule->rulesForFeature( feat, context );
if ( rule->isElse() && !withElse )
continue;

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

bool QgsRuleBasedRenderer::willRenderFeature( QgsFeature &feat, QgsRenderContext &context )
{
return mRootRule->willRenderFeature( feat, &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;
}

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 );
QgsRuleBasedRenderer::RuleList rulesForFeature( QgsFeature &feat, QgsRenderContext *context = nullptr, bool withElse = true, bool onlyActive = true );

/**
* Stop a rendering process. Used to clean up the internal state of this rule
@@ -419,7 +419,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
*
* \returns True if this rule is an else rule
*/
bool isElse() { return mElseRule; }
bool isElse() const { return mElseRule; }

protected:
void initFilter();

0 comments on commit d6331a6

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