@@ -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+
223267QTEST_MAIN ( TestQgsRelationReferenceWidget )
224268#include " testqgsrelationreferencewidget.moc"
0 commit comments