Skip to content

Commit

Permalink
Do not assume edit widget value changes on every signal
Browse files Browse the repository at this point in the history
Widgets may on initialisation send out a notification that the value changed (from invalid to something sensible).

The attribute form should however only tell the rest of the world, that a value changed if the new value doesn't
correspond to the one in the cached QgsFeature.

Fix #17425
  • Loading branch information
m-kuhn committed Nov 9, 2017
1 parent dca0dc1 commit 61b2f74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 7 additions & 10 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -61,7 +61,6 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer *vl, const QgsFeature &featur
, mFormNr( sFormCounter++ )
, mIsSaving( false )
, mPreventFeatureRefresh( false )
, mIsSettingFeature( false )
, mIsSettingMultiEditFeatures( false )
, mUnsavedMultiEditChanges( false )
, mEditCommandMessage( tr( "Attributes changed" ) )
Expand Down Expand Up @@ -222,7 +221,6 @@ void QgsAttributeForm::changeAttribute( const QString &field, const QVariant &va

void QgsAttributeForm::setFeature( const QgsFeature &feature )
{
mIsSettingFeature = true;
mFeature = feature;

switch ( mMode )
Expand All @@ -247,7 +245,6 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature )
break;
}
}
mIsSettingFeature = false;
}

bool QgsAttributeForm::saveEdits()
Expand Down Expand Up @@ -641,19 +638,20 @@ QString QgsAttributeForm::createFilterExpression() const
void QgsAttributeForm::onAttributeChanged( const QVariant &value )
{
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( sender() );

Q_ASSERT( eww );

const QVariant oldValue = mFeature.attribute( eww->fieldIdx() );

// Safetey check, if we receive the same value again, no reason to do anything
if ( oldValue == value && oldValue.isNull() == value.isNull() )
return;

switch ( mMode )
{
case SingleEditMode:
case AddFeatureMode:
{
// don't emit signal if it was triggered by a feature change
if ( !mIsSettingFeature )
{
emit attributeChanged( eww->field().name(), value );
}
emit attributeChanged( eww->field().name(), value );

updateJoinedFields( *eww );

Expand Down Expand Up @@ -684,7 +682,6 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value )

updateConstraints( eww );

// emit
emit attributeChanged( eww->field().name(), value );
}

Expand Down
2 changes: 0 additions & 2 deletions src/gui/qgsattributeform.h
Expand Up @@ -400,8 +400,6 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
//! Flag to prevent refreshFeature() to change mFeature
bool mPreventFeatureRefresh;

//! Set to true while setting feature to prevent attributeChanged signal
bool mIsSettingFeature;
bool mIsSettingMultiEditFeatures;

QgsFeatureIds mMultiEditFeatureIds;
Expand Down

0 comments on commit 61b2f74

Please sign in to comment.