Skip to content

Commit

Permalink
If transformer set on property, allow transformer to handle null values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 14, 2017
1 parent 84dd983 commit 2aae6e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/qgsproperty.cpp
Expand Up @@ -464,11 +464,13 @@ QVariant QgsProperty::value( const QgsExpressionContext& context, const QVariant

bool valOk = false;
QVariant val = propertyValue( context, defaultValue, &valOk );
if ( !valOk )
if ( !d->transformer && !valOk ) // if transformer present, let it handle null values
return defaultValue;

if ( d->transformer )
{
if ( !valOk )
val = QVariant();
val = d->transformer->transform( context, val );
}

Expand Down
20 changes: 20 additions & 0 deletions tests/src/core/testqgsproperty.cpp
Expand Up @@ -807,6 +807,26 @@ void TestQgsProperty::sizeScaleTransformer()
t2.setType( QgsSizeScaleTransformer::Exponential );
t2.setExponent( 1.6 );
QCOMPARE( t2.toExpression( "5+6" ), QStringLiteral( "coalesce(scale_exp(5+6, 15, 25, 150, 250, 1.6), -10)" ) );

// test size scale transformer inside property
QgsProperty p;
p.setTransformer( new QgsSizeScaleTransformer( QgsSizeScaleTransformer::Exponential,
15,
25,
150,
250,
-10,
99 ) );
p.setStaticValue( QVariant() );
bool ok = false;
QCOMPARE( p.valueAsDouble( context, 100, &ok ), -10.0 );
QVERIFY( ok );
p.setExpressionString( QStringLiteral( "NULL" ) );
QCOMPARE( p.valueAsDouble( context, 100, &ok ), -10.0 );
QVERIFY( ok );
p.setExpressionString( QStringLiteral( "no field" ) );
QCOMPARE( p.valueAsDouble( context, 100, &ok ), -10.0 );
QVERIFY( ok );
}

void TestQgsProperty::sizeScaleTransformerFromExpression()
Expand Down

0 comments on commit 2aae6e4

Please sign in to comment.