Skip to content
Permalink
Browse files

do not populate items in rowCount(), use canFetchMore() and fetchMore…

…() instead
  • Loading branch information
etiennesky committed Nov 3, 2012
1 parent 3a6c904 commit 3c07dd02e1fa64713d9510faa6a4aa013a3c83c1
Showing with 23 additions and 2 deletions.
  1. +16 −0 src/core/qgsbrowsermodel.cpp
  2. +4 −0 src/core/qgsbrowsermodel.h
  3. +2 −2 src/core/qgsdataitem.cpp
  4. +1 −0 src/core/qgsdataitem.h
@@ -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() );
}
@@ -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 );
@@ -203,8 +203,8 @@ void QgsDataItem::populate()

int QgsDataItem::rowCount()
{
if ( !mPopulated )
populate();
// if ( !mPopulated )
// populate();
return mChildren.size();
}
bool QgsDataItem::hasChildren()
@@ -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

0 comments on commit 3c07dd0

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