@@ -46,6 +46,7 @@ class TestQgsRelationReferenceWidget : public QObject
46
46
void testChainFilterRefreshed ();
47
47
void testChainFilterDeleteForeignKey ();
48
48
void testInvalidRelation ();
49
+ void testSetGetForeignKey ();
49
50
50
51
private:
51
52
std::unique_ptr<QgsVectorLayer> mLayer1 ;
@@ -129,14 +130,17 @@ void TestQgsRelationReferenceWidget::init()
129
130
130
131
void TestQgsRelationReferenceWidget::cleanup ()
131
132
{
133
+ QgsProject::instance ()->removeMapLayer ( mLayer1 .get () );
134
+ QgsProject::instance ()->removeMapLayer ( mLayer2 .get () );
132
135
}
133
136
134
137
void TestQgsRelationReferenceWidget::testChainFilter ()
135
138
{
136
139
// init a relation reference widget
137
140
QStringList filterFields = { " material" , " diameter" , " raccord" };
138
141
139
- QgsRelationReferenceWidget w ( new QWidget () );
142
+ QWidget parentWidget;
143
+ QgsRelationReferenceWidget w ( &parentWidget );
140
144
w.setChainFilters ( true );
141
145
w.setFilterFields ( filterFields );
142
146
w.setRelation ( *mRelation , true );
@@ -287,5 +291,22 @@ void TestQgsRelationReferenceWidget::testInvalidRelation()
287
291
ww.initWidget ( nullptr );
288
292
}
289
293
294
+ void TestQgsRelationReferenceWidget::testSetGetForeignKey ()
295
+ {
296
+ QWidget parentWidget;
297
+ QgsRelationReferenceWidget w ( &parentWidget );
298
+ w.setRelation ( *mRelation , true );
299
+ w.init ();
300
+
301
+ w.setForeignKey ( 11 );
302
+ QCOMPARE ( w.foreignKey (), QVariant ( 11 ) );
303
+
304
+ w.setForeignKey ( 12 );
305
+ QCOMPARE ( w.foreignKey (), QVariant ( 12 ) );
306
+
307
+ w.setForeignKey ( QVariant ( QVariant::Int ) );
308
+ Q_ASSERT ( w.foreignKey ().isNull () );
309
+ }
310
+
290
311
QGSTEST_MAIN ( TestQgsRelationReferenceWidget )
291
312
#include " testqgsrelationreferencewidget.moc"
0 commit comments