Skip to content

Commit 3c07dd0

Browse files
committedNov 3, 2012
do not populate items in rowCount(), use canFetchMore() and fetchMore() instead
1 parent 3a6c904 commit 3c07dd0

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed
 

‎src/core/qgsbrowsermodel.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,19 @@ QgsDataItem *QgsBrowserModel::dataItem( const QModelIndex &idx ) const
399399
Q_ASSERT( !v || d );
400400
return d;
401401
}
402+
403+
bool QgsBrowserModel::canFetchMore( const QModelIndex & parent ) const
404+
{
405+
QgsDataItem* item = dataItem( parent );
406+
// if ( item )
407+
// QgsDebugMsg( QString( "path = %1 canFetchMore = %2" ).arg( item->path() ).arg( item && ! item->isPopulated() ) );
408+
return ( item && ! item->isPopulated() );
409+
}
410+
411+
void QgsBrowserModel::fetchMore( const QModelIndex & parent )
412+
{
413+
QgsDataItem* item = dataItem( parent );
414+
if ( item )
415+
item->populate();
416+
QgsDebugMsg( "path = " + item->path() );
417+
}

‎src/core/qgsbrowsermodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
8989

9090
void connectItem( QgsDataItem *item );
9191

92+
bool canFetchMore( const QModelIndex & parent ) const;
93+
void fetchMore( const QModelIndex & parent );
94+
9295
public slots:
96+
9397
void beginInsertItems( QgsDataItem *parent, int first, int last );
9498
void endInsertItems();
9599
void beginRemoveItems( QgsDataItem *parent, int first, int last );

‎src/core/qgsdataitem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ void QgsDataItem::populate()
203203

204204
int QgsDataItem::rowCount()
205205
{
206-
if ( !mPopulated )
207-
populate();
206+
// if ( !mPopulated )
207+
// populate();
208208
return mChildren.size();
209209
}
210210
bool QgsDataItem::hasChildren()

‎src/core/qgsdataitem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class CORE_EXPORT QgsDataItem : public QObject
6767

6868
// Populate children using children vector created by createChildren()
6969
virtual void populate();
70+
bool isPopulated() { return mPopulated; }
7071

7172
// Insert new child using alphabetical order based on mName, emits necessary signal to model before and after, sets parent and connects signals
7273
// refresh - refresh populated item, emit signals to model

0 commit comments

Comments
 (0)
Please sign in to comment.