Skip to content
Permalink
Browse files

Browser proxy model: add test for showLayers

  • Loading branch information
elpaso committed Mar 11, 2020
1 parent 3439b22 commit 1bf8cfe32fb64609406c23018ba96b774afaa60e
Showing with 47 additions and 1 deletion.
  1. +1 −1 src/core/qgsbrowserproxymodel.h
  2. +46 −0 tests/src/core/testqgsbrowserproxymodel.cpp
@@ -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
@@ -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()
{
//
@@ -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.
You can’t perform that action at this time.