* @brief Replaces the widget list of a user workspace with the given IDs. */
| 1793 | * @brief Replaces the widget list of a user workspace with the given IDs. |
| 1794 | */ |
| 1795 | void UI::Taskbar::setWorkspaceWidgets(int workspaceId, const QVariantList& windowIds) |
| 1796 | { |
| 1797 | if (workspaceId < WorkspaceIds::AutoStart) |
| 1798 | return; |
| 1799 | |
| 1800 | auto* pm = &DataModel::ProjectModel::instance(); |
| 1801 | |
| 1802 | const auto& workspaces = pm->activeWorkspaces(); |
| 1803 | bool found = false; |
| 1804 | for (const auto& ws : workspaces) { |
| 1805 | if (ws.workspaceId != workspaceId) |
| 1806 | continue; |
| 1807 | |
| 1808 | found = true; |
| 1809 | for (int i = static_cast<int>(ws.widgetRefs.size()) - 1; i >= 0; --i) |
| 1810 | pm->removeWidgetFromWorkspace(workspaceId, i); |
| 1811 | |
| 1812 | break; |
| 1813 | } |
| 1814 | |
| 1815 | if (!found) |
| 1816 | return; |
| 1817 | |
| 1818 | const auto& widgetMap = UI::Dashboard::instance().widgetMap(); |
| 1819 | for (const auto& idVar : windowIds) { |
| 1820 | const int windowId = idVar.toInt(); |
| 1821 | auto* item = findItemByWindowId(windowId); |
| 1822 | if (!item) |
| 1823 | continue; |
| 1824 | |
| 1825 | const auto widgetType = item->data(TaskbarModel::WidgetTypeRole).toInt(); |
| 1826 | const auto groupId = item->data(TaskbarModel::GroupIdRole).toInt(); |
| 1827 | |
| 1828 | int relIdx = -1; |
| 1829 | for (auto it = widgetMap.begin(); it != widgetMap.end(); ++it) { |
| 1830 | if (it.key() == windowId) { |
| 1831 | relIdx = it.value().second; |
| 1832 | break; |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | if (relIdx >= 0) { |
| 1837 | const int groupUid = UI::Dashboard::instance().groupUniqueIdForGroupId(groupId); |
| 1838 | pm->addWidgetToWorkspace(workspaceId, widgetType, groupUid, relIdx); |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | if (m_activeGroupId == workspaceId) |
| 1843 | setActiveGroupId(workspaceId); |
| 1844 | } |
nothing calls this directly
no test coverage detected