summaryrefslogtreecommitdiffstats
path: root/common/modelresult.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-03 10:55:35 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-03 10:55:35 +0100
commitf63f772eb59e246948fcdf178abee72dc3efc8f0 (patch)
treed5cc5e75e09c3b4636e04ee79a76595b6c1c172f /common/modelresult.cpp
parent5eb014833160d0dbd1c27742a7fcddb0ede31859 (diff)
downloadsink-f63f772eb59e246948fcdf178abee72dc3efc8f0.tar.gz
sink-f63f772eb59e246948fcdf178abee72dc3efc8f0.zip
Avoid emitting signals for children without parents
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r--common/modelresult.cpp20
1 files 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 <class T, class Ptr>
279void ModelResult<T, Ptr>::add(const Ptr &value) 279void ModelResult<T, Ptr>::add(const Ptr &value)
280{ 280{
281 const auto childId = qHash(*value); 281 const auto childId = qHash(*value);
282 const auto id = parentId(value); 282 const auto pId = parentId(value);
283 // Ignore updates we get before the initial fetch is done 283 // Ignore updates we get before the initial fetch is done
284 // if (!mEntityChildrenFetched.contains(id)) { 284 // if (!mEntityChildrenFetched.contains(id)) {
285 // SinkTraceCtx(mLogCtx) << "Too early" << id; 285 // SinkTraceCtx(mLogCtx) << "Too early" << id;
@@ -289,21 +289,25 @@ void ModelResult<T, Ptr>::add(const Ptr &value)
289 SinkWarningCtx(mLogCtx) << "Entity already in model: " << value->identifier(); 289 SinkWarningCtx(mLogCtx) << "Entity already in model: " << value->identifier();
290 return; 290 return;
291 } 291 }
292 auto parent = createIndexFromId(id); 292 const auto keys = mTree[pId];
293 SinkTraceCtx(mLogCtx) << "Added entity " << childId << "id: " << value->identifier() << "parent: " << id;
294 const auto keys = mTree[id];
295 int idx = 0; 293 int idx = 0;
296 for (; idx < keys.size(); idx++) { 294 for (; idx < keys.size(); idx++) {
297 if (childId < keys.at(idx)) { 295 if (childId < keys.at(idx)) {
298 break; 296 break;
299 } 297 }
300 } 298 }
299 bool parentIsAvailable = mEntities.contains(pId) || (pId == 0);
300 SinkTraceCtx(mLogCtx) << "Added entity " << childId << "id: " << value->identifier() << "parent: " << pId;
301 // SinkTraceCtx(mLogCtx) << "Inserting rows " << index << parent; 301 // SinkTraceCtx(mLogCtx) << "Inserting rows " << index << parent;
302 beginInsertRows(parent, idx, idx); 302 if (parentIsAvailable) {
303 beginInsertRows(createIndexFromId(pId), idx, idx);
304 }
303 mEntities.insert(childId, value); 305 mEntities.insert(childId, value);
304 mTree[id].insert(idx, childId); 306 mTree[pId].insert(idx, childId);
305 mParents.insert(childId, id); 307 mParents.insert(childId, pId);
306 endInsertRows(); 308 if (parentIsAvailable) {
309 endInsertRows();
310 }
307 // SinkTraceCtx(mLogCtx) << "Inserted rows " << mTree[id].size(); 311 // SinkTraceCtx(mLogCtx) << "Inserted rows " << mTree[id].size();
308} 312}
309 313