summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-03 17:58:47 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-03 17:58:47 +0100
commitfb09018d49e182012422d721fb0fbf95130b82c5 (patch)
tree02900538df0f125874b1465a4c4fdb5300ba7d4a /common
parent9fa528c5fceefd53303a604625d13cf0cdbb109e (diff)
downloadsink-fb09018d49e182012422d721fb0fbf95130b82c5.tar.gz
sink-fb09018d49e182012422d721fb0fbf95130b82c5.zip
We need all parents available, not only one
Diffstat (limited to 'common')
-rw-r--r--common/modelresult.cpp24
-rw-r--r--common/modelresult.h1
2 files changed, 20 insertions, 5 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp
index 9685e3c..495eca0 100644
--- a/common/modelresult.cpp
+++ b/common/modelresult.cpp
@@ -236,6 +236,7 @@ QModelIndex ModelResult<T, Ptr>::createIndexFromId(const qint64 &id) const
236 } 236 }
237 auto grandParentId = mParents.value(id, 0); 237 auto grandParentId = mParents.value(id, 0);
238 auto row = mTree.value(grandParentId).indexOf(id); 238 auto row = mTree.value(grandParentId).indexOf(id);
239 Q_ASSERT(row >= 0);
239 return createIndex(row, 0, id); 240 return createIndex(row, 0, id);
240} 241}
241 242
@@ -291,6 +292,19 @@ void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent)
291} 292}
292 293
293template <class T, class Ptr> 294template <class T, class Ptr>
295bool ModelResult<T, Ptr>::allParentsAvailable(qint64 id) const
296{
297 auto p = id;
298 while (p) {
299 if (!mEntities.contains(p)) {
300 return false;
301 }
302 p = mParents.value(p, 0);
303 }
304 return true;
305}
306
307template <class T, class Ptr>
294void ModelResult<T, Ptr>::add(const Ptr &value) 308void ModelResult<T, Ptr>::add(const Ptr &value)
295{ 309{
296 const auto childId = qHash(*value); 310 const auto childId = qHash(*value);
@@ -306,16 +320,16 @@ void ModelResult<T, Ptr>::add(const Ptr &value)
306 break; 320 break;
307 } 321 }
308 } 322 }
309 bool parentIsAvailable = mEntities.contains(pId) || (pId == 0); 323 bool parentIsVisible = allParentsAvailable(pId);
310 SinkTraceCtx(mLogCtx) << "Added entity " << childId << "id: " << value->identifier() << "parent: " << pId;
311 // SinkTraceCtx(mLogCtx) << "Inserting rows " << index << parent; 324 // SinkTraceCtx(mLogCtx) << "Inserting rows " << index << parent;
312 if (parentIsAvailable) { 325 if (parentIsVisible) {
313 beginInsertRows(createIndexFromId(pId), idx, idx); 326 auto parent = createIndexFromId(pId);
327 beginInsertRows(parent, idx, idx);
314 } 328 }
315 mEntities.insert(childId, value); 329 mEntities.insert(childId, value);
316 mTree[pId].insert(idx, childId); 330 mTree[pId].insert(idx, childId);
317 mParents.insert(childId, pId); 331 mParents.insert(childId, pId);
318 if (parentIsAvailable) { 332 if (parentIsVisible) {
319 endInsertRows(); 333 endInsertRows();
320 } 334 }
321 // SinkTraceCtx(mLogCtx) << "Inserted rows " << mTree[id].size(); 335 // SinkTraceCtx(mLogCtx) << "Inserted rows " << mTree[id].size();
diff --git a/common/modelresult.h b/common/modelresult.h
index 55a95b9..321f9f1 100644
--- a/common/modelresult.h
+++ b/common/modelresult.h
@@ -75,6 +75,7 @@ private:
75 75
76 qint64 parentId(const Ptr &value); 76 qint64 parentId(const Ptr &value);
77 QModelIndex createIndexFromId(const qint64 &id) const; 77 QModelIndex createIndexFromId(const qint64 &id) const;
78 bool allParentsAvailable(qint64 id) const;
78 79
79 Sink::Log::Context mLogCtx; 80 Sink::Log::Context mLogCtx;
80 // TODO we should be able to directly use T as index, with an appropriate hash function, and thus have a QMap<T, T> and QList<T> 81 // TODO we should be able to directly use T as index, with an appropriate hash function, and thus have a QMap<T, T> and QList<T>