MCPcopy Create free account
hub / github.com/MITK/MITK / AddNodeInternal

Method AddNodeInternal

Modules/QtWidgets/src/QmitkDataStorageSimpleTreeModel.cpp:312–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

310}
311
312void QmitkDataStorageSimpleTreeModel::AddNodeInternal(const mitk::DataNode *node)
313{
314 auto dataStorage = m_DataStorage.Lock();
315
316 if (node == nullptr || dataStorage.IsNull() || !dataStorage->Exists(node) || m_Root->Find(node) != nullptr)
317 return;
318
319 // find out if we have a root node
320 TreeItem *parentTreeItem = m_Root;
321 QModelIndex index;
322 mitk::DataNode *parentDataNode = this->GetParentNode(node);
323
324 if (parentDataNode) // no top level data node
325 {
326 parentTreeItem = m_Root->Find(parentDataNode); // find the corresponding tree item
327 if (!parentTreeItem)
328 {
329 this->NodeAdded(parentDataNode);
330 parentTreeItem = m_Root->Find(parentDataNode);
331 if (!parentTreeItem)
332 return;
333 }
334
335 // get the index of this parent with the help of the grand parent
336 index = this->createIndex(parentTreeItem->GetIndex(), 0, parentTreeItem);
337 }
338
339 int firstRowWithASiblingBelow = 0;
340 int nodeLayer = -1;
341 node->GetIntProperty("layer", nodeLayer);
342 for (TreeItem *siblingTreeItem : parentTreeItem->GetChildren())
343 {
344 int siblingLayer = -1;
345 if (mitk::DataNode *siblingNode = siblingTreeItem->GetDataNode())
346 {
347 siblingNode->GetIntProperty("layer", siblingLayer);
348 }
349 if (nodeLayer > siblingLayer)
350 {
351 break;
352 }
353 ++firstRowWithASiblingBelow;
354 }
355 beginInsertRows(index, firstRowWithASiblingBelow, firstRowWithASiblingBelow);
356 auto newNode = new TreeItem(const_cast<mitk::DataNode *>(node));
357 parentTreeItem->InsertChild(newNode, firstRowWithASiblingBelow);
358 m_TreeItems.push_back(newNode);
359
360 endInsertRows();
361}
362
363QModelIndex QmitkDataStorageSimpleTreeModel::IndexFromTreeItem(TreeItem *item) const
364{

Callers 2

NodeAddedMethod · 0.95
UpdateModelDataMethod · 0.95

Calls 11

GetParentNodeMethod · 0.95
NodeAddedMethod · 0.95
LockMethod · 0.45
IsNullMethod · 0.45
ExistsMethod · 0.45
FindMethod · 0.45
GetIndexMethod · 0.45
GetIntPropertyMethod · 0.45
GetChildrenMethod · 0.45
GetDataNodeMethod · 0.45
InsertChildMethod · 0.45

Tested by

no test coverage detected