Skip to content

Commit

Permalink
Fix some issues with QgsRuleBasedRendererV2::Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jan 18, 2016
1 parent d796ade commit 77cbfd3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
39 changes: 32 additions & 7 deletions src/core/symbology-ng/qgsrulebasedrendererv2.cpp
Expand Up @@ -47,6 +47,9 @@ QgsRuleBasedRendererV2::Rule::Rule( QgsSymbolV2* symbol, int scaleMinDenom, int
, mIsActive( true )
, mFilter( nullptr )
{
if ( mElseRule )
mFilterExp = "ELSE";

mRuleKey = QUuid::createUuid().toString();
initFilter();
}
Expand All @@ -61,13 +64,21 @@ QgsRuleBasedRendererV2::Rule::~Rule()

void QgsRuleBasedRendererV2::Rule::initFilter()
{
if ( mFilterExp.compare( "ELSE", Qt::CaseInsensitive ) == 0 || mFilterExp.trimmed().isEmpty() )
if ( mFilterExp.trimmed().compare( "ELSE", Qt::CaseInsensitive ) == 0 )
{
mElseRule = true;
delete mFilter;
mFilter = nullptr;
}
else if ( !mFilterExp.trimmed().isEmpty() )
{
mElseRule = false;
delete mFilter;
mFilter = nullptr;
}
else
{
mElseRule = false;
delete mFilter;
mFilter = new QgsExpression( mFilterExp );
}
Expand Down Expand Up @@ -96,8 +107,7 @@ void QgsRuleBasedRendererV2::Rule::removeChild( Rule* rule )

void QgsRuleBasedRendererV2::Rule::removeChildAt( int i )
{
delete mChildren.at( i );
mChildren.removeAt( i );
delete mChildren.takeAt( i );
updateElseRules();
}

Expand Down Expand Up @@ -142,6 +152,14 @@ void QgsRuleBasedRendererV2::Rule::updateElseRules()
}
}

void QgsRuleBasedRendererV2::Rule::setIsElse( bool iselse )
{
mFilterExp = "ELSE";
mElseRule = iselse;
delete mFilter;
mFilter = nullptr;
}


QString QgsRuleBasedRendererV2::Rule::dump( int indent ) const
{
Expand Down Expand Up @@ -197,6 +215,12 @@ void QgsRuleBasedRendererV2::Rule::setSymbol( QgsSymbolV2* sym )
mSymbol = sym;
}

void QgsRuleBasedRendererV2::Rule::setFilterExpression( const QString& filterExp )
{
mFilterExp = filterExp;
initFilter();
}

QgsLegendSymbolList QgsRuleBasedRendererV2::Rule::legendSymbolItems( double scaleDenominator, const QString& ruleFilter ) const
{
QgsLegendSymbolList lst;
Expand Down Expand Up @@ -428,7 +452,7 @@ bool QgsRuleBasedRendererV2::Rule::startRender( QgsRenderContext& context, const
// Finally they are joined with their parent (this) with AND
QString sf;
// If there are subfilters present (and it's not a single empty one), group them and join them with OR
if ( subfilters.length() > 1 || subfilters.value( 0 ).trimmed().length() > 0 )
if ( subfilters.length() > 1 || !subfilters.value( 0 ).isEmpty() )
{
if ( subfilters.contains( "TRUE" ) )
sf = "TRUE";
Expand All @@ -440,16 +464,17 @@ bool QgsRuleBasedRendererV2::Rule::startRender( QgsRenderContext& context, const
// * The parent is an else rule
// * The existence of parent filter and subfilters

if ( isElse() )
// No filter expression: ELSE rule or catchall rule
if ( !mFilter )
{
if ( mSymbol || sf.trimmed().isEmpty() )
if ( mSymbol || sf.isEmpty() )
filter = "TRUE";
else
filter = sf;
}
else if ( mSymbol )
filter = mFilterExp;
else if ( !mFilterExp.trimmed().isEmpty() && !sf.trimmed().isEmpty() )
else if ( !mFilterExp.trimmed().isEmpty() && !sf.isEmpty() )
filter = QString( "(%1) AND (%2)" ).arg( mFilterExp, sf );
else if ( !mFilterExp.trimmed().isEmpty() )
filter = mFilterExp;
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsrulebasedrendererv2.h
Expand Up @@ -204,7 +204,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
*
* @param filterExp An expression
*/
void setFilterExpression( const QString& filterExp ) { mFilterExp = filterExp; initFilter(); }
void setFilterExpression( const QString& filterExp );

/**
* Set a human readable description for this rule
Expand Down Expand Up @@ -338,7 +338,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
*
* @param iselse If true, this rule is an ELSE rule
*/
void setIsElse( bool iselse ) { mElseRule = iselse; }
void setIsElse( bool iselse );

/**
* Check if this rule is an ELSE rule
Expand Down

0 comments on commit 77cbfd3

Please sign in to comment.