MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / selectGroupAfterRebuild

Method selectGroupAfterRebuild

app/src/UI/Taskbar.cpp:1092–1140  ·  view source on GitHub ↗

* @brief Selects the saved or first group after a rebuild, or no-ops if none is available. */

Source from the content-addressed store, hash-verified

1090 * @brief Selects the saved or first group after a rebuild, or no-ops if none is available.
1091 */
1092void UI::Taskbar::selectGroupAfterRebuild()
1093{
1094 const auto model = workspaceModel();
1095 if (model.isEmpty())
1096 return;
1097
1098 int targetGroupId = -1;
1099 bool restored = false;
1100
1101 if (m_independentWorkspace) {
1102 const auto inModel = [&model](int gid) {
1103 return gid >= 0 && std::any_of(model.begin(), model.end(), [gid](const QVariant& v) {
1104 return v.toMap().value("id").toInt() == gid;
1105 });
1106 };
1107
1108 if (inModel(m_desiredGroupId)) {
1109 setActiveGroupId(m_desiredGroupId);
1110 return;
1111 }
1112
1113 if (inModel(m_activeGroupId)) {
1114 setActiveGroupId(m_activeGroupId);
1115 return;
1116 }
1117 }
1118
1119 const auto opMode = AppState::instance().operationMode();
1120 if (opMode == SerialStudio::ProjectFile && !m_independentWorkspace) {
1121 auto* pm = &DataModel::ProjectModel::instance();
1122 const int savedId = pm->activeGroupId();
1123 const bool found =
1124 savedId >= 0 && std::any_of(model.begin(), model.end(), [savedId](const QVariant& v) {
1125 return v.toMap().value("id").toInt() == savedId;
1126 });
1127 if (found) {
1128 targetGroupId = savedId;
1129 restored = true;
1130 }
1131 }
1132
1133 if (!restored && model.first().canConvert<QVariantMap>()) {
1134 const QVariantMap firstItem = model.first().toMap();
1135 if (firstItem.contains("id"))
1136 targetGroupId = firstItem["id"].toInt();
1137 }
1138
1139 setActiveGroupId(targetGroupId);
1140}
1141
1142//--------------------------------------------------------------------------------------------------
1143// Utility functions

Callers

nothing calls this directly

Calls 7

isEmptyMethod · 0.80
beginMethod · 0.80
operationModeMethod · 0.80
firstMethod · 0.80
valueMethod · 0.45
activeGroupIdMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected