Skip to content
Permalink
Browse files

Move updating of else rules list out of render feature

  • Loading branch information
NathanW2 committed Sep 12, 2013
1 parent af04c79 commit dfe32bad392717150efff051773b5d8b62c2eeee
Showing with 66 additions and 9 deletions.
  1. +57 −3 src/core/symbology-ng/qgsrulebasedrendererv2.cpp
  2. +9 −6 src/core/symbology-ng/qgsrulebasedrendererv2.h
@@ -64,6 +64,61 @@ void QgsRuleBasedRendererV2::Rule::initFilter()
}
}

void QgsRuleBasedRendererV2::Rule::appendChild( Rule* rule )
{
mChildren.append( rule );
rule->mParent = this;
updateElseRules();
}

void QgsRuleBasedRendererV2::Rule::insertChild( int i, Rule* rule )
{
mChildren.insert( i, rule );
rule->mParent = this;
updateElseRules();
}

void QgsRuleBasedRendererV2::Rule::removeChild( Rule* rule )
{
mChildren.removeAll( rule );
delete rule;
updateElseRules();
}

void QgsRuleBasedRendererV2::Rule::removeChildAt( int i )
{
Rule* rule = mChildren[i];
mChildren.removeAt( i );
delete rule;
updateElseRules();
}

void QgsRuleBasedRendererV2::Rule::takeChild( Rule* rule )
{
mChildren.removeAll( rule );
rule->mParent = NULL;
updateElseRules();
}

QgsRuleBasedRendererV2::Rule* QgsRuleBasedRendererV2::Rule::takeChildAt( int i )
{
Rule* rule = mChildren.takeAt( i );
rule->mParent = NULL;
return rule;
updateElseRules();
}

void QgsRuleBasedRendererV2::Rule::updateElseRules()
{
mElseRules.clear();
foreach (Rule* rule, mChildren )
{
if ( rule->isElse() )
mElseRules << rule;
}
}


QString QgsRuleBasedRendererV2::Rule::dump( int offset ) const
{
QString off;
@@ -378,7 +433,6 @@ bool QgsRuleBasedRendererV2::Rule::renderFeature( QgsRuleBasedRendererV2::Featur
rendered = true;
}

QList<Rule*> elserules;
bool willrendersomething = false;

// process children
@@ -387,7 +441,7 @@ bool QgsRuleBasedRendererV2::Rule::renderFeature( QgsRuleBasedRendererV2::Featur
Rule* rule = *it;
if ( rule->isElse())
{
elserules << rule;
// Don't process else rules yet
continue;
}
willrendersomething |= rule->renderFeature( featToRender, context, renderQueue );
@@ -397,7 +451,7 @@ bool QgsRuleBasedRendererV2::Rule::renderFeature( QgsRuleBasedRendererV2::Featur
// If none of the rules passed then we jump into the else rules and process them.
if ( !willrendersomething )
{
foreach(Rule* rule, elserules)
foreach(Rule* rule, mElseRules)
{
rendered |= rule->renderFeature( featToRender, context, renderQueue );
}
@@ -152,17 +152,19 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
Rule* parent() { return mParent; }

//! add child rule, take ownership, sets this as parent
void appendChild( Rule* rule ) { mChildren.append( rule ); rule->mParent = this; }
void appendChild( Rule* rule );
//! add child rule, take ownership, sets this as parent
void insertChild( int i, Rule* rule ) { mChildren.insert( i, rule ); rule->mParent = this; }
void insertChild( int i, Rule* rule );
//! delete child rule
void removeChild( Rule* rule ) { mChildren.removeAll( rule ); delete rule; }
void removeChild( Rule* rule );
//! delete child rule
void removeChildAt( int i ) { Rule* rule = mChildren[i]; mChildren.removeAt( i ); delete rule; }
void removeChildAt( int i );
//! take child rule out, set parent as null
void takeChild( Rule* rule ) { mChildren.removeAll( rule ); rule->mParent = NULL; }
void takeChild( Rule* rule );
//! take child rule out, set parent as null
Rule* takeChildAt( int i ) { Rule* rule = mChildren.takeAt( i ); rule->mParent = NULL; return rule; }
Rule* takeChildAt( int i );

void updateElseRules();

void setIsElse( bool iselse ) { mElseRule = iselse; }
bool isElse() { return mElseRule; }
@@ -176,6 +178,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
QString mFilterExp, mLabel, mDescription;
bool mElseRule;
RuleList mChildren;
RuleList mElseRules;

// temporary
QgsExpression* mFilter;

0 comments on commit dfe32ba

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