summaryrefslogtreecommitdiffstats
path: root/common/modelresult.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r--common/modelresult.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp
index d18dba1..690a17e 100644
--- a/common/modelresult.cpp
+++ b/common/modelresult.cpp
@@ -24,6 +24,13 @@
24#include "domain/folder.h" 24#include "domain/folder.h"
25#include "log.h" 25#include "log.h"
26 26
27static uint qHash(const Akonadi2::ApplicationDomain::ApplicationDomainType &type)
28{
29 Q_ASSERT(!type.resourceInstanceIdentifier().isEmpty());
30 Q_ASSERT(!type.identifier().isEmpty());
31 return qHash(type.resourceInstanceIdentifier() + type.identifier());
32}
33
27template<class T, class Ptr> 34template<class T, class Ptr>
28ModelResult<T, Ptr>::ModelResult(const Akonadi2::Query &query, const QList<QByteArray> &propertyColumns) 35ModelResult<T, Ptr>::ModelResult(const Akonadi2::Query &query, const QList<QByteArray> &propertyColumns)
29 :QAbstractItemModel(), 36 :QAbstractItemModel(),
@@ -44,9 +51,9 @@ template<class T, class Ptr>
44qint64 ModelResult<T, Ptr>::parentId(const Ptr &value) 51qint64 ModelResult<T, Ptr>::parentId(const Ptr &value)
45{ 52{
46 if (!mQuery.parentProperty.isEmpty()) { 53 if (!mQuery.parentProperty.isEmpty()) {
47 const auto property = value->getProperty(mQuery.parentProperty).toByteArray(); 54 const auto identifier = value->getProperty(mQuery.parentProperty).toByteArray();
48 if (!property.isEmpty()) { 55 if (!identifier.isEmpty()) {
49 return qHash(property); 56 return qHash(T(value->resourceInstanceIdentifier(), identifier, 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()));
50 } 57 }
51 } 58 }
52 return 0; 59 return 0;
@@ -152,7 +159,7 @@ void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent)
152template<class T, class Ptr> 159template<class T, class Ptr>
153void ModelResult<T, Ptr>::add(const Ptr &value) 160void ModelResult<T, Ptr>::add(const Ptr &value)
154{ 161{
155 const auto childId = qHash(value->identifier()); 162 const auto childId = qHash(*value);
156 const auto id = parentId(value); 163 const auto id = parentId(value);
157 //Ignore updates we get before the initial fetch is done 164 //Ignore updates we get before the initial fetch is done
158 if (!mEntityChildrenFetched.contains(id)) { 165 if (!mEntityChildrenFetched.contains(id)) {
@@ -184,11 +191,11 @@ void ModelResult<T, Ptr>::add(const Ptr &value)
184template<class T, class Ptr> 191template<class T, class Ptr>
185void ModelResult<T, Ptr>::remove(const Ptr &value) 192void ModelResult<T, Ptr>::remove(const Ptr &value)
186{ 193{
187 auto childId = qHash(value->identifier()); 194 auto childId = qHash(*value);
188 auto id = parentId(value); 195 auto id = parentId(value);
189 auto parent = createIndexFromId(id); 196 auto parent = createIndexFromId(id);
190 // qDebug() << "Removed entity" << childId; 197 // qDebug() << "Removed entity" << childId;
191 auto index = mTree[id].indexOf(qHash(value->identifier())); 198 auto index = mTree[id].indexOf(childId);
192 beginRemoveRows(parent, index, index); 199 beginRemoveRows(parent, index, index);
193 mEntities.remove(childId); 200 mEntities.remove(childId);
194 mTree[id].removeAll(childId); 201 mTree[id].removeAll(childId);
@@ -202,7 +209,7 @@ void ModelResult<T, Ptr>::fetchEntities(const QModelIndex &parent)
202{ 209{
203 const auto id = getIdentifier(parent); 210 const auto id = getIdentifier(parent);
204 mEntityChildrenFetched.insert(id); 211 mEntityChildrenFetched.insert(id);
205 Trace() << "Loading child entities"; 212 Trace() << "Loading child entities of parent " << id;
206 if (loadEntities) { 213 if (loadEntities) {
207 loadEntities(parent.data(DomainObjectRole).template value<Ptr>()); 214 loadEntities(parent.data(DomainObjectRole).template value<Ptr>());
208 } else { 215 } else {
@@ -220,7 +227,7 @@ void ModelResult<T, Ptr>::setFetcher(const std::function<void(const Ptr &parent)
220template<class T, class Ptr> 227template<class T, class Ptr>
221void ModelResult<T, Ptr>::setEmitter(const typename Akonadi2::ResultEmitter<Ptr>::Ptr &emitter) 228void ModelResult<T, Ptr>::setEmitter(const typename Akonadi2::ResultEmitter<Ptr>::Ptr &emitter)
222{ 229{
223 setFetcher(emitter->mFetcher); 230 setFetcher([this](const Ptr &parent) {mEmitter->fetch(parent);});
224 emitter->onAdded([this](const Ptr &value) { 231 emitter->onAdded([this](const Ptr &value) {
225 this->add(value); 232 this->add(value);
226 }); 233 });
@@ -231,7 +238,7 @@ void ModelResult<T, Ptr>::setEmitter(const typename Akonadi2::ResultEmitter<Ptr>
231 this->remove(value); 238 this->remove(value);
232 }); 239 });
233 emitter->onInitialResultSetComplete([this](const Ptr &parent) { 240 emitter->onInitialResultSetComplete([this](const Ptr &parent) {
234 const qint64 parentId = parent ? qHash(parent->identifier()) : 0; 241 const qint64 parentId = parent ? qHash(*parent) : 0;
235 const auto parentIndex = createIndexFromId(parentId); 242 const auto parentIndex = createIndexFromId(parentId);
236 mEntityChildrenFetchComplete.insert(parentId); 243 mEntityChildrenFetchComplete.insert(parentId);
237 emit dataChanged(parentIndex, parentIndex, QVector<int>() << ChildrenFetchedRole); 244 emit dataChanged(parentIndex, parentIndex, QVector<int>() << ChildrenFetchedRole);
@@ -248,7 +255,7 @@ bool ModelResult<T, Ptr>::childrenFetched(const QModelIndex &index) const
248template<class T, class Ptr> 255template<class T, class Ptr>
249void ModelResult<T, Ptr>::modify(const Ptr &value) 256void ModelResult<T, Ptr>::modify(const Ptr &value)
250{ 257{
251 auto childId = qHash(value->identifier()); 258 auto childId = qHash(*value);
252 auto id = parentId(value); 259 auto id = parentId(value);
253 //Ignore updates we get before the initial fetch is done 260 //Ignore updates we get before the initial fetch is done
254 if (!mEntityChildrenFetched.contains(id)) { 261 if (!mEntityChildrenFetched.contains(id)) {