Skip to content

Commit

Permalink
fix(MultiEdits): fire valueChanged when syncing form same fields
Browse files Browse the repository at this point in the history
If not, mIsChanged state and multiedit button icon are not updated in
QgsAttributeFormEditorWidget. The former leads to not saving
modification issues when applying multi edit modifications because
widget could appear not changed.
  • Loading branch information
troopa81 authored and nyalldawson committed Nov 11, 2024
1 parent 00eccb4 commit d45c0fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/gui/qgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,8 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value, const QVariant
if ( formEditorWidget->editorWidget() == eww )
continue;

// formEditorWidget and eww points to the same field, so block signals
// as there is no need to handle valueChanged again for each duplicate
whileBlocking( formEditorWidget->editorWidget() )->setValue( value );
// formEditorWidget and eww points to the same field, so update its value
formEditorWidget->editorWidget()->setValue( value );
}

switch ( mMode )
Expand Down
20 changes: 20 additions & 0 deletions tests/src/gui/testqgsdualview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,31 @@ void TestQgsDualView::testDuplicateField()

const QList<QgsAttributeFormEditorWidget *> formEditorWidgets = dualView.mAttributeForm->mFormEditorWidgets.values( 0 );

// reset mIsChanged state
formEditorWidgets[0]->changesCommitted();
formEditorWidgets[1]->changesCommitted();
QVERIFY( !formEditorWidgets[0]->hasChanged() );
QVERIFY( !formEditorWidgets[1]->hasChanged() );

formEditorWidgets[0]->editorWidget()->setValues( 20, QVariantList() );
QCOMPARE( formEditorWidgets[0]->editorWidget()->value().toInt(), 20 );
QCOMPARE( formEditorWidgets[1]->editorWidget()->value().toInt(), 20 );
QVERIFY( formEditorWidgets[0]->hasChanged() );
QVERIFY( formEditorWidgets[1]->hasChanged() );
ft = layer->getFeature( ft.id() );
QCOMPARE( ft.attribute( QStringLiteral( "col0" ) ).toInt(), 20 );

// reset mIsChanged state
formEditorWidgets[0]->changesCommitted();
formEditorWidgets[1]->changesCommitted();
QVERIFY( !formEditorWidgets[0]->hasChanged() );
QVERIFY( !formEditorWidgets[1]->hasChanged() );

formEditorWidgets[1]->editorWidget()->setValues( 21, QVariantList() );
QCOMPARE( formEditorWidgets[0]->editorWidget()->value().toInt(), 21 );
QCOMPARE( formEditorWidgets[1]->editorWidget()->value().toInt(), 21 );
QVERIFY( formEditorWidgets[0]->hasChanged() );
QVERIFY( formEditorWidgets[1]->hasChanged() );
ft = layer->getFeature( ft.id() );
QCOMPARE( ft.attribute( QStringLiteral( "col0" ) ).toInt(), 21 );

Expand Down

0 comments on commit d45c0fb

Please sign in to comment.