| 481 | } |
| 482 | |
| 483 | void QmitkRenderWindowDataStorageTreeModel::AddNodeInternal(const mitk::DataNode* dataNode, const mitk::BaseRenderer* renderer) |
| 484 | { |
| 485 | if (nullptr == dataNode |
| 486 | || m_DataStorage.IsExpired() |
| 487 | || nullptr != m_Root->Find(dataNode)) |
| 488 | { |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | // find out if we have a root node |
| 493 | auto parentItem = m_Root; |
| 494 | QModelIndex index; |
| 495 | auto parentDataNode = GetParentNode(dataNode); |
| 496 | |
| 497 | if (nullptr != parentDataNode) // no top level data node |
| 498 | { |
| 499 | parentItem = m_Root->Find(parentDataNode); |
| 500 | if (nullptr == parentItem) |
| 501 | { |
| 502 | // parent node not contained in the tree; add it |
| 503 | NodeAdded(parentDataNode); |
| 504 | parentItem = m_Root->Find(parentDataNode); |
| 505 | if (nullptr == parentItem) |
| 506 | { |
| 507 | // could not find and add the parent tree; abort |
| 508 | return; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // get the index of this parent with the help of the grand parent |
| 513 | index = createIndex(parentItem->GetIndex(), 0, parentItem); |
| 514 | } |
| 515 | |
| 516 | int firstRowWithASiblingBelow = 0; |
| 517 | int nodeLayer = -1; |
| 518 | dataNode->GetIntProperty("layer", nodeLayer, renderer); |
| 519 | for (const auto& siblingItem : parentItem->GetChildren()) |
| 520 | { |
| 521 | int siblingLayer = -1; |
| 522 | auto siblingNode = siblingItem->GetDataNode(); |
| 523 | if (nullptr != siblingNode) |
| 524 | { |
| 525 | siblingNode->GetIntProperty("layer", siblingLayer, renderer); |
| 526 | } |
| 527 | if (nodeLayer > siblingLayer) |
| 528 | { |
| 529 | break; |
| 530 | } |
| 531 | ++firstRowWithASiblingBelow; |
| 532 | } |
| 533 | |
| 534 | beginInsertRows(index, firstRowWithASiblingBelow, firstRowWithASiblingBelow); |
| 535 | auto newNode = new QmitkDataStorageTreeModelInternalItem(const_cast<mitk::DataNode*>(dataNode)); |
| 536 | parentItem->InsertChild(newNode, firstRowWithASiblingBelow); |
| 537 | endInsertRows(); |
| 538 | } |
| 539 | |
| 540 | void QmitkRenderWindowDataStorageTreeModel::RemoveNodeInternal(const mitk::DataNode* dataNode) |
nothing calls this directly
no test coverage detected