Skip to content

Commit 1bf8cfe

Browse files
committedMar 11, 2020
Browser proxy model: add test for showLayers
1 parent 3439b22 commit 1bf8cfe

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
 

‎src/core/qgsbrowserproxymodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class CORE_EXPORT QgsBrowserProxyModel : public QSortFilterProxyModel
203203
//! Returns TRUE if at least one ancestor is accepted by filter
204204
bool filterAcceptsAncestor( const QModelIndex &sourceIndex ) const;
205205

206-
//! Returns TRUE if at least one descendant s accepted by filter
206+
//! Returns TRUE if at least one descendant is accepted by filter
207207
bool filterAcceptsDescendant( const QModelIndex &sourceIndex ) const;
208208

209209
//! Filter accepts item name

‎tests/src/core/testqgsbrowserproxymodel.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,23 @@ class TestQgsBrowserProxyModel : public QObject
3838
void cleanup() {} // will be called after every testfunction.
3939

4040
void testModel();
41+
void testShowLayers();
4142

4243
};
4344

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+
4458
void TestQgsBrowserProxyModel::initTestCase()
4559
{
4660
//
@@ -266,5 +280,37 @@ void TestQgsBrowserProxyModel::testModel()
266280
QCOMPARE( proxy.rowCount(), 2 );
267281
}
268282

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+
269315
QGSTEST_MAIN( TestQgsBrowserProxyModel )
270316
#include "testqgsbrowserproxymodel.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.