| 317 | } |
| 318 | |
| 319 | QVariant QmitkMultiLabelTreeModel::data(const QModelIndex &index, int role) const |
| 320 | { |
| 321 | if (!index.isValid()) |
| 322 | return QVariant(); |
| 323 | |
| 324 | auto item = static_cast<QmitkMultiLabelSegTreeItem*>(index.internalPointer()); |
| 325 | |
| 326 | if (!item) |
| 327 | return QVariant(); |
| 328 | |
| 329 | // Safe guard: avoid accessing segmentation state mid-update |
| 330 | if (m_ModelUpdateOngoing) |
| 331 | { |
| 332 | switch (role) |
| 333 | { |
| 334 | case Qt::DisplayRole: |
| 335 | case Qt::EditRole: |
| 336 | case Qt::DecorationRole: |
| 337 | return QVariant(); // benign safe fallback |
| 338 | default: |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | if (role == Qt::DisplayRole||role == Qt::EditRole) |
| 344 | { |
| 345 | if (TableColumns::NAME_COL == index.column()) |
| 346 | { |
| 347 | switch (item->m_ItemType) |
| 348 | { |
| 349 | case QmitkMultiLabelSegTreeItem::ItemType::Group: |
| 350 | { |
| 351 | const auto groupID = item->GetGroupID(); |
| 352 | if (m_Segmentation->ExistGroup(groupID)) |
| 353 | { |
| 354 | return QVariant(QString::fromStdString(mitk::LabelSetImageHelper::CreateDisplayGroupName(m_Segmentation, groupID))); |
| 355 | } |
| 356 | return QVariant(QString("unknown group")); |
| 357 | } |
| 358 | |
| 359 | case QmitkMultiLabelSegTreeItem::ItemType::Label: |
| 360 | { |
| 361 | auto label = item->GetLabel(); |
| 362 | |
| 363 | if (nullptr == label) |
| 364 | mitkThrow() << "Invalid internal state. QmitkMultiLabelTreeModel currentItem is referring to a label that does not exist."; |
| 365 | |
| 366 | QString name = QString::fromStdString(label->GetName()); |
| 367 | |
| 368 | if (!item->HandleAsInstance()) |
| 369 | name = name + QString(" (%1 instances)").arg(item->m_childItems.size()); |
| 370 | |
| 371 | return QVariant(name); |
| 372 | } |
| 373 | |
| 374 | case QmitkMultiLabelSegTreeItem::ItemType::Instance: |
| 375 | { |
| 376 | auto label = item->GetLabel(); |