Skip to content

Commit

Permalink
Merge pull request #5879 from pblottiere/refrelfilter_218
Browse files Browse the repository at this point in the history
[bugfix]  Fixes auto select foreign key when filters are updated in QgsRelationReferenceWidget
  • Loading branch information
pblottiere committed Dec 18, 2017
2 parents 3277853 + 9b2320a commit d814324
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -941,6 +941,18 @@ void QgsRelationReferenceWidget::filterChanged()
}

mFilterModel->setFilteredFeatures( featureIds );

if ( mChainFilters && mComboBox->count() > 0 )
{
if ( scb->currentIndex() == 0 )
{
mComboBox->setCurrentIndex( 0 );
}
else if ( mComboBox->count() > 1 )
{
mComboBox->setCurrentIndex( 1 );
}
}
}

void QgsRelationReferenceWidget::addEntry()
Expand Down
12 changes: 12 additions & 0 deletions tests/src/gui/testqgsrelationreferencewidget.cpp
Expand Up @@ -174,8 +174,20 @@ void TestQgsRelationReferenceWidget::testChainFilter()

// set the filter for "raccord" and then reset filter for "diameter". As
// chain filter is activated, the filter on "raccord" field should be reset
cbs[0]->setCurrentIndex( 0 );
QCOMPARE( w.mComboBox->currentIndex(), 0 );

cbs[0]->setCurrentIndex( cbs[0]->findText( "iron" ) );
QCOMPARE( w.mComboBox->currentIndex(), 1 );

cbs[1]->setCurrentIndex( cbs[1]->findText( "120" ) );
QCOMPARE( w.mComboBox->currentIndex(), 1 );

cbs[2]->setCurrentIndex( cbs[2]->findText( "brides" ) );
QCOMPARE( w.mComboBox->currentIndex(), 1 );

cbs[1]->setCurrentIndex( cbs[1]->findText( "diameter" ) );
QCOMPARE( w.mComboBox->currentIndex(), 0 );

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

0 comments on commit d814324

Please sign in to comment.