|
21 | 21 | #include <attributetable/qgsdualview.h>
|
22 | 22 | #include <editform/qgsattributeeditorhtmlelement.h>
|
23 | 23 | #include "qgsattributeform.h"
|
| 24 | +#include "qgsattributeeditorcontainer.h" |
| 25 | +#include "qgsattributeeditorfield.h" |
| 26 | +#include "qgsattributeformeditorwidget.h" |
24 | 27 | #include <qgsapplication.h>
|
25 | 28 | #include "qgsfeatureiterator.h"
|
26 | 29 | #include <qgsvectorlayer.h>
|
@@ -58,6 +61,8 @@ class TestQgsDualView : public QObject
|
58 | 61 | void testAttributeFormSharedValueScanning();
|
59 | 62 | void testNoGeom();
|
60 | 63 |
|
| 64 | + void testDuplicateField(); |
| 65 | + |
61 | 66 | #ifdef WITH_QTWEBKIT
|
62 | 67 | void testHtmlWidget_data();
|
63 | 68 | void testHtmlWidget();
|
@@ -404,5 +409,46 @@ void TestQgsDualView::testHtmlWidget()
|
404 | 409 | }
|
405 | 410 | #endif
|
406 | 411 |
|
| 412 | +void TestQgsDualView::testDuplicateField() |
| 413 | +{ |
| 414 | + // test updating same field appearing in different widget |
| 415 | + |
| 416 | + // make a temporary vector layer |
| 417 | + const QString def = QStringLiteral( "Point?field=col0:integer" ); |
| 418 | + QgsVectorLayer *layer = new QgsVectorLayer( def, QStringLiteral( "test" ), QStringLiteral( "memory" ) ); |
| 419 | + layer->setEditorWidgetSetup( 0, QgsEditorWidgetSetup( QStringLiteral( "Range" ), QVariantMap() ) ); |
| 420 | + |
| 421 | + // add same field twice so they get synced |
| 422 | + QgsEditFormConfig editFormConfig = layer->editFormConfig(); |
| 423 | + editFormConfig.clearTabs(); |
| 424 | + editFormConfig.invisibleRootContainer()->addChildElement( new QgsAttributeEditorField( "col0", 0, editFormConfig.invisibleRootContainer() ) ); |
| 425 | + editFormConfig.invisibleRootContainer()->addChildElement( new QgsAttributeEditorField( "col0", 0, editFormConfig.invisibleRootContainer() ) ); |
| 426 | + editFormConfig.setLayout( Qgis::AttributeFormLayout::DragAndDrop ); |
| 427 | + layer->setEditFormConfig( editFormConfig ); |
| 428 | + |
| 429 | + // add a feature to the vector layer |
| 430 | + QgsFeature ft( layer->dataProvider()->fields(), 1 ); |
| 431 | + ft.setAttribute( QStringLiteral( "col0" ), 1 ); |
| 432 | + layer->dataProvider()->addFeature( ft ); |
| 433 | + |
| 434 | + QgsDualView dualView; |
| 435 | + dualView.init( layer, mCanvas ); |
| 436 | + |
| 437 | + layer->startEditing(); |
| 438 | + |
| 439 | + const QList<QgsAttributeFormEditorWidget *> formEditorWidgets = dualView.mAttributeForm->mFormEditorWidgets.values( 0 ); |
| 440 | + |
| 441 | + formEditorWidgets[0]->editorWidget()->setValues( 20, QVariantList() ); |
| 442 | + ft = layer->getFeature( ft.id() ); |
| 443 | + QCOMPARE( ft.attribute( QStringLiteral( "col0" ) ).toInt(), 20 ); |
| 444 | + |
| 445 | + formEditorWidgets[1]->editorWidget()->setValues( 21, QVariantList() ); |
| 446 | + ft = layer->getFeature( ft.id() ); |
| 447 | + QCOMPARE( ft.attribute( QStringLiteral( "col0" ) ).toInt(), 21 ); |
| 448 | + |
| 449 | + layer->rollBack(); |
| 450 | +} |
| 451 | + |
| 452 | + |
407 | 453 | QGSTEST_MAIN( TestQgsDualView )
|
408 | 454 | #include "testqgsdualview.moc"
|
0 commit comments