Skip to content

Commit 63d2086

Browse files
committedMay 15, 2018
Rename functions from get_current_form_field_value to current_value
and current_geometry
1 parent 83328ae commit 63d2086

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed
 
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "get_current_form_field_value",
2+
"name": "current_value",
33
"type": "function",
44
"description": "Returns the current value of a field in the form or table row currently being edited.",
55
"arguments": [ {"arg":"field_name","description":"a field name in the current form or table row"}],
6-
"examples": [ { "expression":"get_current_form_field_value( 'FIELD_NAME' )","returns":"The current value of field 'FIELD_NAME'."} ]
6+
"examples": [ { "expression":"current_value( 'FIELD_NAME' )","returns":"The current value of field 'FIELD_NAME'."} ]
77
}

‎src/core/expression/qgsexpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ void QgsExpression::initVariableHelp()
773773
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)." ) );
774774

775775
//form context variable
776-
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." ) );
776+
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." ) );
777777
}
778778

779779
QString QgsExpression::variableHelpText( const QString &variableName )

‎src/core/qgsexpressioncontext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ class GetCurrentFormFieldValue : public QgsScopedExpressionFunction
741741
{
742742
public:
743743
GetCurrentFormFieldValue( )
744-
: QgsScopedExpressionFunction( QStringLiteral( "get_current_form_field_value" ), QgsExpressionFunction::ParameterList() << QStringLiteral( "field_name" ), QStringLiteral( "Form" ) )
744+
: QgsScopedExpressionFunction( QStringLiteral( "current_value" ), QgsExpressionFunction::ParameterList() << QStringLiteral( "field_name" ), QStringLiteral( "Form" ) )
745745
{}
746746

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

‎tests/src/gui/testqgsvaluerelationwidgetwrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void TestQgsValueRelationWidgetWrapper::testDrillDown()
155155
cfg_municipality.insert( QStringLiteral( "NofColumns" ), 1 );
156156
cfg_municipality.insert( QStringLiteral( "AllowNull" ), false );
157157
cfg_municipality.insert( QStringLiteral( "OrderByValue" ), true );
158-
cfg_municipality.insert( QStringLiteral( "FilterExpression" ), QStringLiteral( "\"province\" = get_current_form_field_value('fk_province')" ) );
158+
cfg_municipality.insert( QStringLiteral( "FilterExpression" ), QStringLiteral( "\"province\" = current_value('fk_province')" ) );
159159
cfg_municipality.insert( QStringLiteral( "UseCompleter" ), false );
160160
w_municipality.setConfig( cfg_municipality );
161161
w_municipality.widget();
@@ -170,7 +170,7 @@ void TestQgsValueRelationWidgetWrapper::testDrillDown()
170170
QCOMPARE( w_municipality.mComboBox->itemText( 0 ), QStringLiteral( "Some Place By The River" ) );
171171

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

185185
// Enlarge the buffer
186-
cfg_municipality[ QStringLiteral( "FilterExpression" ) ] = QStringLiteral( "contains(buffer(@current_form_geometry, 3 ), $geometry)" );
186+
cfg_municipality[ QStringLiteral( "FilterExpression" ) ] = QStringLiteral( "contains(buffer(@current_geometry, 3 ), $geometry)" );
187187
w_municipality.setConfig( cfg_municipality );
188188
w_municipality.setFeature( f3 );
189189
QCOMPARE( w_municipality.mComboBox->count(), 2 );

‎tests/src/python/test_qgsfieldformatters.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,21 @@ def _test(a, b):
136136

137137
def test_expressionRequiresFormScope(self):
138138

139-
res = list(QgsValueRelationFieldFormatter.expressionFormAttributes("get_current_form_field_value('ONE') AND get_current_form_field_value('TWO')"))
139+
res = list(QgsValueRelationFieldFormatter.expressionFormAttributes("current_value('ONE') AND current_value('TWO')"))
140140
res = sorted(res)
141141
self.assertEqual(res, ['ONE', 'TWO'])
142142

143-
res = list(QgsValueRelationFieldFormatter.expressionFormVariables("current_form_geometry"))
144-
self.assertEqual(res, ['current_form_geometry'])
143+
res = list(QgsValueRelationFieldFormatter.expressionFormVariables("current_geometry"))
144+
self.assertEqual(res, ['current_geometry'])
145145

146146
self.assertFalse(QgsValueRelationFieldFormatter.expressionRequiresFormScope(""))
147-
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("get_current_form_field_value('TWO')"))
148-
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("get_current_form_field_value ( 'TWO' )"))
149-
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("current_form_geometry"))
147+
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("current_value('TWO')"))
148+
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("current_value ( 'TWO' )"))
149+
self.assertTrue(QgsValueRelationFieldFormatter.expressionRequiresFormScope("current_geometry"))
150150

151151
self.assertTrue(QgsValueRelationFieldFormatter.expressionIsUsable("", QgsFeature()))
152-
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("current_form_geometry", QgsFeature()))
153-
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("get_current_form_field_value ( 'TWO' )", QgsFeature()))
152+
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("current_geometry", QgsFeature()))
153+
self.assertFalse(QgsValueRelationFieldFormatter.expressionIsUsable("current_value ( 'TWO' )", QgsFeature()))
154154

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.