SILICON
Loading...
Searching...
No Matches
projectTree.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <optional>
21#include <span>
22#include <string>
23#include <string_view>
24
25#include <QTreeWidget>
26
28
29namespace SILICON::ui {
30
33
38
40class ProjectTree : public QTreeWidget {
41 Q_OBJECT
42
43public:
44 explicit ProjectTree(QWidget* parent = nullptr);
45
47 std::span<const project::Document> documents,
48 std::string_view activeDocumentPath = {});
49
50 void selectDocument(std::string_view path);
52
53 [[nodiscard]] QTreeWidgetItem* selectedProjectItem() const;
54 [[nodiscard]] std::optional<ProjectTreeDocumentSelection> selectedDocument() const;
55
56 [[nodiscard]] static ProjectTreeItemKind itemKind(const QTreeWidgetItem* item);
57 [[nodiscard]] static std::optional<project::DocumentType>
58 itemDocumentType(const QTreeWidgetItem* item);
59 [[nodiscard]] static std::optional<project::DocumentCategory>
60 itemDocumentCategory(const QTreeWidgetItem* item);
61 [[nodiscard]] static std::string documentPath(const QTreeWidgetItem* item);
62 [[nodiscard]] static std::string architectureName(const QTreeWidgetItem* item);
63
64private:
65 void addSection(QTreeWidgetItem* projectItem, project::DocumentCategory category,
66 std::span<const project::Document> documents);
67 void addDocument(QTreeWidgetItem* parent, const project::Document& document);
68};
69
70} // namespace SILICON::ui
static std::optional< project::DocumentType > itemDocumentType(const QTreeWidgetItem *item)
static std::string architectureName(const QTreeWidgetItem *item)
void addSection(QTreeWidgetItem *projectItem, project::DocumentCategory category, std::span< const project::Document > documents)
static ProjectTreeItemKind itemKind(const QTreeWidgetItem *item)
void rebuild(const project::ProjectInfo &project, std::span< const project::Document > documents, std::string_view activeDocumentPath={})
static std::string documentPath(const QTreeWidgetItem *item)
void selectDocument(std::string_view path)
QTreeWidgetItem * selectedProjectItem() const
void addDocument(QTreeWidgetItem *parent, const project::Document &document)
static std::optional< project::DocumentCategory > itemDocumentCategory(const QTreeWidgetItem *item)
ProjectTree(QWidget *parent=nullptr)
std::optional< ProjectTreeDocumentSelection > selectedDocument() const
ProjectTreeItemKind
Semantic role of an item shown in the project tree.
Project-level data stored in project.json.