Skip to content

Commit

Permalink
[bugfix] Add dirty bit to attribute form
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgoedkoop committed Jan 28, 2018
1 parent 285bb06 commit 37fa41b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/gui/qgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ bool QgsAttributeForm::saveMultiEdits()

bool QgsAttributeForm::save()
{
if ( mIsSaving )
if ( mIsSaving || !mDirty )
return true;

mIsSaving = true;
Expand Down Expand Up @@ -594,16 +594,20 @@ bool QgsAttributeForm::save()

mIsSaving = false;
mUnsavedMultiEditChanges = false;
mDirty = false;

return success;
}

void QgsAttributeForm::resetValues()
{
mValuesInitialized = false;
Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
{
ww->setFeature( mFeature );
}
mValuesInitialized = true;
mDirty = false;
}

void QgsAttributeForm::resetSearch()
Expand Down Expand Up @@ -658,6 +662,9 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value )
if ( oldValue == value && oldValue.isNull() == value.isNull() )
return;

if ( mValuesInitialized )
mDirty = true;

switch ( mMode )
{
case SingleEditMode:
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsattributeform.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
QList< QgsAttributeFormWidget *> mFormWidgets;
QgsExpressionContext mExpressionContext;
QMap<const QgsVectorLayerJoinInfo *, QgsFeature> mJoinedFeatures;
bool mValuesInitialized = false;
bool mDirty = false;

struct ContainerInformation
{
Expand Down

0 comments on commit 37fa41b

Please sign in to comment.