Skip to content

Commit 89cd785

Browse files
committedAug 23, 2018
Used named parameters for with_variable function
1 parent 34bb08c commit 89cd785

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed
 

‎resources/function_help/json/with_variable

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"arguments": [
66
{"arg":"name","description":"the name of the variable to set"},
77
{"arg":"value","description":"the value to set"},
8-
{"arg":"node","description":"the expression for which the variable will be available"}
8+
{"arg":"expression","description":"the expression for which the variable will be available"}
99
],
1010
"examples": [ { "expression":"with_variable('my_sum', 1 + 2 + 3, @my_sum * 2 + @my_sum * 5)", "returns":"42"}]
1111
}

‎src/core/expression/qgsexpressionfunction.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4863,7 +4863,11 @@ bool QgsArrayForeachExpressionFunction::prepare( const QgsExpressionNodeFunction
48634863
}
48644864

48654865
QgsWithVariableExpressionFunction::QgsWithVariableExpressionFunction()
4866-
: QgsExpressionFunction( QStringLiteral( "with_variable" ), 3, QCoreApplication::tr( "General" ) )
4866+
: QgsExpressionFunction( QStringLiteral( "with_variable" ), QgsExpressionFunction::ParameterList() <<
4867+
QgsExpressionFunction::Parameter( QStringLiteral( "name" ) )
4868+
<< QgsExpressionFunction::Parameter( QStringLiteral( "value" ) )
4869+
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ) ),
4870+
QCoreApplication::tr( "General" ) )
48674871
{
48684872

48694873
}

‎tests/src/core/testqgsexpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ class TestQgsExpression: public QObject
12871287
QTest::newRow( "'a' not like 'a%'" ) << QStringLiteral( "'a' not like 'a%'" ) << false << QVariant( 0 );
12881288

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

12931293
// array_first, array_last

0 commit comments

Comments
 (0)
Please sign in to comment.