Skip to content

Commit

Permalink
Rename functions from get_current_form_field_value to current_value
Browse files Browse the repository at this point in the history
and current_geometry
  • Loading branch information
elpaso committed May 15, 2018
1 parent 83328ae commit 63d2086
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions resources/function_help/json/get_current_form_field_value.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "get_current_form_field_value",
"name": "current_value",
"type": "function",
"description": "Returns the current value of a field in the form or table row currently being edited.",
"arguments": [ {"arg":"field_name","description":"a field name in the current form or table row"}],
"examples": [ { "expression":"get_current_form_field_value( 'FIELD_NAME' )","returns":"The current value of field 'FIELD_NAME'."} ]
"examples": [ { "expression":"current_value( 'FIELD_NAME' )","returns":"The current value of field 'FIELD_NAME'."} ]
}
2 changes: 1 addition & 1 deletion src/core/expression/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ void QgsExpression::initVariableHelp()
sVariableHelpTexts.insert( QStringLiteral( "notification_message" ), QCoreApplication::translate( "notification_message", "Content of the notification message sent by the provider (available only for actions triggered by provider notifications)." ) );

//form context variable
sVariableHelpTexts.insert( QStringLiteral( "current_form_geometry" ), QCoreApplication::translate( "current_form_geometry", "Represents the geometry of the feature currently being edited in the form or the table row. Can be used for in a form/row context to filter the related features." ) );
sVariableHelpTexts.insert( QStringLiteral( "current_geometry" ), QCoreApplication::translate( "current_geometry", "Represents the geometry of the feature currently being edited in the form or the table row. Can be used for in a form/row context to filter the related features." ) );
}

QString QgsExpression::variableHelpText( const QString &variableName )
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsexpressioncontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class GetCurrentFormFieldValue : public QgsScopedExpressionFunction
{
public:
GetCurrentFormFieldValue( )
: QgsScopedExpressionFunction( QStringLiteral( "get_current_form_field_value" ), QgsExpressionFunction::ParameterList() << QStringLiteral( "field_name" ), QStringLiteral( "Form" ) )
: QgsScopedExpressionFunction( QStringLiteral( "current_value" ), QgsExpressionFunction::ParameterList() << QStringLiteral( "field_name" ), QStringLiteral( "Form" ) )
{}

QVariant func( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *, const QgsExpressionNodeFunction * ) override
Expand Down Expand Up @@ -794,8 +794,8 @@ QgsExpressionContextScope *QgsExpressionContextUtils::formScope( const QgsFeatur
{
QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Form" ) );
scope->setFeature( formFeature );
scope->addFunction( QStringLiteral( "get_current_form_field_value" ), new GetCurrentFormFieldValue( ) );
scope->setVariable( QStringLiteral( "current_form_geometry" ), formFeature.geometry( ), true );
scope->addFunction( QStringLiteral( "current_value" ), new GetCurrentFormFieldValue( ) );
scope->setVariable( QStringLiteral( "current_geometry" ), formFeature.geometry( ), true );
return scope;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/src/gui/testqgsvaluerelationwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void TestQgsValueRelationWidgetWrapper::testDrillDown()
cfg_municipality.insert( QStringLiteral( "NofColumns" ), 1 );
cfg_municipality.insert( QStringLiteral( "AllowNull" ), false );
cfg_municipality.insert( QStringLiteral( "OrderByValue" ), true );
cfg_municipality.insert( QStringLiteral( "FilterExpression" ), QStringLiteral( "\"province\" = get_current_form_field_value('fk_province')" ) );
cfg_municipality.insert( QStringLiteral( "FilterExpression" ), QStringLiteral( "\"province\" = current_value('fk_province')" ) );
cfg_municipality.insert( QStringLiteral( "UseCompleter" ), false );
w_municipality.setConfig( cfg_municipality );
w_municipality.widget();
Expand All @@ -170,7 +170,7 @@ void TestQgsValueRelationWidgetWrapper::testDrillDown()
QCOMPARE( w_municipality.mComboBox->itemText( 0 ), QStringLiteral( "Some Place By The River" ) );

// Filter by geometry
cfg_municipality[ QStringLiteral( "FilterExpression" ) ] = QStringLiteral( "contains(buffer(@current_form_geometry, 1 ), $geometry)" );
cfg_municipality[ QStringLiteral( "FilterExpression" ) ] = QStringLiteral( "contains(buffer(@current_geometry, 1 ), $geometry)" );
w_municipality.setConfig( cfg_municipality );
w_municipality.setFeature( f3 );
QCOMPARE( w_municipality.mComboBox->count(), 1 );
Expand All @@ -183,7 +183,7 @@ void TestQgsValueRelationWidgetWrapper::testDrillDown()
QCOMPARE( w_municipality.mComboBox->itemText( 0 ), QStringLiteral( "Dreamland By The Clouds" ) );

// Enlarge the buffer
cfg_municipality[ QStringLiteral( "FilterExpression" ) ] = QStringLiteral( "contains(buffer(@current_form_geometry, 3 ), $geometry)" );
cfg_municipality[ QStringLiteral( "FilterExpression" ) ] = QStringLiteral( "contains(buffer(@current_geometry, 3 ), $geometry)" );
w_municipality.setConfig( cfg_municipality );
w_municipality.setFeature( f3 );
QCOMPARE( w_municipality.mComboBox->count(), 2 );
Expand Down
24 changes: 12 additions & 12 deletions tests/src/python/test_qgsfieldformatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ def _test(a, b):

def test_expressionRequiresFormScope(self):

res = list(QgsValueRelationFieldFormatter.expressionFormAttributes("get_current_form_field_value('ONE') AND get_current_form_field_value('TWO')"))
res = list(QgsValueRelationFieldFormatter.expressionFormAttributes("current_value('ONE') AND current_value('TWO')"))
res = sorted(res)
self.assertEqual(res, ['ONE', 'TWO'])

res = list(QgsValueRelationFieldFormatter.expressionFormVariables("current_form_geometry"))
self.assertEqual(res, ['current_form_geometry'])
res = list(QgsValueRelationFieldFormatter.expressionFormVariables("current_geometry"))
self.assertEqual(res, ['current_geometry'])

self.assertFalse(QgsValueRelationFieldFormatter.expressionRequiresFormScope(""))
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("get_current_form_field_value('TWO')"))
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("get_current_form_field_value ( 'TWO' )"))
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("current_form_geometry"))
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("current_value('TWO')"))
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("current_value ( 'TWO' )"))
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("current_geometry"))

self.assertTrue(QgsValueRelationFieldFormatter.expressionIsUsable("", QgsFeature()))
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("current_form_geometry", QgsFeature()))
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("get_current_form_field_value ( 'TWO' )", QgsFeature()))
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("current_geometry", QgsFeature()))
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("current_value ( 'TWO' )", QgsFeature()))

layer = QgsVectorLayer("none?field=pkid:integer&field=decoded:string",
"layer", "memory")
Expand All @@ -160,10 +160,10 @@ def test_expressionRequiresFormScope(self):
f.setAttributes([1, 'value'])
point = QgsGeometry.fromPointXY(QgsPointXY(123, 456))
f.setGeometry(point)
self.assertTrue(QgsValueRelationFieldFormatter.expressionIsUsable("current_form_geometry", f))
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("get_current_form_field_value ( 'TWO' )", f))
self.assertTrue(QgsValueRelationFieldFormatter.expressionIsUsable("get_current_form_field_value ( 'pkid' )", f))
self.assertTrue(QgsValueRelationFieldFormatter.expressionIsUsable("@current_form_geometry get_current_form_field_value ( 'pkid' )", f))
self.assertTrue(QgsValueRelationFieldFormatter.expressionIsUsable("current_geometry", f))
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("current_value ( 'TWO' )", f))
self.assertTrue(QgsValueRelationFieldFormatter.expressionIsUsable("current_value ( 'pkid' )", f))
self.assertTrue(QgsValueRelationFieldFormatter.expressionIsUsable("@current_geometry current_value ( 'pkid' )", f))

QgsProject.instance().removeMapLayer(layer.id())

Expand Down

0 comments on commit 63d2086

Please sign in to comment.