* @brief Appends the Groups subtree (groups, datasets, output widgets) into root. */
| 1598 | * @brief Appends the Groups subtree (groups, datasets, output widgets) into root. |
| 1599 | */ |
| 1600 | void DataModel::ProjectEditor::appendGroupTreeItems(QStandardItem* root, |
| 1601 | QHash<QString, bool>& expandedStates) |
| 1602 | { |
| 1603 | Q_ASSERT(root != nullptr); |
| 1604 | |
| 1605 | const QString q = m_treeSearchQuery.trimmed(); |
| 1606 | const bool filterActive = !q.isEmpty(); |
| 1607 | const auto matches = [&q](const QString& s) { |
| 1608 | return s.contains(q, Qt::CaseInsensitive); |
| 1609 | }; |
| 1610 | |
| 1611 | const auto groupFilteredOut = [&](const DataModel::Group& g, bool groupTitleMatches) { |
| 1612 | if (!filterActive || groupTitleMatches) |
| 1613 | return false; |
| 1614 | |
| 1615 | for (const auto& ds : g.datasets) |
| 1616 | if (matches(ds.title)) |
| 1617 | return false; |
| 1618 | |
| 1619 | return true; |
| 1620 | }; |
| 1621 | |
| 1622 | const auto& groups = DataModel::ProjectModel::instance().groups(); |
| 1623 | const auto& folders = DataModel::ProjectModel::instance().editorGroupFolders(); |
| 1624 | const bool showFolders = !filterActive && !folders.empty(); |
| 1625 | |
| 1626 | bool anyGroup = false; |
| 1627 | for (const auto& group : groups) { |
| 1628 | const bool groupMatches = !filterActive || matches(group.title); |
| 1629 | if (!groupFilteredOut(group, groupMatches)) { |
| 1630 | anyGroup = true; |
| 1631 | break; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | if (!anyGroup && !showFolders) |
| 1636 | return; |
| 1637 | |
| 1638 | auto* groupsRoot = new QStandardItem(tr("Dashboard Widgets")); |
| 1639 | groupsRoot->setData(tr("Dashboard Widgets"), TreeViewText); |
| 1640 | groupsRoot->setData("qrc:/icons/project-editor/treeview/dashboard-widgets.svg", TreeViewIcon); |
| 1641 | groupsRoot->setData(-1, TreeViewFrameIndex); |
| 1642 | groupsRoot->setData(true, TreeViewExpanded); |
| 1643 | |
| 1644 | QHash<int, QStandardItem*> folderItems; |
| 1645 | if (showFolders) |
| 1646 | folderItems = |
| 1647 | appendGroupFolderItems(groupsRoot, root->text() + "/" + groupsRoot->text(), expandedStates); |
| 1648 | |
| 1649 | for (const auto& group : groups) { |
| 1650 | const bool groupMatches = !filterActive || matches(group.title); |
| 1651 | if (groupFilteredOut(group, groupMatches)) |
| 1652 | continue; |
| 1653 | |
| 1654 | auto* groupItem = new QStandardItem(group.title); |
| 1655 | auto icon = SerialStudio::dashboardWidgetIcon(SerialStudio::getDashboardWidget(group), false); |
| 1656 | |
| 1657 | groupItem->setData(icon, TreeViewIcon); |