Skip to content

Commit 05dcb53

Browse files
authored
Merge pull request #5350 from pblottiere/null_218
[bugfix] Properly update filter comboboxes of relation reference widget
2 parents fe52c93 + b70d9b5 commit 05dcb53

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
310310
void QgsRelationReferenceWidget::deleteForeignKey()
311311
{
312312
QVariant nullValue = QSettings().value( "qgis/nullValue", "NULL" );
313+
314+
// deactivate filter comboboxes
315+
if ( mChainFilters && !mFilterComboBoxes.isEmpty() )
316+
{
317+
QComboBox *cb = mFilterComboBoxes.first();
318+
cb->setCurrentIndex( 0 );
319+
disableChainedComboBoxes( cb );
320+
}
321+
313322
if ( mReadOnlySelector )
314323
{
315324
QString nullText = "";
@@ -522,6 +531,13 @@ void QgsRelationReferenceWidget::init()
522531
mFilterCache[mFilterFields[i]][cf] << nf;
523532
}
524533
}
534+
535+
if ( !mFilterComboBoxes.isEmpty() )
536+
{
537+
QComboBox *cb = mFilterComboBoxes.first();
538+
cb->setCurrentIndex( 0 );
539+
disableChainedComboBoxes( cb );
540+
}
525541
}
526542
}
527543
else

tests/src/gui/testqgsrelationreferencewidget.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TestQgsRelationReferenceWidget : public QObject
3838

3939
void testChainFilter();
4040
void testChainFilterRefreshed();
41+
void testChainFilterDeleteForeignKey();
4142

4243
private:
4344
QgsVectorLayer* mLayer1;
@@ -220,5 +221,48 @@ void TestQgsRelationReferenceWidget::testChainFilterRefreshed()
220221
QCOMPARE( cbs[2]->currentText(), QString( "sleeve" ) );
221222
}
222223

224+
void TestQgsRelationReferenceWidget::testChainFilterDeleteForeignKey()
225+
{
226+
// init a relation reference widget
227+
QStringList filterFields = QStringList() << "material" << "diameter" << "raccord";
228+
229+
QgsRelationReferenceWidget w( new QWidget() );
230+
w.setChainFilters( true );
231+
w.setFilterFields( filterFields );
232+
w.setRelation( *mRelation, true );
233+
w.init();
234+
235+
// check the default status of filter comboboxes
236+
QList<QComboBox *> cbs = w.mFilterComboBoxes;
237+
238+
QCOMPARE( cbs[0]->currentText(), QString( "material" ) );
239+
QCOMPARE( cbs[0]->isEnabled(), true );
240+
241+
QCOMPARE( cbs[1]->currentText(), QString( "diameter" ) );
242+
QCOMPARE( cbs[1]->isEnabled(), false );
243+
244+
QCOMPARE( cbs[2]->currentText(), QString( "raccord" ) );
245+
QCOMPARE( cbs[2]->isEnabled(), false );
246+
247+
// set a foreign key
248+
w.setForeignKey( QVariant( 11 ) );
249+
250+
QCOMPARE( cbs[0]->currentText(), QString( "iron" ) );
251+
QCOMPARE( cbs[1]->currentText(), QString( "120" ) );
252+
QCOMPARE( cbs[2]->currentText(), QString( "sleeve" ) );
253+
254+
// delete the foreign key
255+
w.deleteForeignKey();
256+
257+
QCOMPARE( cbs[0]->currentText(), QString( "material" ) );
258+
QCOMPARE( cbs[0]->isEnabled(), true );
259+
260+
QCOMPARE( cbs[1]->currentText(), QString( "diameter" ) );
261+
QCOMPARE( cbs[1]->isEnabled(), false );
262+
263+
QCOMPARE( cbs[2]->currentText(), QString( "raccord" ) );
264+
QCOMPARE( cbs[2]->isEnabled(), false );
265+
}
266+
223267
QTEST_MAIN( TestQgsRelationReferenceWidget )
224268
#include "testqgsrelationreferencewidget.moc"

0 commit comments

Comments
 (0)