Skip to content

Commit

Permalink
Browser proxy model: add test for showLayers
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Mar 11, 2020
1 parent 3439b22 commit 1bf8cfe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgsbrowserproxymodel.h
Expand Up @@ -203,7 +203,7 @@ class CORE_EXPORT QgsBrowserProxyModel : public QSortFilterProxyModel
//! Returns TRUE if at least one ancestor is accepted by filter
bool filterAcceptsAncestor( const QModelIndex &sourceIndex ) const;

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

//! Filter accepts item name
Expand Down
46 changes: 46 additions & 0 deletions tests/src/core/testqgsbrowserproxymodel.cpp
Expand Up @@ -38,9 +38,23 @@ class TestQgsBrowserProxyModel : public QObject
void cleanup() {} // will be called after every testfunction.

void testModel();
void testShowLayers();

};

class TestCollectionItem: public QgsDataCollectionItem
{
public:

TestCollectionItem( QgsDataItem *parent, const QString &name, const QString &path = QString(), const QString &providerKey = QString() )
: QgsDataCollectionItem( parent, name, path, providerKey )
{
};

bool layerCollection() const override { return true; };
};


void TestQgsBrowserProxyModel::initTestCase()
{
//
Expand Down Expand Up @@ -266,5 +280,37 @@ void TestQgsBrowserProxyModel::testModel()
QCOMPARE( proxy.rowCount(), 2 );
}

void TestQgsBrowserProxyModel::testShowLayers()
{
QgsBrowserModel model;
QgsBrowserProxyModel proxy;
QVERIFY( !proxy.browserModel() );
proxy.setBrowserModel( &model );
QCOMPARE( proxy.browserModel(), &model );

// add a root child to model
QgsDataCollectionItem *rootItem1 = new QgsDataCollectionItem( nullptr, QStringLiteral( "Test" ), QStringLiteral( "root1" ) );
model.setupItemConnections( rootItem1 );
model.beginInsertRows( QModelIndex(), 0, 0 );
model.mRootItems.append( rootItem1 );
model.endInsertRows();

// Add a layer collection item
QgsDataCollectionItem *containerItem1 = new TestCollectionItem( nullptr, QStringLiteral( "Test" ), QStringLiteral( "root1" ) );
rootItem1->addChildItem( containerItem1 );
QgsLayerItem *childItem1 = new QgsLayerItem( nullptr, QStringLiteral( "Child1" ), QStringLiteral( "child1" ), QString(), QgsLayerItem::Vector, QString() );
containerItem1->addChildItem( childItem1, true );
QCOMPARE( proxy.rowCount(), 1 );
auto root1Index = proxy.index( 0, 0 );
QVERIFY( root1Index.isValid() );
auto container1Index = proxy.index( 0, 0, root1Index );
QVERIFY( container1Index.isValid() );
QVERIFY( proxy.hasChildren( container1Index ) );

proxy.setShowLayers( false );
QVERIFY( ! proxy.hasChildren( container1Index ) );

}

QGSTEST_MAIN( TestQgsBrowserProxyModel )
#include "testqgsbrowserproxymodel.moc"

0 comments on commit 1bf8cfe

Please sign in to comment.