diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-03 17:58:47 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-03 17:58:47 +0100 |
commit | fb09018d49e182012422d721fb0fbf95130b82c5 (patch) | |
tree | 02900538df0f125874b1465a4c4fdb5300ba7d4a /common/modelresult.cpp | |
parent | 9fa528c5fceefd53303a604625d13cf0cdbb109e (diff) | |
download | sink-fb09018d49e182012422d721fb0fbf95130b82c5.tar.gz sink-fb09018d49e182012422d721fb0fbf95130b82c5.zip |
We need all parents available, not only one
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r-- | common/modelresult.cpp | 24 |
1 files changed, 19 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 | ||
293 | template <class T, class Ptr> | 294 | template <class T, class Ptr> |
295 | bool 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 | |||
307 | template <class T, class Ptr> | ||
294 | void ModelResult<T, Ptr>::add(const Ptr &value) | 308 | void 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(); |