Skip to content

Commit

Permalink
Merge pull request #5555 from m-kuhn/fixRepresentValue
Browse files Browse the repository at this point in the history
Fix represent value
  • Loading branch information
m-kuhn committed Nov 7, 2017
2 parents 07cef67 + 80ea446 commit 8aa8c30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -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 );

Expand All @@ -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
{
Expand Down
5 changes: 4 additions & 1 deletion tests/src/core/testqgsexpression.cpp
Expand Up @@ -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" ) );


Expand Down

0 comments on commit 8aa8c30

Please sign in to comment.