Skip to content

Commit d814324

Browse files
authored
Merge pull request #5879 from pblottiere/refrelfilter_218
[bugfix] Fixes auto select foreign key when filters are updated in QgsRelationReferenceWidget
2 parents 3277853 + 9b2320a commit d814324

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,18 @@ void QgsRelationReferenceWidget::filterChanged()
941941
}
942942

943943
mFilterModel->setFilteredFeatures( featureIds );
944+
945+
if ( mChainFilters && mComboBox->count() > 0 )
946+
{
947+
if ( scb->currentIndex() == 0 )
948+
{
949+
mComboBox->setCurrentIndex( 0 );
950+
}
951+
else if ( mComboBox->count() > 1 )
952+
{
953+
mComboBox->setCurrentIndex( 1 );
954+
}
955+
}
944956
}
945957

946958
void QgsRelationReferenceWidget::addEntry()

tests/src/gui/testqgsrelationreferencewidget.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,20 @@ void TestQgsRelationReferenceWidget::testChainFilter()
174174

175175
// set the filter for "raccord" and then reset filter for "diameter". As
176176
// chain filter is activated, the filter on "raccord" field should be reset
177+
cbs[0]->setCurrentIndex( 0 );
178+
QCOMPARE( w.mComboBox->currentIndex(), 0 );
179+
180+
cbs[0]->setCurrentIndex( cbs[0]->findText( "iron" ) );
181+
QCOMPARE( w.mComboBox->currentIndex(), 1 );
182+
183+
cbs[1]->setCurrentIndex( cbs[1]->findText( "120" ) );
184+
QCOMPARE( w.mComboBox->currentIndex(), 1 );
185+
177186
cbs[2]->setCurrentIndex( cbs[2]->findText( "brides" ) );
187+
QCOMPARE( w.mComboBox->currentIndex(), 1 );
188+
178189
cbs[1]->setCurrentIndex( cbs[1]->findText( "diameter" ) );
190+
QCOMPARE( w.mComboBox->currentIndex(), 0 );
179191

180192
// combobox should propose NULL, 10 and 11 because the filter is now:
181193
// "material" == 'iron'

0 commit comments

Comments
 (0)