From 89cd7858e54db2e19b8ce151952034a093ea801f Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 23 Aug 2018 10:06:20 +1000 Subject: [PATCH] Used named parameters for with_variable function --- resources/function_help/json/with_variable | 2 +- src/core/expression/qgsexpressionfunction.cpp | 6 +++++- tests/src/core/testqgsexpression.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/resources/function_help/json/with_variable b/resources/function_help/json/with_variable index bc8f2dd56a6..87d80f3643c 100644 --- a/resources/function_help/json/with_variable +++ b/resources/function_help/json/with_variable @@ -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"}] } diff --git a/src/core/expression/qgsexpressionfunction.cpp b/src/core/expression/qgsexpressionfunction.cpp index b5a0a752b64..1d82c5b0d82 100644 --- a/src/core/expression/qgsexpressionfunction.cpp +++ b/src/core/expression/qgsexpressionfunction.cpp @@ -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" ) ) { } diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp index eec700ee4f6..8ad9049a48e 100644 --- a/tests/src/core/testqgsexpression.cpp +++ b/tests/src/core/testqgsexpression.cpp @@ -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