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

Function parseWidgetId

app/src/API/Handlers/WorkspacesHandler.cpp:85–119  ·  view source on GitHub ↗

* @brief Parses a "ws : :g : " string back into its fields. */

Source from the content-addressed store, hash-verified

83 * @brief Parses a "ws<id>:<slug>:g<gid>:<rel>" string back into its fields.
84 */
85[[nodiscard]] static ParsedWidgetId parseWidgetId(const QString& s)
86{
87 ParsedWidgetId out;
88 const auto parts = s.split(QChar(':'));
89 if (parts.size() != 4)
90 return out;
91
92 const auto& wsTok = parts.at(0);
93 const auto& slug = parts.at(1);
94 const auto& gTok = parts.at(2);
95 const auto& rTok = parts.at(3);
96
97 if (!wsTok.startsWith(QStringLiteral("ws")) || !gTok.startsWith(QChar('g')))
98 return out;
99
100 bool wsOk = false;
101 bool gOk = false;
102 bool rOk = false;
103 const int ws = wsTok.mid(2).toInt(&wsOk);
104 const int g = gTok.mid(1).toInt(&gOk);
105 const int r = rTok.toInt(&rOk);
106 if (!wsOk || !gOk || !rOk)
107 return out;
108
109 const int wt = API::EnumLabels::dashboardWidgetFromSlug(slug);
110 if (wt < 0)
111 return out;
112
113 out.workspaceId = ws;
114 out.widgetType = wt;
115 out.groupId = g;
116 out.relativeIndex = r;
117 out.valid = true;
118 return out;
119}
120
121/**
122 * @brief Serialises a workspace's widget refs as a QJsonArray of objects.

Callers 1

widgetRemoveMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected