From b5648af02ea7246b41d24e242c5f94e43e43980e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Nov 2015 11:09:31 +0100 Subject: Provide status information about children fetch state The fetch state is per parent. --- common/modelresult.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'common/modelresult.cpp') diff --git a/common/modelresult.cpp b/common/modelresult.cpp index 582f8ff..4def20f 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp @@ -74,6 +74,9 @@ QVariant ModelResult::data(const QModelIndex &index, int role) const Q_ASSERT(mEntities.contains(index.internalId())); return QVariant::fromValue(mEntities.value(index.internalId())); } + if (role == ChildrenFetchedRole) { + return childrenFetched(index); + } if (role == Qt::DisplayRole) { if (index.column() < mPropertyColumns.size()) { Q_ASSERT(mEntities.contains(index.internalId())); @@ -122,8 +125,8 @@ bool ModelResult::hasChildren(const QModelIndex &parent) const template bool ModelResult::canFetchMore(const QModelIndex &parent) const { - qDebug() << "Can fetch more: " << parent << mEntityChildrenFetched.value(parent.internalId()); - return !mEntityChildrenFetched.value(parent.internalId(), false); + qDebug() << "Can fetch more: " << parent << mEntityChildrenFetched.contains(parent.internalId()); + return !mEntityChildrenFetched.contains(parent.internalId()); } template @@ -139,7 +142,8 @@ void ModelResult::add(const Ptr &value) const auto childId = qHash(value->identifier()); const auto id = parentId(value); //Ignore updates we get before the initial fetch is done - if (!mEntityChildrenFetched[id]) { + if (!mEntityChildrenFetched.contains(id)) { + qDebug() << "Children not yet fetched"; return; } auto parent = createIndexFromId(id); @@ -185,7 +189,7 @@ template void ModelResult::fetchEntities(const QModelIndex &parent) { const auto id = getIdentifier(parent); - mEntityChildrenFetched[id] = true; + mEntityChildrenFetched.insert(id); Trace() << "Loading child entities"; loadEntities(parent.data(DomainObjectRole).template value()); } @@ -210,22 +214,28 @@ void ModelResult::setEmitter(const typename Akonadi2::ResultEmitter emitter->onRemoved([this](const Ptr &value) { this->remove(value); }); - emitter->onInitialResultSetComplete([this]() { - }); - emitter->onComplete([this]() { - }); - emitter->onClear([this]() { + emitter->onInitialResultSetComplete([this](const Ptr &parent) { + qint64 parentId = parent ? qHash(parent->identifier()) : 0; + const auto parentIndex = createIndexFromId(parentId); + mEntityChildrenFetchComplete.insert(parentId); + emit dataChanged(parentIndex, parentIndex, QVector() << ChildrenFetchedRole); }); mEmitter = emitter; } +template +bool ModelResult::childrenFetched(const QModelIndex &index) const +{ + return mEntityChildrenFetchComplete.contains(getIdentifier(index)); +} + template void ModelResult::modify(const Ptr &value) { auto childId = qHash(value->identifier()); auto id = parentId(value); //Ignore updates we get before the initial fetch is done - if (!mEntityChildrenFetched[id]) { + if (!mEntityChildrenFetched.contains(id)) { return; } auto parent = createIndexFromId(id); -- cgit v1.2.3