* @brief Recursively builds one level of the workspace folder tree, skipping empty workspaces * and folders whose subtree resolves to nothing. */
| 1427 | * and folders whose subtree resolves to nothing. |
| 1428 | */ |
| 1429 | static QVariantList buildWorkspaceTreeLevel(int parentFolderId, |
| 1430 | const std::vector<DataModel::Workspace>& workspaces, |
| 1431 | const std::vector<DataModel::WorkspaceFolder>& folders) |
| 1432 | { |
| 1433 | QVariantList level; |
| 1434 | |
| 1435 | for (const auto& f : folders) { |
| 1436 | if (f.parentFolderId != parentFolderId) |
| 1437 | continue; |
| 1438 | |
| 1439 | const auto children = buildWorkspaceTreeLevel(f.folderId, workspaces, folders); |
| 1440 | if (children.isEmpty()) |
| 1441 | continue; |
| 1442 | |
| 1443 | QVariantMap node; |
| 1444 | node[QStringLiteral("isFolder")] = true; |
| 1445 | node[QStringLiteral("id")] = f.folderId; |
| 1446 | node[QStringLiteral("text")] = f.title; |
| 1447 | node[QStringLiteral("icon")] = QStringLiteral("qrc:/icons/dashboard-small/folder.svg"); |
| 1448 | node[QStringLiteral("children")] = children; |
| 1449 | level.append(node); |
| 1450 | } |
| 1451 | |
| 1452 | for (const auto& ws : workspaces) { |
| 1453 | if (ws.parentFolderId != parentFolderId) |
| 1454 | continue; |
| 1455 | |
| 1456 | if (ws.widgetRefs.empty()) |
| 1457 | continue; |
| 1458 | |
| 1459 | QVariantMap node; |
| 1460 | const auto icon = ws.icon.isEmpty() ? QStringLiteral("qrc:/icons/dashboard-small/workspace.svg") |
| 1461 | : Misc::IconEngine::resolveActionIconSource(ws.icon); |
| 1462 | node[QStringLiteral("isFolder")] = false; |
| 1463 | node[QStringLiteral("id")] = ws.workspaceId; |
| 1464 | node[QStringLiteral("text")] = ws.title; |
| 1465 | node[QStringLiteral("icon")] = icon; |
| 1466 | node[QStringLiteral("children")] = QVariantList(); |
| 1467 | level.append(node); |
| 1468 | } |
| 1469 | |
| 1470 | return level; |
| 1471 | } |
| 1472 | |
| 1473 | /** |
| 1474 | * @brief Returns the workspace switcher model as a folder -> children tree. |
no test coverage detected