| 310 | } |
| 311 | |
| 312 | void 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 | |
| 363 | QModelIndex QmitkDataStorageSimpleTreeModel::IndexFromTreeItem(TreeItem *item) const |
| 364 | { |
no test coverage detected