@@ -40,6 +40,7 @@ class TestQgsRelationReferenceWidget : public QObject
40
40
41
41
void testChainFilter ();
42
42
void testChainFilterRefreshed ();
43
+ void testChainFilterDeleteForeignKey ();
43
44
44
45
private:
45
46
std::unique_ptr<QgsVectorLayer> mLayer1 ;
@@ -222,5 +223,48 @@ void TestQgsRelationReferenceWidget::testChainFilterRefreshed()
222
223
QCOMPARE ( cbs[2 ]->currentText (), QString ( " sleeve" ) );
223
224
}
224
225
226
+ void TestQgsRelationReferenceWidget::testChainFilterDeleteForeignKey ()
227
+ {
228
+ // init a relation reference widget
229
+ QStringList filterFields = { " material" , " diameter" , " raccord" };
230
+
231
+ QgsRelationReferenceWidget w ( new QWidget () );
232
+ w.setChainFilters ( true );
233
+ w.setFilterFields ( filterFields );
234
+ w.setRelation ( *mRelation , true );
235
+ w.init ();
236
+
237
+ // check the default status of filter comboboxes
238
+ QList<QComboBox *> cbs = w.mFilterComboBoxes ;
239
+
240
+ QCOMPARE ( cbs[0 ]->currentText (), QString ( " material" ) );
241
+ QCOMPARE ( cbs[0 ]->isEnabled (), true );
242
+
243
+ QCOMPARE ( cbs[1 ]->currentText (), QString ( " diameter" ) );
244
+ QCOMPARE ( cbs[1 ]->isEnabled (), false );
245
+
246
+ QCOMPARE ( cbs[2 ]->currentText (), QString ( " raccord" ) );
247
+ QCOMPARE ( cbs[2 ]->isEnabled (), false );
248
+
249
+ // set a foreign key
250
+ w.setForeignKey ( QVariant ( 11 ) );
251
+
252
+ QCOMPARE ( cbs[0 ]->currentText (), QString ( " iron" ) );
253
+ QCOMPARE ( cbs[1 ]->currentText (), QString ( " 120" ) );
254
+ QCOMPARE ( cbs[2 ]->currentText (), QString ( " sleeve" ) );
255
+
256
+ // delete the foreign key
257
+ w.deleteForeignKey ();
258
+
259
+ QCOMPARE ( cbs[0 ]->currentText (), QString ( " material" ) );
260
+ QCOMPARE ( cbs[0 ]->isEnabled (), true );
261
+
262
+ QCOMPARE ( cbs[1 ]->currentText (), QString ( " diameter" ) );
263
+ QCOMPARE ( cbs[1 ]->isEnabled (), false );
264
+
265
+ QCOMPARE ( cbs[2 ]->currentText (), QString ( " raccord" ) );
266
+ QCOMPARE ( cbs[2 ]->isEnabled (), false );
267
+ }
268
+
225
269
QGSTEST_MAIN ( TestQgsRelationReferenceWidget )
226
270
#include " testqgsrelationreferencewidget.moc"
0 commit comments