* @brief Moves a dataset within its group, renumbering datasetIds and re-resolving * workspace refs in customise mode. */
| 3790 | * workspace refs in customise mode. |
| 3791 | */ |
| 3792 | void DataModel::ProjectModel::moveDataset(int groupId, int fromDatasetId, int toDatasetId) |
| 3793 | { |
| 3794 | if (groupId < 0 || static_cast<size_t>(groupId) >= m_groups.size()) |
| 3795 | return; |
| 3796 | |
| 3797 | auto& datasets = m_groups[groupId].datasets; |
| 3798 | const int n = static_cast<int>(datasets.size()); |
| 3799 | if (fromDatasetId < 0 || fromDatasetId >= n) |
| 3800 | return; |
| 3801 | |
| 3802 | const int target = std::clamp(toDatasetId, 0, n - 1); |
| 3803 | if (target == fromDatasetId) |
| 3804 | return; |
| 3805 | |
| 3806 | std::vector<std::vector<detail::RefAnchor>> anchors; |
| 3807 | if (m_customizeWorkspaces) |
| 3808 | anchors = snapshotAllRefs(m_workspaces, m_groups); |
| 3809 | |
| 3810 | auto dataset = datasets[fromDatasetId]; |
| 3811 | datasets.erase(datasets.begin() + fromDatasetId); |
| 3812 | datasets.insert(datasets.begin() + target, dataset); |
| 3813 | |
| 3814 | for (size_t i = 0; i < datasets.size(); ++i) |
| 3815 | datasets[i].datasetId = static_cast<int>(i); |
| 3816 | |
| 3817 | if (m_customizeWorkspaces) |
| 3818 | for (size_t w = 0; w < m_workspaces.size(); ++w) |
| 3819 | resolveOneWorkspaceRefs(m_workspaces[w], anchors[w], m_groups); |
| 3820 | |
| 3821 | if (m_selectedDataset.groupId == groupId && m_selectedDataset.datasetId == fromDatasetId) |
| 3822 | m_selectedDataset = datasets[target]; |
| 3823 | |
| 3824 | Q_EMIT groupsChanged(); |
| 3825 | setModified(true); |
| 3826 | } |
| 3827 | |
| 3828 | /** |
| 3829 | * @brief Moves a workspace to the given index in the editor list. |
no test coverage detected