@@ -38,9 +38,23 @@ class TestQgsBrowserProxyModel : public QObject
38
38
void cleanup () {} // will be called after every testfunction.
39
39
40
40
void testModel ();
41
+ void testShowLayers ();
41
42
42
43
};
43
44
45
+ class TestCollectionItem : public QgsDataCollectionItem
46
+ {
47
+ public:
48
+
49
+ TestCollectionItem ( QgsDataItem *parent, const QString &name, const QString &path = QString(), const QString &providerKey = QString() )
50
+ : QgsDataCollectionItem( parent, name, path, providerKey )
51
+ {
52
+ };
53
+
54
+ bool layerCollection () const override { return true ; };
55
+ };
56
+
57
+
44
58
void TestQgsBrowserProxyModel::initTestCase ()
45
59
{
46
60
//
@@ -266,5 +280,37 @@ void TestQgsBrowserProxyModel::testModel()
266
280
QCOMPARE ( proxy.rowCount (), 2 );
267
281
}
268
282
283
+ void TestQgsBrowserProxyModel::testShowLayers ()
284
+ {
285
+ QgsBrowserModel model;
286
+ QgsBrowserProxyModel proxy;
287
+ QVERIFY ( !proxy.browserModel () );
288
+ proxy.setBrowserModel ( &model );
289
+ QCOMPARE ( proxy.browserModel (), &model );
290
+
291
+ // add a root child to model
292
+ QgsDataCollectionItem *rootItem1 = new QgsDataCollectionItem ( nullptr , QStringLiteral ( " Test" ), QStringLiteral ( " root1" ) );
293
+ model.setupItemConnections ( rootItem1 );
294
+ model.beginInsertRows ( QModelIndex (), 0 , 0 );
295
+ model.mRootItems .append ( rootItem1 );
296
+ model.endInsertRows ();
297
+
298
+ // Add a layer collection item
299
+ QgsDataCollectionItem *containerItem1 = new TestCollectionItem ( nullptr , QStringLiteral ( " Test" ), QStringLiteral ( " root1" ) );
300
+ rootItem1->addChildItem ( containerItem1 );
301
+ QgsLayerItem *childItem1 = new QgsLayerItem ( nullptr , QStringLiteral ( " Child1" ), QStringLiteral ( " child1" ), QString (), QgsLayerItem::Vector, QString () );
302
+ containerItem1->addChildItem ( childItem1, true );
303
+ QCOMPARE ( proxy.rowCount (), 1 );
304
+ auto root1Index = proxy.index ( 0 , 0 );
305
+ QVERIFY ( root1Index.isValid () );
306
+ auto container1Index = proxy.index ( 0 , 0 , root1Index );
307
+ QVERIFY ( container1Index.isValid () );
308
+ QVERIFY ( proxy.hasChildren ( container1Index ) );
309
+
310
+ proxy.setShowLayers ( false );
311
+ QVERIFY ( ! proxy.hasChildren ( container1Index ) );
312
+
313
+ }
314
+
269
315
QGSTEST_MAIN ( TestQgsBrowserProxyModel )
270
316
#include " testqgsbrowserproxymodel.moc"
0 commit comments