| 1601 | } |
| 1602 | |
| 1603 | void MainWindow::onRemoveDatasetsRequested(const QList<DatasetId>& dataset_ids) { |
| 1604 | if (dataset_ids.isEmpty()) { |
| 1605 | return; |
| 1606 | } |
| 1607 | // One combined confirmation. Single removal keeps the named wording; a batch |
| 1608 | // shows the count. |
| 1609 | QString message; |
| 1610 | if (dataset_ids.size() == 1) { |
| 1611 | QString name = QString::number(dataset_ids.front()); |
| 1612 | for (const auto& [id, dataset_name] : session_->catalogModel().datasets()) { |
| 1613 | if (id == dataset_ids.front()) { |
| 1614 | name = dataset_name; |
| 1615 | break; |
| 1616 | } |
| 1617 | } |
| 1618 | message = tr("Are you sure you want to remove '%1' and its data?").arg(name); |
| 1619 | } else { |
| 1620 | message = tr("Are you sure you want to remove these %1 datasets and their data?").arg(dataset_ids.size()); |
| 1621 | } |
| 1622 | const int choice = MessageBox::question( |
| 1623 | this, dataset_ids.size() == 1 ? tr("Remove dataset") : tr("Remove datasets"), message, |
| 1624 | {{tr("Remove"), MessageBox::kDestructiveRole}, {tr("Cancel"), MessageBox::kCancelRole}}); |
| 1625 | if (choice != 0) { |
| 1626 | return; // Cancel / Esc |
| 1627 | } |
| 1628 | |
| 1629 | // Cascade to derived series whose input lives in any of these datasets (their |
| 1630 | // output is typically in another dataset, so removeDataset alone would orphan |
| 1631 | // them). Warn + remove those transforms and their Custom Series entries; abort |
| 1632 | // the whole removal on cancel. No-op when nothing depends on the removed data. |
| 1633 | { |
| 1634 | std::vector<std::string> removed_names; |
| 1635 | for (const auto& item : session_->catalogModel().items()) { |
| 1636 | if (std::find(dataset_ids.begin(), dataset_ids.end(), item.dataset_id) != dataset_ids.end()) { |
| 1637 | removed_names.push_back(item.topic_name.toStdString()); |
| 1638 | } |
| 1639 | } |
| 1640 | if (!confirmAndRemoveDependentTransforms(removed_names)) { |
| 1641 | return; // user cancelled |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | for (const DatasetId id : dataset_ids) { |
| 1646 | removeDatasetData(id); |
| 1647 | } |
| 1648 | // Shrink the playback range to the remaining data right away — unless a streaming |
| 1649 | // dataset exists (the slider is scoped to the active stream). Reset undo once. |
| 1650 | if (active_streaming_dataset_id_ == 0) { |
| 1651 | session_->seedPlaybackFromSession(); |
| 1652 | } |
| 1653 | resetUndoHistory(); |
| 1654 | } |
| 1655 | |
| 1656 | void MainWindow::onMergeDatasetsRequested(const QList<DatasetId>& dataset_ids) { |
| 1657 | std::vector<DatasetId> ids; |