* @brief Resolves a workspace ref into a stable RefAnchor before a reorder. */
| 3608 | * @brief Resolves a workspace ref into a stable RefAnchor before a reorder. |
| 3609 | */ |
| 3610 | static detail::RefAnchor anchorRef(const DataModel::WidgetRef& r, |
| 3611 | const std::vector<DataModel::Group>& groups) |
| 3612 | { |
| 3613 | detail::RefAnchor a; |
| 3614 | a.widgetType = r.widgetType; |
| 3615 | a.sourceGid = r.groupUniqueId; |
| 3616 | a.datasetFrameIndex = -1; |
| 3617 | a.isGroupOrLed = false; |
| 3618 | |
| 3619 | auto git = std::find_if(groups.begin(), groups.end(), [uid = r.groupUniqueId](const auto& g) { |
| 3620 | return g.uniqueId == uid; |
| 3621 | }); |
| 3622 | if (git == groups.end()) |
| 3623 | return a; |
| 3624 | |
| 3625 | const auto& g = *git; |
| 3626 | const auto groupKey = SerialStudio::getDashboardWidget(g); |
| 3627 | const bool emptyOutPanel = g.groupType == DataModel::GroupType::Output && g.outputWidgets.empty(); |
| 3628 | const bool groupRef = SerialStudio::groupWidgetEligibleForWorkspace(groupKey) && !emptyOutPanel |
| 3629 | && static_cast<int>(groupKey) == r.widgetType; |
| 3630 | const bool ledAggregate = (r.widgetType == static_cast<int>(SerialStudio::DashboardLED)); |
| 3631 | if (groupRef || ledAggregate) { |
| 3632 | a.isGroupOrLed = true; |
| 3633 | return a; |
| 3634 | } |
| 3635 | |
| 3636 | int slot = 0; |
| 3637 | for (const auto& d : g.datasets) { |
| 3638 | const auto keys = SerialStudio::getDashboardWidgets(d); |
| 3639 | for (const auto& k : keys) { |
| 3640 | if (static_cast<int>(k) != r.widgetType) |
| 3641 | continue; |
| 3642 | |
| 3643 | if (!SerialStudio::datasetWidgetEligibleForWorkspace(k)) |
| 3644 | continue; |
| 3645 | |
| 3646 | if (slot == r.relativeIndex) { |
| 3647 | a.datasetFrameIndex = d.index; |
| 3648 | return a; |
| 3649 | } |
| 3650 | |
| 3651 | slot += 1; |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | return a; |
| 3656 | } |
| 3657 | |
| 3658 | /** |
| 3659 | * @brief Re-resolves a RefAnchor into a per-type slot index in the given group. |
no test coverage detected