Skip to content
Permalink
Browse files

Do not assume edit widget value changes on every signal

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 8, 2017
1 parent dca0dc1 commit 61b2f74aae077d07e14b8d9619a4fa7f91514e5f
Showing with 7 additions and 12 deletions.
  1. +7 −10 src/gui/qgsattributeform.cpp
  2. +0 −2 src/gui/qgsattributeform.h
@@ -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" ) )
@@ -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 )
@@ -247,7 +245,6 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature )
break;
}
}
mIsSettingFeature = false;
}

bool QgsAttributeForm::saveEdits()
@@ -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 );

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

updateConstraints( eww );

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

@@ -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;

0 comments on commit 61b2f74

Please sign in to comment.
You can’t perform that action at this time.