* @brief Rebuilds the taskbar's full and visible models from the latest dashboard frame. */
| 862 | * @brief Rebuilds the taskbar's full and visible models from the latest dashboard frame. |
| 863 | */ |
| 864 | void UI::Taskbar::rebuildModel() |
| 865 | { |
| 866 | if (m_rebuildInProgress) |
| 867 | return; |
| 868 | |
| 869 | m_focusCycleTimer.stop(); |
| 870 | m_focusCycleQueue.clear(); |
| 871 | |
| 872 | m_rebuildInProgress = true; |
| 873 | { |
| 874 | QSignalBlocker fullBlocker(m_fullModel); |
| 875 | QSignalBlocker taskbarBlocker(m_taskbarButtons); |
| 876 | |
| 877 | for (auto it = m_windowConnections.begin(); it != m_windowConnections.end(); ++it) |
| 878 | disconnect(*it); |
| 879 | |
| 880 | m_windowConnections.clear(); |
| 881 | |
| 882 | m_windowIDs.clear(); |
| 883 | m_fullModel->clear(); |
| 884 | m_activeWindow = nullptr; |
| 885 | m_widgetIdToWindowId.clear(); |
| 886 | m_windowIdToWidgetId.clear(); |
| 887 | if (m_windowManager) |
| 888 | m_windowManager->clear(); |
| 889 | } |
| 890 | |
| 891 | auto* db = &UI::Dashboard::instance(); |
| 892 | |
| 893 | const auto& frame = db->processedFrame(); |
| 894 | if (frame.title.isEmpty() || frame.groups.size() <= 0) { |
| 895 | setActiveGroupId(-1); |
| 896 | Q_EMIT fullModelChanged(); |
| 897 | Q_EMIT windowStatesChanged(); |
| 898 | Q_EMIT registeredWindowsChanged(); |
| 899 | m_rebuildInProgress = false; |
| 900 | return; |
| 901 | } |
| 902 | |
| 903 | QSet<int> groupIds; |
| 904 | for (const DataModel::Group& group : frame.groups) { |
| 905 | const auto groupId = group.groupId; |
| 906 | const auto groupName = group.title; |
| 907 | const auto groupType = SerialStudio::getDashboardWidget(group); |
| 908 | if (SerialStudio::isDashboardTool(groupType)) |
| 909 | continue; |
| 910 | |
| 911 | QList<int> windowIds; |
| 912 | QList<int> relativeIds; |
| 913 | QList<SerialStudio::DashboardWidget> widgetTypes; |
| 914 | collectGroupWidgetIds(groupId, windowIds, relativeIds, widgetTypes); |
| 915 | |
| 916 | int mainWindowId = -1; |
| 917 | for (int i = 0; i < windowIds.count(); ++i) { |
| 918 | if (widgetTypes[i] != groupType) |
| 919 | continue; |
| 920 | |
| 921 | mainWindowId = windowIds[i]; |