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

Function flattenSwitcherNodes

app/src/UI/Taskbar.cpp:1514–1536  ·  view source on GitHub ↗

* @brief Flattens the switcher tree into leaf workspaces, prefixing each label with its folder * path so nested workspaces stay distinguishable without submenus. */

Source from the content-addressed store, hash-verified

1512 * path so nested workspaces stay distinguishable without submenus.
1513 */
1514static void flattenSwitcherNodes(const QVariantList& nodes,
1515 const QString& prefix,
1516 QVariantList& out)
1517{
1518 for (const auto& value : nodes) {
1519 const auto node = value.toMap();
1520 const auto title = node.value(QStringLiteral("text")).toString();
1521 const bool isFolder = node.value(QStringLiteral("isFolder")).toBool();
1522
1523 if (isFolder) {
1524 const auto branch = prefix.isEmpty() ? title : prefix + QStringLiteral(" / ") + title;
1525 flattenSwitcherNodes(node.value(QStringLiteral("children")).toList(), branch, out);
1526 continue;
1527 }
1528
1529 QVariantMap entry;
1530 entry[QStringLiteral("id")] = node.value(QStringLiteral("id"));
1531 entry[QStringLiteral("text")] =
1532 prefix.isEmpty() ? title : prefix + QStringLiteral(" / ") + title;
1533 entry[QStringLiteral("icon")] = node.value(QStringLiteral("icon"));
1534 out.append(entry);
1535 }
1536}
1537
1538/**
1539 * @brief Returns the cached flat switcher list: empty workspaces removed, a lone root folder

Callers 1

Calls 3

isEmptyMethod · 0.80
valueMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected