Skip to content

Commit

Permalink
Allow + for string concat in QgsExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Aug 18, 2014
1 parent 0b213b6 commit 978642a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,12 @@ QVariant QgsExpression::NodeBinaryOperator::eval( QgsExpression* parent, const Q
switch ( mOp )
{
case boPlus:
if ( vL.type() == QVariant::String && vR.type() == QVariant::String )
{
QString sL = getStringValue( vL, parent ); ENSURE_NO_EVAL_ERROR;
QString sR = getStringValue( vR, parent ); ENSURE_NO_EVAL_ERROR;
return QVariant( sL + sR );
}
case boMinus:
case boMul:
case boDiv:
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "regexp 3" ) << "'hello' ~ 'llo$'" << false << QVariant( 1 );

// concatenation
QTest::newRow( "concat with plus" ) << "'a' + 'b'" << false << QVariant( "ab" );
QTest::newRow( "concat" ) << "'a' || 'b'" << false << QVariant( "ab" );
QTest::newRow( "concat with int" ) << "'a' || 1" << false << QVariant( "a1" );
QTest::newRow( "concat with int" ) << "2 || 'b'" << false << QVariant( "2b" );
Expand Down

0 comments on commit 978642a

Please sign in to comment.