Skip to content

Commit

Permalink
Rename set_variable to with_variable
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jul 7, 2017
1 parent efff5f1 commit 10dc0d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
11 changes: 11 additions & 0 deletions resources/function_help/json/with_variable
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "with_variable",
"type": "function",
"description": "This function sets a variable for any expression code that will be provided as 3rd argument. This is only useful for complicated expressions, where the same calculated value needs to be used in different places.",
"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"}
],
"examples": [ { "expression":"with_variable('my_sum', 1 + 2 + 3, @my_sum * 2 + @my_sum * 5)", "returns":"42"}]
}
14 changes: 7 additions & 7 deletions src/core/expression/qgsexpressionfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4230,7 +4230,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()

sFunctions
<< new QgsStaticExpressionFunction( QStringLiteral( "env" ), 1, fcnEnvVar, QStringLiteral( "General" ), QString() )
<< new QgsSetVariableExpressionFunction()
<< new QgsWithVariableExpressionFunction()
<< new QgsStaticExpressionFunction( QStringLiteral( "attribute" ), 2, fcnAttribute, QStringLiteral( "Record" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES )

// functions for arrays
Expand Down Expand Up @@ -4276,13 +4276,13 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
return sFunctions;
}

QgsSetVariableExpressionFunction::QgsSetVariableExpressionFunction()
: QgsExpressionFunction( "set_variable", 3, QCoreApplication::tr( "General" ), "help text TODODOODO" )
QgsWithVariableExpressionFunction::QgsWithVariableExpressionFunction()
: QgsExpressionFunction( QStringLiteral("with_variable"), 3, QCoreApplication::tr( "General" ) )
{

}

bool QgsSetVariableExpressionFunction::isStatic( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const
bool QgsWithVariableExpressionFunction::isStatic( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const
{
bool isStatic = false;

Expand Down Expand Up @@ -4310,7 +4310,7 @@ bool QgsSetVariableExpressionFunction::isStatic( const QgsExpressionNodeFunction
return false;
}

QVariant QgsSetVariableExpressionFunction::run( QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent )
QVariant QgsWithVariableExpressionFunction::run( QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent )
{
QVariant result;

Expand All @@ -4332,7 +4332,7 @@ QVariant QgsSetVariableExpressionFunction::run( QgsExpressionNode::NodeList *arg
return result;
}

QVariant QgsSetVariableExpressionFunction::func( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent )
QVariant QgsWithVariableExpressionFunction::func( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent )
{
// This is a dummy function, all the real handling is in run
Q_UNUSED( values )
Expand All @@ -4343,7 +4343,7 @@ QVariant QgsSetVariableExpressionFunction::func( const QVariantList &values, con
return QVariant();
}

bool QgsSetVariableExpressionFunction::prepare( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const
bool QgsWithVariableExpressionFunction::prepare( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const
{
QgsExpressionNode::NodeList *args = node->args();

Expand Down
4 changes: 2 additions & 2 deletions src/core/expression/qgsexpressionfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@ class QgsStaticExpressionFunction : public QgsExpressionFunction
bool mIsStatic = false;
};

class QgsSetVariableExpressionFunction : public QgsExpressionFunction
class QgsWithVariableExpressionFunction : public QgsExpressionFunction
{
public:
QgsSetVariableExpressionFunction();
QgsWithVariableExpressionFunction();

bool isStatic( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const override;

Expand Down

0 comments on commit 10dc0d5

Please sign in to comment.