Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
do not populate items in rowCount(), use canFetchMore() and fetchMore…
…() instead
  • Loading branch information
etiennesky committed Nov 3, 2012
1 parent 3a6c904 commit 3c07dd0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/core/qgsbrowsermodel.cpp
Expand Up @@ -399,3 +399,19 @@ QgsDataItem *QgsBrowserModel::dataItem( const QModelIndex &idx ) const
Q_ASSERT( !v || d );
return d;
}

bool QgsBrowserModel::canFetchMore( const QModelIndex & parent ) const
{
QgsDataItem* item = dataItem( parent );
// if ( item )
// QgsDebugMsg( QString( "path = %1 canFetchMore = %2" ).arg( item->path() ).arg( item && ! item->isPopulated() ) );
return ( item && ! item->isPopulated() );
}

void QgsBrowserModel::fetchMore( const QModelIndex & parent )
{
QgsDataItem* item = dataItem( parent );
if ( item )
item->populate();
QgsDebugMsg( "path = " + item->path() );
}
4 changes: 4 additions & 0 deletions src/core/qgsbrowsermodel.h
Expand Up @@ -89,7 +89,11 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel

void connectItem( QgsDataItem *item );

bool canFetchMore( const QModelIndex & parent ) const;
void fetchMore( const QModelIndex & parent );

public slots:

void beginInsertItems( QgsDataItem *parent, int first, int last );
void endInsertItems();
void beginRemoveItems( QgsDataItem *parent, int first, int last );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsdataitem.cpp
Expand Up @@ -203,8 +203,8 @@ void QgsDataItem::populate()

int QgsDataItem::rowCount()
{
if ( !mPopulated )
populate();
// if ( !mPopulated )
// populate();
return mChildren.size();
}
bool QgsDataItem::hasChildren()
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsdataitem.h
Expand Up @@ -67,6 +67,7 @@ class CORE_EXPORT QgsDataItem : public QObject

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

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

0 comments on commit 3c07dd0

Please sign in to comment.