* @brief Reorders user-defined workspaces (id >= UserStart) by the given id * sequence, bailing out when the id set does not match the existing user * workspaces because a partial reorder would silently corrupt the list. */
| 5184 | * workspaces because a partial reorder would silently corrupt the list. |
| 5185 | */ |
| 5186 | void DataModel::ProjectModel::reorderWorkspaces(const QList<int>& userWorkspaceIds) |
| 5187 | { |
| 5188 | if (AppState::instance().operationMode() != SerialStudio::ProjectFile) |
| 5189 | return; |
| 5190 | |
| 5191 | QHash<int, DataModel::Workspace> userById; |
| 5192 | std::vector<DataModel::Workspace> systemSlots; |
| 5193 | for (auto& ws : m_workspaces) |
| 5194 | if (ws.workspaceId >= WorkspaceIds::UserStart) |
| 5195 | userById.insert(ws.workspaceId, std::move(ws)); |
| 5196 | else |
| 5197 | systemSlots.push_back(std::move(ws)); |
| 5198 | |
| 5199 | if (userWorkspaceIds.size() != userById.size()) |
| 5200 | return; |
| 5201 | |
| 5202 | for (int id : userWorkspaceIds) |
| 5203 | if (!userById.contains(id)) |
| 5204 | return; |
| 5205 | |
| 5206 | std::vector<DataModel::Workspace> rebuilt; |
| 5207 | rebuilt.reserve(systemSlots.size() + userById.size()); |
| 5208 | for (auto& ws : systemSlots) |
| 5209 | rebuilt.push_back(std::move(ws)); |
| 5210 | |
| 5211 | for (int id : userWorkspaceIds) |
| 5212 | rebuilt.push_back(std::move(userById[id])); |
| 5213 | |
| 5214 | m_workspaces = std::move(rebuilt); |
| 5215 | |
| 5216 | if (!m_customizeWorkspaces) |
| 5217 | setCustomizeWorkspaces(true); |
| 5218 | |
| 5219 | setModified(true); |
| 5220 | Q_EMIT editorWorkspacesChanged(); |
| 5221 | Q_EMIT activeWorkspacesChanged(); |
| 5222 | } |
| 5223 | |
| 5224 | //-------------------------------------------------------------------------------------------------- |
| 5225 | // Data-table CRUD |
no test coverage detected