MCPcopy Create free account
hub / github.com/KDAB/GammaRay / populateFromNode

Method populateFromNode

plugins/quickinspector/quickscenegraphmodel.cpp:183–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181 }
182
183void QuickSceneGraphModel::populateFromNode(QSGNode *node, bool emitSignals)
184{
185 if (!node)
186 return;
187
188 QVector<QSGNode *> &childList = m_parentChildMap[node];
189 QVector<QSGNode *> newChildList;
190
191 newChildList.reserve(node->childCount());
192 for (QSGNode *childNode = node->firstChild(); childNode; childNode = childNode->nextSibling())
193 newChildList.append(childNode);
194
195 QModelIndex myIndex; // don't call indexForNode(node) here yet, in the common case of few changes we waste a lot of time here
196 bool hasMyIndex = false;
197
198 std::sort(newChildList.begin(), newChildList.end());
199
200 auto i = childList.begin();
201 auto j = newChildList.constBegin();
202
203 while (i != childList.end() && j != newChildList.constEnd()) {
204 if (*i < *j) { // handle deleted node
205 emit nodeDeleted(*i);
206 GET_INDEX
207 if (emitSignals) {
208 const auto idx = std::distance(childList.begin(), i);
209 beginRemoveRows(myIndex, idx, idx);
210 }
211 pruneSubTree(*i);
212 i = childList.erase(i);
213 if (emitSignals)
214 endRemoveRows();
215 } else if (*i > *j) { // handle added node
216 GET_INDEX
217 const auto idx = std::distance(childList.begin(), i);
218 if (contains(m_childParentMap, *j)) { // move from elsewhere in our tree
219 const auto sourceIdx = indexForNode(*j);
220 Q_ASSERT(sourceIdx.isValid());
221#if 0
222 if (emitSignals)
223 beginMoveRows(sourceIdx.parent(), sourceIdx.row(), sourceIdx.row(), myIndex,
224 idx);
225 m_parentChildMap[m_childParentMap.value(*j)].remove(sourceIdx.row());
226 m_childParentMap.insert(*j, node);
227 i = childList.insert(i, *j);
228 if (emitSignals)
229 endMoveRows();
230#else
231 if (emitSignals) {
232 beginRemoveRows(sourceIdx.parent(), sourceIdx.row(), sourceIdx.row());
233 }
234
235 auto cit = m_childParentMap.find(*j);
236 if (cit != m_childParentMap.end()) {
237 QSGNode *node = cit->second;
238 m_parentChildMap[node].remove(sourceIdx.row());
239
240 m_childParentMap.erase(cit);

Callers

nothing calls this directly

Calls 14

containsFunction · 0.85
reserveMethod · 0.80
appendMethod · 0.80
endMethod · 0.80
rowMethod · 0.80
beginMethod · 0.45
constBeginMethod · 0.45
constEndMethod · 0.45
isValidMethod · 0.45
parentMethod · 0.45
removeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected