* @brief Drops every workspace widget ref whose encoded key isn't in validKeys. */
| 5918 | * @brief Drops every workspace widget ref whose encoded key isn't in validKeys. |
| 5919 | */ |
| 5920 | int DataModel::ProjectModel::cleanupWorkspaceWidgetRefs(const QSet<qint64>& validKeys) |
| 5921 | { |
| 5922 | if (AppState::instance().operationMode() != SerialStudio::ProjectFile) |
| 5923 | return 0; |
| 5924 | |
| 5925 | const auto encode = [](int widgetType, int groupId, int relIdx) { |
| 5926 | return (static_cast<qint64>(widgetType) << 40) | (static_cast<qint64>(groupId) << 20) |
| 5927 | | static_cast<qint64>(relIdx); |
| 5928 | }; |
| 5929 | |
| 5930 | int removed = 0; |
| 5931 | for (auto& ws : m_workspaces) { |
| 5932 | auto& refs = ws.widgetRefs; |
| 5933 | const auto it = std::remove_if(refs.begin(), refs.end(), [&](const auto& r) { |
| 5934 | return !validKeys.contains(encode(r.widgetType, r.groupUniqueId, r.relativeIndex)); |
| 5935 | }); |
| 5936 | |
| 5937 | const auto count = std::distance(it, refs.end()); |
| 5938 | if (count > 0) { |
| 5939 | refs.erase(it, refs.end()); |
| 5940 | removed += static_cast<int>(count); |
| 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | if (removed == 0) |
| 5945 | return 0; |
| 5946 | |
| 5947 | if (!m_customizeWorkspaces) |
| 5948 | setCustomizeWorkspaces(true); |
| 5949 | |
| 5950 | setModified(true); |
| 5951 | Q_EMIT editorWorkspacesChanged(); |
| 5952 | Q_EMIT activeWorkspacesChanged(); |
| 5953 | return removed; |
| 5954 | } |
| 5955 | |
| 5956 | /** |
| 5957 | * @brief Returns the title of a workspace, or empty if not found. |
no test coverage detected