Skip to content
Permalink
Browse files

Fix rule-based renderer's descendants() method.

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 e38b13c5d0a9a691400e5814492145d2574a092d
Showing with 26 additions and 1 deletion.
  1. +1 −1 src/core/symbology-ng/qgsrulebasedrendererv2.h
  2. +25 −0 tests/src/core/testqgsrulebasedrenderer.cpp
@@ -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
@@ -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 )
{

0 comments on commit e38b13c

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