Skip to content
Permalink
Browse files

If transformer set on property, allow transformer to handle null values

  • Loading branch information
nyalldawson committed Feb 14, 2017
1 parent 84dd983 commit 2aae6e42d5af20b5383c4f96b28f4b3a7f2c9794
Showing with 23 additions and 1 deletion.
  1. +3 −1 src/core/qgsproperty.cpp
  2. +20 −0 tests/src/core/testqgsproperty.cpp
@@ -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 );
}

@@ -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()

0 comments on commit 2aae6e4

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