Skip to content

Commit

Permalink
Add comment, tweak test to deal with post feature gathering events
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 4, 2024
1 parent 33062f0 commit 32a063f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ void QgsRelationReferenceWidget::init()

// Only connect after iterating, to have only one iterator on the referenced table at once
connect( mComboBox, &QgsFeatureListComboBox::currentFeatureChanged, this, &QgsRelationReferenceWidget::comboReferenceChanged );
// To avoid wrongly signaling a foreign key change, handle model feature found state following feature gathering separately
connect( mComboBox, &QgsFeatureListComboBox::currentFeatureFoundChanged, this, &QgsRelationReferenceWidget::comboReferenceFoundChanged );

QApplication::restoreOverrideCursor();
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsfeaturelistcombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ QgsFeatureListComboBox::QgsFeatureListComboBox( QWidget *parent )
connect( mLineEdit, &QgsFilterLineEdit::cleared, this, &QgsFeatureListComboBox::onFilterLineEditCleared );

connect( mModel, &QgsFeatureFilterModel::currentFeatureChanged, this, &QgsFeatureListComboBox::currentFeatureChanged );
// To avoid wrongly signaling a foreign key change, handle model feature found state following feature gathering separately
connect( mModel, &QgsFeatureFilterModel::extraValueDoesNotExistChanged, this, &QgsFeatureListComboBox::currentFeatureFoundChanged );

setToolTip( tr( "Just start typing what you are looking for." ) );
Expand Down
47 changes: 37 additions & 10 deletions tests/src/gui/testqgsrelationreferencewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,30 +517,57 @@ void TestQgsRelationReferenceWidget::testSetGetForeignKey()
{
QWidget parentWidget;
QgsRelationReferenceWidget w( &parentWidget );

w.setRelation( *mRelation, true );
w.init();

QSignalSpy spy( &w, &QgsRelationReferenceWidget::foreignKeysChanged );
QEventLoop loop;

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

w.setForeignKeys( QVariantList() << 11 );
QCOMPARE( w.foreignKeys().at( 0 ), QVariant( 11 ) );
QCOMPARE( w.mComboBox->currentText(), QStringLiteral( "(11)" ) );
QCOMPARE( spy.count(), 2 );
QTimer::singleShot( 1000, &loop, &QEventLoop::quit );
loop.exec();

QVERIFY( w.foreignKeys().at( 0 ).isNull() );
QVERIFY( w.foreignKeys().at( 0 ).isValid() );
QCOMPARE( spy.count(), 1 );

w.setForeignKeys( QVariantList() << 12 );

QTimer::singleShot( 1000, &loop, &QEventLoop::quit );
loop.exec();

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

w.setForeignKeys( QVariantList() << 11 );

QTimer::singleShot( 1000, &loop, &QEventLoop::quit );
loop.exec();

QCOMPARE( w.foreignKeys().at( 0 ), QVariant( 11 ) );
QCOMPARE( w.mComboBox->currentText(), QStringLiteral( "11" ) );
QCOMPARE( spy.count(), 3 );

w.setForeignKeys( QVariantList() << 0 );

QTimer::singleShot( 1000, &loop, &QEventLoop::quit );
loop.exec();

QCOMPARE( w.foreignKeys().at( 0 ), QVariant( 0 ) );
QCOMPARE( w.mComboBox->currentText(), QStringLiteral( "(0)" ) );
QCOMPARE( spy.count(), 4 );

w.setForeignKeys( QVariantList() << QVariant() );

QTimer::singleShot( 1000, &loop, &QEventLoop::quit );
loop.exec();

QVERIFY( w.foreignKeys().at( 0 ).isNull() );
QVERIFY( w.foreignKeys().at( 0 ).isValid() );
QCOMPARE( spy.count(), 4 );
QCOMPARE( spy.count(), 5 );
}

// Test issue https://github.com/qgis/QGIS/issues/29884
Expand Down

0 comments on commit 32a063f

Please sign in to comment.