From f63f772eb59e246948fcdf178abee72dc3efc8f0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 3 Jan 2018 10:55:35 +0100 Subject: Avoid emitting signals for children without parents --- common/modelresult.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/common/modelresult.cpp b/common/modelresult.cpp index cc5f4ed..5f8fc8a 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp @@ -279,7 +279,7 @@ template void ModelResult::add(const Ptr &value) { const auto childId = qHash(*value); - const auto id = parentId(value); + const auto pId = parentId(value); // Ignore updates we get before the initial fetch is done // if (!mEntityChildrenFetched.contains(id)) { // SinkTraceCtx(mLogCtx) << "Too early" << id; @@ -289,21 +289,25 @@ void ModelResult::add(const Ptr &value) SinkWarningCtx(mLogCtx) << "Entity already in model: " << value->identifier(); return; } - auto parent = createIndexFromId(id); - SinkTraceCtx(mLogCtx) << "Added entity " << childId << "id: " << value->identifier() << "parent: " << id; - const auto keys = mTree[id]; + const auto keys = mTree[pId]; int idx = 0; for (; idx < keys.size(); idx++) { if (childId < keys.at(idx)) { break; } } + bool parentIsAvailable = mEntities.contains(pId) || (pId == 0); + SinkTraceCtx(mLogCtx) << "Added entity " << childId << "id: " << value->identifier() << "parent: " << pId; // SinkTraceCtx(mLogCtx) << "Inserting rows " << index << parent; - beginInsertRows(parent, idx, idx); + if (parentIsAvailable) { + beginInsertRows(createIndexFromId(pId), idx, idx); + } mEntities.insert(childId, value); - mTree[id].insert(idx, childId); - mParents.insert(childId, id); - endInsertRows(); + mTree[pId].insert(idx, childId); + mParents.insert(childId, pId); + if (parentIsAvailable) { + endInsertRows(); + } // SinkTraceCtx(mLogCtx) << "Inserted rows " << mTree[id].size(); } -- cgit v1.2.3