Skip to content
Permalink
Browse files

Merge pull request #5555 from m-kuhn/fixRepresentValue

Fix represent value
  • Loading branch information
m-kuhn committed Nov 7, 2017
2 parents 07cef67 + 80ea446 commit 8aa8c30bbfdce579323366daa84bdb2c04ef2d46
Showing with 9 additions and 8 deletions.
  1. +5 −7 src/core/expression/qgsexpressionfunction.cpp
  2. +4 −1 tests/src/core/testqgsexpression.cpp
@@ -3435,15 +3435,13 @@ static QVariant fcnRepresentValue( const QVariantList &values, const QgsExpressi
{
QVariant result;
QString fieldName;
if ( values.size() == 1 )
if ( !values.isEmpty() )
{
QgsExpressionNodeColumnRef *col = dynamic_cast<QgsExpressionNodeColumnRef *>( node->args()->at( 0 ) );
if ( col )
if ( col && ( values.size() == 1 || !values.at( 1 ).isValid() ) )
fieldName = col->name();
}
else
{
fieldName = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
else if ( values.size() == 2 )
fieldName = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
}
QVariant value = values.at( 0 );

@@ -3456,7 +3454,7 @@ static QVariant fcnRepresentValue( const QVariantList &values, const QgsExpressi

if ( index == -1 )
{
parent->setEvalErrorString( QStringLiteral( "%1: Field not found %2" ).arg( QStringLiteral( "represent_value" ), fieldName ) );
parent->setEvalErrorString( QCoreApplication::translate( "expression", "%1: Field not found %2" ).arg( QStringLiteral( "represent_value" ), fieldName ) );
}
else
{
@@ -420,9 +420,12 @@ class TestQgsExpression: public QObject
if ( expression3.hasEvalError() )
qDebug() << expression3.evalErrorString();
Q_ASSERT( !expression3.hasEvalError() );
expression3.prepare( &context );

mPointsLayer->getFeatures( QgsFeatureRequest().setFilterExpression( "Pilots = 1" ) ).nextFeature( feature );
context.setFeature( feature );

QCOMPARE( expression.evaluate( &context ).toString(), QStringLiteral( "one" ) );
expression3.prepare( &context );
QCOMPARE( expression.evaluate( &context ).toString(), QStringLiteral( "one" ) );


0 comments on commit 8aa8c30

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