Skip to content
Permalink
Browse files

Fix some issues with QgsRuleBasedRendererV2::Rule

  • Loading branch information
m-kuhn committed Jan 18, 2016
1 parent d796ade commit 77cbfd34cf728f02c0cb36e6591133bf8f731200
Showing with 34 additions and 9 deletions.
  1. +32 −7 src/core/symbology-ng/qgsrulebasedrendererv2.cpp
  2. +2 −2 src/core/symbology-ng/qgsrulebasedrendererv2.h
@@ -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();
}
@@ -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 );
}
@@ -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();
}

@@ -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
{
@@ -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;
@@ -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";
@@ -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;
@@ -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
@@ -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

0 comments on commit 77cbfd3

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