Skip to content
Permalink
Browse files

Dox, tests

  • Loading branch information
nyalldawson committed Oct 18, 2018
1 parent 67f1e10 commit 765dbf6ae76fc473419e2f14900d08015a61e4b6
@@ -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
@@ -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
@@ -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
@@ -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 );

@@ -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" ) );
@@ -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" ) );
@@ -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() );


}

0 comments on commit 765dbf6

Please sign in to comment.
You can’t perform that action at this time.