Skip to content

Commit

Permalink
Dox, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 18, 2018
1 parent 67f1e10 commit 765dbf6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/core/auto_generated/qgsbrowsermodel.sip.in
Expand Up @@ -79,8 +79,20 @@ Constructor for QgsBrowserModel, with the specified ``parent`` object.


QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = 0 ) const;
%Docstring
Returns the model index corresponding to the specified data ``item``.
If the item was not found, an invalid QModelIndex is returned.

If the ``parent`` item is argument is specified, then only items which are children
of ``parent`` are searched. If no ``parent`` is specified, then all items within
the model are searched.
%End

QgsDataItem *dataItem( const QModelIndex &idx ) const;
%Docstring
Returns the data item at the specified index, or a None if no item
exists at the index.
%End

void refresh( const QString &path );
%Docstring
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsbrowsermodel.h
Expand Up @@ -102,8 +102,20 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
bool canFetchMore( const QModelIndex &parent ) const override;
void fetchMore( const QModelIndex &parent ) override;

/**
* Returns the model index corresponding to the specified data \a item.
* If the item was not found, an invalid QModelIndex is returned.
*
* If the \a parent item is argument is specified, then only items which are children
* of \a parent are searched. If no \a parent is specified, then all items within
* the model are searched.
*/
QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = nullptr ) const;

/**
* Returns the data item at the specified index, or a nullptr if no item
* exists at the index.
*/
QgsDataItem *dataItem( const QModelIndex &idx ) const;

//! Refresh item specified by path
Expand Down Expand Up @@ -205,6 +217,9 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
QMap< QString, QgsDataItem * > mDriveItems;

void removeRootItem( QgsDataItem *item );

friend class TestQgsBrowserModel;
friend class TestQgsBrowserProxyModel;
};

#endif // QGSBROWSERMODEL_H
8 changes: 8 additions & 0 deletions tests/src/core/testqgsbrowsermodel.cpp
Expand Up @@ -75,6 +75,7 @@ void TestQgsBrowserModel::testModel()

// add a root child
QgsDataCollectionItem *rootItem1 = new QgsDataCollectionItem( nullptr, QStringLiteral( "Test" ), QStringLiteral( "root1" ) );
QVERIFY( !model.findItem( rootItem1 ).isValid() );
model.connectItem( rootItem1 );
model.mRootItems.append( rootItem1 );

Expand All @@ -94,6 +95,7 @@ void TestQgsBrowserModel::testModel()
QCOMPARE( model.data( root1Index ).toString(), QStringLiteral( "Test" ) );
QCOMPARE( model.data( root1Index, QgsBrowserModel::PathRole ).toString(), QStringLiteral( "root1" ) );
QCOMPARE( model.dataItem( root1Index ), rootItem1 );
QCOMPARE( model.findItem( rootItem1 ), root1Index );

// second root item
QgsDataCollectionItem *rootItem2 = new QgsDataCollectionItem( nullptr, QStringLiteral( "Test2" ), QStringLiteral( "root2" ) );
Expand All @@ -109,6 +111,7 @@ void TestQgsBrowserModel::testModel()
QCOMPARE( model.data( root2Index ).toString(), QStringLiteral( "Test2" ) );
QCOMPARE( model.data( root2Index, QgsBrowserModel::PathRole ).toString(), QStringLiteral( "root2" ) );
QCOMPARE( model.dataItem( root2Index ), rootItem2 );
QCOMPARE( model.findItem( rootItem2 ), root2Index );

// child item
QgsDataCollectionItem *childItem1 = new QgsDataCollectionItem( nullptr, QStringLiteral( "Child1" ), QStringLiteral( "child1" ) );
Expand All @@ -124,6 +127,11 @@ void TestQgsBrowserModel::testModel()
QCOMPARE( model.data( child1Index ).toString(), QStringLiteral( "Child1" ) );
QCOMPARE( model.data( child1Index, QgsBrowserModel::PathRole ).toString(), QStringLiteral( "child1" ) );
QCOMPARE( model.dataItem( child1Index ), childItem1 );
QCOMPARE( model.findItem( childItem1 ), child1Index );
QCOMPARE( model.findItem( childItem1, rootItem1 ), child1Index );
// search for child in wrong parent
QVERIFY( !model.findItem( childItem1, rootItem2 ).isValid() );


}

Expand Down

0 comments on commit 765dbf6

Please sign in to comment.