Skip to content

Commit

Permalink
Used named parameters for with_variable function
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 23, 2018
1 parent 34bb08c commit 89cd785
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion resources/function_help/json/with_variable
Expand Up @@ -5,7 +5,7 @@
"arguments": [
{"arg":"name","description":"the name of the variable to set"},
{"arg":"value","description":"the value to set"},
{"arg":"node","description":"the expression for which the variable will be available"}
{"arg":"expression","description":"the expression for which the variable will be available"}
],
"examples": [ { "expression":"with_variable('my_sum', 1 + 2 + 3, @my_sum * 2 + @my_sum * 5)", "returns":"42"}]
}
6 changes: 5 additions & 1 deletion src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -4863,7 +4863,11 @@ bool QgsArrayForeachExpressionFunction::prepare( const QgsExpressionNodeFunction
}

QgsWithVariableExpressionFunction::QgsWithVariableExpressionFunction()
: QgsExpressionFunction( QStringLiteral( "with_variable" ), 3, QCoreApplication::tr( "General" ) )
: QgsExpressionFunction( QStringLiteral( "with_variable" ), QgsExpressionFunction::ParameterList() <<
QgsExpressionFunction::Parameter( QStringLiteral( "name" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "value" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ) ),
QCoreApplication::tr( "General" ) )
{

}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgsexpression.cpp
Expand Up @@ -1287,7 +1287,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "'a' not like 'a%'" ) << QStringLiteral( "'a' not like 'a%'" ) << false << QVariant( 0 );

// with_variable
QTest::newRow( "with_variable('five', 5, @five * 2)" ) << QStringLiteral( "with_variable('five', 5, @five * 2)" ) << false << QVariant( 10 );
QTest::newRow( "with_variable(name:='five', value:=5, expression:=@five * 2)" ) << QStringLiteral( "with_variable(name:='five', value:=5, expression:=@five * 2)" ) << false << QVariant( 10 );
QTest::newRow( "with_variable('nothing', NULL, COALESCE(@nothing, 'something'))" ) << QStringLiteral( "with_variable('nothing', NULL, COALESCE(@nothing, 'something'))" ) << false << QVariant( "something" );

// array_first, array_last
Expand Down

0 comments on commit 89cd785

Please sign in to comment.