Skip to content

Commit 37fa41b

Browse files
committed
[bugfix] Add dirty bit to attribute form
In some cases it is difficult to prevent that an edit widget doesn't return the original value, even if the user didn't change anything. So rather than just comparing values to check if they have been modified, a dirty bit has been added which is set whenever the user actually edits the data in an edit widget. This is part of the fix for #17878.
1 parent 285bb06 commit 37fa41b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/gui/qgsattributeform.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ bool QgsAttributeForm::saveMultiEdits()
565565

566566
bool QgsAttributeForm::save()
567567
{
568-
if ( mIsSaving )
568+
if ( mIsSaving || !mDirty )
569569
return true;
570570

571571
mIsSaving = true;
@@ -594,16 +594,20 @@ bool QgsAttributeForm::save()
594594

595595
mIsSaving = false;
596596
mUnsavedMultiEditChanges = false;
597+
mDirty = false;
597598

598599
return success;
599600
}
600601

601602
void QgsAttributeForm::resetValues()
602603
{
604+
mValuesInitialized = false;
603605
Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
604606
{
605607
ww->setFeature( mFeature );
606608
}
609+
mValuesInitialized = true;
610+
mDirty = false;
607611
}
608612

609613
void QgsAttributeForm::resetSearch()
@@ -658,6 +662,9 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value )
658662
if ( oldValue == value && oldValue.isNull() == value.isNull() )
659663
return;
660664

665+
if ( mValuesInitialized )
666+
mDirty = true;
667+
661668
switch ( mMode )
662669
{
663670
case SingleEditMode:

src/gui/qgsattributeform.h

+2
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
364364
QList< QgsAttributeFormWidget *> mFormWidgets;
365365
QgsExpressionContext mExpressionContext;
366366
QMap<const QgsVectorLayerJoinInfo *, QgsFeature> mJoinedFeatures;
367+
bool mValuesInitialized = false;
368+
bool mDirty = false;
367369

368370
struct ContainerInformation
369371
{

0 commit comments

Comments
 (0)