Skip to content

Commit

Permalink
Fix rule-based renderer's descendants() method.
Browse files Browse the repository at this point in the history
This was causing unexpected changes to rule keys on 3rd level and deeper
  • Loading branch information
wonder-sk committed Feb 19, 2015
1 parent c89688a commit e38b13c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsrulebasedrendererv2.h
Expand Up @@ -158,7 +158,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
static Rule* create( QDomElement& ruleElem, QgsSymbolV2Map& symbolMap );

RuleList& children() { return mChildren; }
RuleList descendants() const { RuleList l; foreach ( Rule *c, mChildren ) { l += c; l += c->children(); } return l; }
RuleList descendants() const { RuleList l; foreach ( Rule *c, mChildren ) { l += c; l += c->descendants(); } return l; }
Rule* parent() { return mParent; }

//! add child rule, take ownership, sets this as parent
Expand Down
25 changes: 25 additions & 0 deletions tests/src/core/testqgsrulebasedrenderer.cpp
Expand Up @@ -109,6 +109,31 @@ class TestQgsRuleBasedRenderer: public QObject
delete layer;
}

void test_clone_ruleKey()
{
RRule* rootRule = new RRule( 0 );
RRule* sub1Rule = new RRule( 0, 0, 0, "fld > 1" );
RRule* sub2Rule = new RRule( 0, 0, 0, "fld > 2" );
RRule* sub3Rule = new RRule( 0, 0, 0, "fld > 3" );
rootRule->appendChild( sub1Rule );
sub1Rule->appendChild( sub2Rule );
sub2Rule->appendChild( sub3Rule );
QgsRuleBasedRendererV2 r( rootRule );

QgsRuleBasedRendererV2* clone = static_cast<QgsRuleBasedRendererV2*>( r.clone() );
RRule* cloneRootRule = clone->rootRule();
RRule* cloneSub1Rule = cloneRootRule->children()[0];
RRule* cloneSub2Rule = cloneSub1Rule->children()[0];
RRule* cloneSub3Rule = cloneSub2Rule->children()[0];

QCOMPARE( rootRule->ruleKey(), cloneRootRule->ruleKey() );
QCOMPARE( sub1Rule->ruleKey(), cloneSub1Rule->ruleKey() );
QCOMPARE( sub2Rule->ruleKey(), cloneSub2Rule->ruleKey() );
QCOMPARE( sub3Rule->ruleKey(), cloneSub3Rule->ruleKey() );

delete clone;
}

private:
void xml2domElement( QString testFile, QDomDocument& doc )
{
Expand Down

0 comments on commit e38b13c

Please sign in to comment.