summaryrefslogtreecommitdiffstats
path: root/common/modelresult.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r--common/modelresult.cpp30
1 files changed, 20 insertions, 10 deletions
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<T, Ptr>::data(const QModelIndex &index, int role) const
74 Q_ASSERT(mEntities.contains(index.internalId())); 74 Q_ASSERT(mEntities.contains(index.internalId()));
75 return QVariant::fromValue(mEntities.value(index.internalId())); 75 return QVariant::fromValue(mEntities.value(index.internalId()));
76 } 76 }
77 if (role == ChildrenFetchedRole) {
78 return childrenFetched(index);
79 }
77 if (role == Qt::DisplayRole) { 80 if (role == Qt::DisplayRole) {
78 if (index.column() < mPropertyColumns.size()) { 81 if (index.column() < mPropertyColumns.size()) {
79 Q_ASSERT(mEntities.contains(index.internalId())); 82 Q_ASSERT(mEntities.contains(index.internalId()));
@@ -122,8 +125,8 @@ bool ModelResult<T, Ptr>::hasChildren(const QModelIndex &parent) const
122template<class T, class Ptr> 125template<class T, class Ptr>
123bool ModelResult<T, Ptr>::canFetchMore(const QModelIndex &parent) const 126bool ModelResult<T, Ptr>::canFetchMore(const QModelIndex &parent) const
124{ 127{
125 qDebug() << "Can fetch more: " << parent << mEntityChildrenFetched.value(parent.internalId()); 128 qDebug() << "Can fetch more: " << parent << mEntityChildrenFetched.contains(parent.internalId());
126 return !mEntityChildrenFetched.value(parent.internalId(), false); 129 return !mEntityChildrenFetched.contains(parent.internalId());
127} 130}
128 131
129template<class T, class Ptr> 132template<class T, class Ptr>
@@ -139,7 +142,8 @@ void ModelResult<T, Ptr>::add(const Ptr &value)
139 const auto childId = qHash(value->identifier()); 142 const auto childId = qHash(value->identifier());
140 const auto id = parentId(value); 143 const auto id = parentId(value);
141 //Ignore updates we get before the initial fetch is done 144 //Ignore updates we get before the initial fetch is done
142 if (!mEntityChildrenFetched[id]) { 145 if (!mEntityChildrenFetched.contains(id)) {
146 qDebug() << "Children not yet fetched";
143 return; 147 return;
144 } 148 }
145 auto parent = createIndexFromId(id); 149 auto parent = createIndexFromId(id);
@@ -185,7 +189,7 @@ template<class T, class Ptr>
185void ModelResult<T, Ptr>::fetchEntities(const QModelIndex &parent) 189void ModelResult<T, Ptr>::fetchEntities(const QModelIndex &parent)
186{ 190{
187 const auto id = getIdentifier(parent); 191 const auto id = getIdentifier(parent);
188 mEntityChildrenFetched[id] = true; 192 mEntityChildrenFetched.insert(id);
189 Trace() << "Loading child entities"; 193 Trace() << "Loading child entities";
190 loadEntities(parent.data(DomainObjectRole).template value<Ptr>()); 194 loadEntities(parent.data(DomainObjectRole).template value<Ptr>());
191} 195}
@@ -210,22 +214,28 @@ void ModelResult<T, Ptr>::setEmitter(const typename Akonadi2::ResultEmitter<Ptr>
210 emitter->onRemoved([this](const Ptr &value) { 214 emitter->onRemoved([this](const Ptr &value) {
211 this->remove(value); 215 this->remove(value);
212 }); 216 });
213 emitter->onInitialResultSetComplete([this]() { 217 emitter->onInitialResultSetComplete([this](const Ptr &parent) {
214 }); 218 qint64 parentId = parent ? qHash(parent->identifier()) : 0;
215 emitter->onComplete([this]() { 219 const auto parentIndex = createIndexFromId(parentId);
216 }); 220 mEntityChildrenFetchComplete.insert(parentId);
217 emitter->onClear([this]() { 221 emit dataChanged(parentIndex, parentIndex, QVector<int>() << ChildrenFetchedRole);
218 }); 222 });
219 mEmitter = emitter; 223 mEmitter = emitter;
220} 224}
221 225
222template<class T, class Ptr> 226template<class T, class Ptr>
227bool ModelResult<T, Ptr>::childrenFetched(const QModelIndex &index) const
228{
229 return mEntityChildrenFetchComplete.contains(getIdentifier(index));
230}
231
232template<class T, class Ptr>
223void ModelResult<T, Ptr>::modify(const Ptr &value) 233void ModelResult<T, Ptr>::modify(const Ptr &value)
224{ 234{
225 auto childId = qHash(value->identifier()); 235 auto childId = qHash(value->identifier());
226 auto id = parentId(value); 236 auto id = parentId(value);
227 //Ignore updates we get before the initial fetch is done 237 //Ignore updates we get before the initial fetch is done
228 if (!mEntityChildrenFetched[id]) { 238 if (!mEntityChildrenFetched.contains(id)) {
229 return; 239 return;
230 } 240 }
231 auto parent = createIndexFromId(id); 241 auto parent = createIndexFromId(id);