* @brief Wires ProjectModel dataset add/delete signals into selection bookkeeping. */
| 427 | * @brief Wires ProjectModel dataset add/delete signals into selection bookkeeping. |
| 428 | */ |
| 429 | void DataModel::ProjectEditor::wireDatasetSignals() |
| 430 | { |
| 431 | auto& pm = DataModel::ProjectModel::instance(); |
| 432 | |
| 433 | connect( |
| 434 | &pm, |
| 435 | &DataModel::ProjectModel::datasetAdded, |
| 436 | this, |
| 437 | [this](int groupId, int datasetId) { |
| 438 | if (!m_selectionModel) |
| 439 | return; |
| 440 | |
| 441 | for (auto it = m_datasetItems.begin(); it != m_datasetItems.end(); ++it) { |
| 442 | if (it.value().groupId != groupId || it.value().datasetId != datasetId) |
| 443 | continue; |
| 444 | |
| 445 | m_selectionModel->setCurrentIndex(it.key()->index(), QItemSelectionModel::ClearAndSelect); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | m_pendingSelectionKind = PendingSelectionKind::Dataset; |
| 450 | m_pendingSelectionGroupId = groupId; |
| 451 | m_pendingSelectionItemId = datasetId; |
| 452 | }, |
| 453 | Qt::QueuedConnection); |
| 454 | |
| 455 | connect( |
| 456 | &pm, |
| 457 | &DataModel::ProjectModel::datasetDeleted, |
| 458 | this, |
| 459 | [this](int survivingGroupId) { |
| 460 | if (!m_selectionModel) |
| 461 | return; |
| 462 | |
| 463 | if (survivingGroupId >= 0) { |
| 464 | for (auto it = m_groupItems.begin(); it != m_groupItems.end(); ++it) { |
| 465 | if (it.value().groupId != survivingGroupId) |
| 466 | continue; |
| 467 | |
| 468 | m_selectionModel->setCurrentIndex(it.key()->index(), QItemSelectionModel::ClearAndSelect); |
| 469 | return; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if (m_groupsRootItem) { |
| 474 | m_selectionModel->setCurrentIndex(m_groupsRootItem->index(), |
| 475 | QItemSelectionModel::ClearAndSelect); |
| 476 | return; |
| 477 | } |
| 478 | |
| 479 | auto index = m_treeModel->index(0, 0); |
| 480 | m_selectionModel->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); |
| 481 | }, |
| 482 | Qt::QueuedConnection); |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * @brief Wires ProjectModel action add/delete signals into selection bookkeeping. |
nothing calls this directly
no test coverage detected