* @brief Moves a group from one position to another, preserving widget settings, * workspace refs, hidden state, and auto-workspace IDs across the shift. */
| 3736 | * workspace refs, hidden state, and auto-workspace IDs across the shift. |
| 3737 | */ |
| 3738 | void DataModel::ProjectModel::moveGroup(int fromGroupId, int toGroupId) |
| 3739 | { |
| 3740 | const int n = static_cast<int>(m_groups.size()); |
| 3741 | if (fromGroupId < 0 || fromGroupId >= n) |
| 3742 | return; |
| 3743 | |
| 3744 | const int target = std::clamp(toGroupId, 0, n - 1); |
| 3745 | if (target == fromGroupId) |
| 3746 | return; |
| 3747 | |
| 3748 | std::vector<int> oldToNewGid(static_cast<size_t>(n)); |
| 3749 | for (int i = 0; i < n; ++i) |
| 3750 | oldToNewGid[static_cast<size_t>(i)] = i; |
| 3751 | |
| 3752 | if (fromGroupId < target) |
| 3753 | for (int i = fromGroupId + 1; i <= target; ++i) |
| 3754 | oldToNewGid[static_cast<size_t>(i)] = i - 1; |
| 3755 | |
| 3756 | else |
| 3757 | for (int i = target; i < fromGroupId; ++i) |
| 3758 | oldToNewGid[static_cast<size_t>(i)] = i + 1; |
| 3759 | |
| 3760 | oldToNewGid[static_cast<size_t>(fromGroupId)] = target; |
| 3761 | |
| 3762 | std::vector<std::vector<detail::RefAnchor>> anchors; |
| 3763 | if (m_customizeWorkspaces) |
| 3764 | anchors = snapshotAllRefs(m_workspaces, m_groups); |
| 3765 | |
| 3766 | auto group = m_groups[fromGroupId]; |
| 3767 | m_groups.erase(m_groups.begin() + fromGroupId); |
| 3768 | m_groups.insert(m_groups.begin() + target, group); |
| 3769 | |
| 3770 | remapGroupIdsAfterReorder(oldToNewGid); |
| 3771 | |
| 3772 | remapLayoutKeysAfterReorder(oldToNewGid); |
| 3773 | remapHiddenGroupIdsAfterReorder(oldToNewGid); |
| 3774 | remapAutoWorkspaceIdsAfterReorder(oldToNewGid); |
| 3775 | |
| 3776 | if (m_customizeWorkspaces) |
| 3777 | for (size_t w = 0; w < m_workspaces.size(); ++w) |
| 3778 | resolveOneWorkspaceRefs(m_workspaces[w], anchors[w], m_groups); |
| 3779 | |
| 3780 | if (m_selectedGroup.groupId == fromGroupId) |
| 3781 | m_selectedGroup = m_groups[target]; |
| 3782 | |
| 3783 | Q_EMIT groupsChanged(); |
| 3784 | Q_EMIT widgetSettingsChanged(); |
| 3785 | setModified(true); |
| 3786 | } |
| 3787 | |
| 3788 | /** |
| 3789 | * @brief Moves a dataset within its group, renumbering datasetIds and re-resolving |
no test coverage detected