From f00e9a9f16a9f653d42cb960f882edba85f5329f Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 6 Jul 2024 12:42:37 +0700 Subject: [PATCH] Add test coverage --- tests/src/gui/testqgsattributeform.cpp | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/src/gui/testqgsattributeform.cpp b/tests/src/gui/testqgsattributeform.cpp index 82bea31db6b19..4ace795bb626e 100644 --- a/tests/src/gui/testqgsattributeform.cpp +++ b/tests/src/gui/testqgsattributeform.cpp @@ -58,6 +58,7 @@ class TestQgsAttributeForm : public QObject void testAttributeFormInterface(); void testDefaultValueUpdate(); void testDefaultValueUpdateRecursion(); + void testParentFeatureUpdate(); void testSameFieldSync(); void testZeroDoubles(); void testMinimumWidth(); @@ -1111,6 +1112,38 @@ void TestQgsAttributeForm::testDefaultValueUpdateRecursion() QCOMPARE( ww3->value().toInt(), 43 ); } +void TestQgsAttributeForm::testParentFeatureUpdate() +{ + // make a temporary layer to check through + const QString def = QStringLiteral( "Point?field=col0:integer" ); + QgsVectorLayer *layer = new QgsVectorLayer( def, QStringLiteral( "test" ), QStringLiteral( "memory" ) ); + layer->setDefaultValueDefinition( 0, QgsDefaultValue( QStringLiteral( "current_parent_value('colZero\')" ), true ) ); + layer->startEditing(); + + // initalize parent feature + QgsFields parentFields; + parentFields.append( QgsField( QStringLiteral( "colZero" ), QMetaType::Type::Int ) ); + + QgsFeature parentFeature( parentFields, 1 ); + parentFeature.setAttribute( QStringLiteral( "colZero" ), 10 ); + + // initalize child feature + QgsFeature feature( layer->dataProvider()->fields(), 1 ); + + // build a form + QgsAttributeEditorContext context; + context.setParentFormFeature( parentFeature ); + QgsAttributeForm form( layer, feature, context ); + + // get wrappers for each widget + QgsEditorWidgetWrapper *ww0; + ww0 = qobject_cast( form.mWidgets[0] ); + + form.parentFormValueChanged( QStringLiteral( "colZero" ), 20 ); + + QCOMPARE( ww0->value().toInt(), 20 ); +} + void TestQgsAttributeForm::testSameFieldSync() { // Check that widget synchronisation works when a form contains the same field several times