Skip to content

Commit 61b2f74

Browse files
committedNov 9, 2017
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
1 parent dca0dc1 commit 61b2f74

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed
 

‎src/gui/qgsattributeform.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer *vl, const QgsFeature &featur
6161
, mFormNr( sFormCounter++ )
6262
, mIsSaving( false )
6363
, mPreventFeatureRefresh( false )
64-
, mIsSettingFeature( false )
6564
, mIsSettingMultiEditFeatures( false )
6665
, mUnsavedMultiEditChanges( false )
6766
, mEditCommandMessage( tr( "Attributes changed" ) )
@@ -222,7 +221,6 @@ void QgsAttributeForm::changeAttribute( const QString &field, const QVariant &va
222221

223222
void QgsAttributeForm::setFeature( const QgsFeature &feature )
224223
{
225-
mIsSettingFeature = true;
226224
mFeature = feature;
227225

228226
switch ( mMode )
@@ -247,7 +245,6 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature )
247245
break;
248246
}
249247
}
250-
mIsSettingFeature = false;
251248
}
252249

253250
bool QgsAttributeForm::saveEdits()
@@ -641,19 +638,20 @@ QString QgsAttributeForm::createFilterExpression() const
641638
void QgsAttributeForm::onAttributeChanged( const QVariant &value )
642639
{
643640
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( sender() );
644-
645641
Q_ASSERT( eww );
646642

643+
const QVariant oldValue = mFeature.attribute( eww->fieldIdx() );
644+
645+
// Safetey check, if we receive the same value again, no reason to do anything
646+
if ( oldValue == value && oldValue.isNull() == value.isNull() )
647+
return;
648+
647649
switch ( mMode )
648650
{
649651
case SingleEditMode:
650652
case AddFeatureMode:
651653
{
652-
// don't emit signal if it was triggered by a feature change
653-
if ( !mIsSettingFeature )
654-
{
655-
emit attributeChanged( eww->field().name(), value );
656-
}
654+
emit attributeChanged( eww->field().name(), value );
657655

658656
updateJoinedFields( *eww );
659657

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

685683
updateConstraints( eww );
686684

687-
// emit
688685
emit attributeChanged( eww->field().name(), value );
689686
}
690687

‎src/gui/qgsattributeform.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,6 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
400400
//! Flag to prevent refreshFeature() to change mFeature
401401
bool mPreventFeatureRefresh;
402402

403-
//! Set to true while setting feature to prevent attributeChanged signal
404-
bool mIsSettingFeature;
405403
bool mIsSettingMultiEditFeatures;
406404

407405
QgsFeatureIds mMultiEditFeatureIds;

0 commit comments

Comments
 (0)
Please sign in to comment.