Skip to content

Commit 561d255

Browse files
committed
Relation reference widget, only send valueChanged signal once
1 parent da93520 commit 561d255

4 files changed

Lines changed: 31 additions & 12 deletions

File tree

‎src/core/qgsfeaturefiltermodel.cpp‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ QSet<QString> QgsFeatureFilterModel::requestedAttributes() const
394394
return requestedAttrs;
395395
}
396396

397-
void QgsFeatureFilterModel::setExtraIdentifierValueIndex( int index )
397+
void QgsFeatureFilterModel::setExtraIdentifierValueIndex( int index, bool force )
398398
{
399-
if ( mExtraIdentifierValueIndex == index )
399+
if ( mExtraIdentifierValueIndex == index && !force )
400400
return;
401401

402402
mExtraIdentifierValueIndex = index;
@@ -437,7 +437,7 @@ void QgsFeatureFilterModel::setExtraIdentifierValueUnguarded( const QVariant &ex
437437
mEntries.prepend( Entry( extraIdentifierValue, QStringLiteral( "(%1)" ).arg( extraIdentifierValue.toString() ), QgsFeature() ) );
438438
endInsertRows();
439439

440-
setExtraIdentifierValueIndex( 0 );
440+
setExtraIdentifierValueIndex( 0, true );
441441

442442
reloadCurrentFeature();
443443
}
@@ -535,8 +535,16 @@ void QgsFeatureFilterModel::setExtraIdentifierValue( const QVariant &extraIdenti
535535
if ( extraIdentifierValue == mExtraIdentifierValue && extraIdentifierValue.isNull() == mExtraIdentifierValue.isNull() && mExtraIdentifierValue.isValid() )
536536
return;
537537

538-
setExtraIdentifierValueUnguarded( extraIdentifierValue );
538+
if ( mIsSettingExtraIdentifierValue )
539+
return;
540+
541+
mIsSettingExtraIdentifierValue = true;
539542

540543
mExtraIdentifierValue = extraIdentifierValue;
544+
545+
setExtraIdentifierValueUnguarded( extraIdentifierValue );
546+
547+
mIsSettingExtraIdentifierValue = false;
548+
541549
emit extraIdentifierValueChanged();
542550
}

‎src/core/qgsfeaturefiltermodel.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class CORE_EXPORT QgsFeatureFilterModel : public QAbstractItemModel
261261

262262
private:
263263
QSet<QString> requestedAttributes() const;
264-
void setExtraIdentifierValueIndex( int index );
264+
void setExtraIdentifierValueIndex( int index, bool force = false );
265265
void setExtraValueDoesNotExist( bool extraValueDoesNotExist );
266266
void reload();
267267
void reloadCurrentFeature();
@@ -298,6 +298,7 @@ class CORE_EXPORT QgsFeatureFilterModel : public QAbstractItemModel
298298
bool mShouldReloadCurrentFeature = false;
299299
bool mExtraValueDoesNotExist = false;
300300
bool mAllowNull = false;
301+
bool mIsSettingExtraIdentifierValue = false;
301302

302303
QString mIdentifierField;
303304

‎src/gui/editorwidgets/qgsrelationreferencewidget.cpp‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant &value )
281281
mRemoveFKButton->setEnabled( mIsEditable );
282282
highlightFeature( mFeature ); // TODO : make this async
283283
updateAttributeEditorFrame( mFeature );
284-
emit foreignKeyChanged( foreignKey() );
284+
285+
emitForeignKeyChanged( foreignKey() );
285286
}
286287

287288
void QgsRelationReferenceWidget::deleteForeignKey()
@@ -304,18 +305,16 @@ void QgsRelationReferenceWidget::deleteForeignKey()
304305
nullText = tr( "%1 (no selection)" ).arg( nullValue );
305306
}
306307
mLineEdit->setText( nullText );
307-
mForeignKey = QVariant();
308+
mForeignKey = QVariant( QVariant::Int );
308309
mFeature.setValid( false );
309310
}
310311
else
311312
{
312-
mComboBox->setIdentifierValue( QVariant() );
313-
314-
313+
mComboBox->setIdentifierValue( QVariant( QVariant::Int ) );
315314
}
316315
mRemoveFKButton->setEnabled( false );
317316
updateAttributeEditorFrame( QgsFeature() );
318-
emit foreignKeyChanged( QVariant( QVariant::Int ) );
317+
emitForeignKeyChanged( QVariant( QVariant::Int ) );
319318
}
320319

321320
QgsFeature QgsRelationReferenceWidget::referencedFeature() const
@@ -667,7 +666,8 @@ void QgsRelationReferenceWidget::comboReferenceChanged( int index )
667666
mReferencedLayer->getFeatures( mComboBox->currentFeatureRequest() ).nextFeature( mFeature );
668667
highlightFeature( mFeature );
669668
updateAttributeEditorFrame( mFeature );
670-
emit foreignKeyChanged( mFeature.attribute( mReferencedFieldIdx ) );
669+
670+
emitForeignKeyChanged( mComboBox->identifierValue() );
671671
}
672672

673673
void QgsRelationReferenceWidget::updateAttributeEditorFrame( const QgsFeature &feature )
@@ -900,3 +900,12 @@ void QgsRelationReferenceWidget::disableChainedComboBoxes( const QComboBox *scb
900900
ccb = cb;
901901
}
902902
}
903+
904+
void QgsRelationReferenceWidget::emitForeignKeyChanged( const QVariant &foreignKey )
905+
{
906+
if ( foreignKey != mForeignKey || foreignKey.isNull() != mForeignKey.isNull() )
907+
{
908+
mForeignKey = foreignKey;
909+
emit foreignKeyChanged( foreignKey );
910+
}
911+
}

‎src/gui/editorwidgets/qgsrelationreferencewidget.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
188188
void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
189189
void updateAttributeEditorFrame( const QgsFeature &feature );
190190
void disableChainedComboBoxes( const QComboBox *cb );
191+
void emitForeignKeyChanged( const QVariant &foreignKey );
191192

192193
// initialized
193194
QgsAttributeEditorContext mEditorContext;

0 commit comments

Comments
 (0)