@@ -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
287288void 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
321320QgsFeature 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
673673void 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+ }
0 commit comments