Skip to content

Commit

Permalink
[Backport release-3_10] fix edge case where fkey is 0 in relation ref…
Browse files Browse the repository at this point in the history
…erence widget (#39015)

* fix edge case where fkey is 0 in relation reference widget

* Update qgsfeaturefiltermodel.cpp

* Delete qgsfeaturepickermodelbase.cpp

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Denis Rouzaud <denis.rouzaud@gmail.com>
  • Loading branch information
3 people committed Sep 25, 2020
1 parent 821c5fe commit 9de7be1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -576,7 +576,7 @@ void QgsRelationReferenceWidget::init()
}

// Only connect after iterating, to have only one iterator on the referenced table at once
connect( mComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRelationReferenceWidget::comboReferenceChanged );
connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsRelationReferenceWidget::comboReferenceChanged );

QApplication::restoreOverrideCursor();

Expand Down Expand Up @@ -1041,7 +1041,7 @@ void QgsRelationReferenceWidget::disableChainedComboBoxes( const QComboBox *scb

void QgsRelationReferenceWidget::emitForeignKeysChanged( const QVariantList &foreignKeys, bool force )
{
if ( foreignKeys == mForeignKeys && force == false )
if ( foreignKeys == mForeignKeys && force == false && qVariantListIsNull( foreignKeys ) == qVariantListIsNull( mForeignKeys ) )
return;

mForeignKeys = foreignKeys;
Expand Down
13 changes: 9 additions & 4 deletions tests/src/gui/testqgsrelationreferencewidget.cpp
Expand Up @@ -499,22 +499,27 @@ void TestQgsRelationReferenceWidget::testSetGetForeignKey()
w.setRelation( *mRelation, true );
w.init();

QSignalSpy spy( &w, SIGNAL( foreignKeyChanged( QVariant ) ) );
QSignalSpy spy( &w, &QgsRelationReferenceWidget::foreignKeysChanged );

w.setForeignKeys( QVariantList() << 0 );
QCOMPARE( w.foreignKeys().at( 0 ), QVariant( 0 ) );
QCOMPARE( w.mComboBox->currentText(), QStringLiteral( "(0)" ) );
QCOMPARE( spy.count(), 1 );

w.setForeignKeys( QVariantList() << 11 );
QCOMPARE( w.foreignKeys().at( 0 ), QVariant( 11 ) );
QCOMPARE( w.mComboBox->currentText(), QStringLiteral( "(11)" ) );
QCOMPARE( spy.count(), 1 );
QCOMPARE( spy.count(), 2 );

w.setForeignKeys( QVariantList() << 12 );
QCOMPARE( w.foreignKeys().at( 0 ), QVariant( 12 ) );
QCOMPARE( w.mComboBox->currentText(), QStringLiteral( "(12)" ) );
QCOMPARE( spy.count(), 2 );
QCOMPARE( spy.count(), 3 );

w.setForeignKeys( QVariantList() << QVariant() );
QVERIFY( w.foreignKeys().at( 0 ).isNull() );
QVERIFY( w.foreignKeys().at( 0 ).isValid() );
QCOMPARE( spy.count(), 3 );
QCOMPARE( spy.count(), 4 );
}


Expand Down

0 comments on commit 9de7be1

Please sign in to comment.