Skip to content

Commit

Permalink
[bugfix] Fixes willRenderFeature method for QgsRuledBasedRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 27, 2018
1 parent 7b8603c commit d6331a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
32 changes: 28 additions & 4 deletions src/core/symbology/qgsrulebasedrenderer.cpp
Expand Up @@ -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 ) )
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology/qgsrulebasedrenderer.h
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d6331a6

Please sign in to comment.