ACAV f0ba4b7c9529
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
Loading...
Searching...
No Matches
TranslationUnitModel.h
Go to the documentation of this file.
1/*$!{
2* Aurora Clang AST Viewer (ACAV)
3*
4* Copyright (c) 2026 Min Liu
5* Copyright (c) 2026 Michael David Adams
6*
7* SPDX-License-Identifier: GPL-2.0-or-later
8*
9* This program is free software; you can redistribute it and/or modify
10* it under the terms of the GNU General Public License as published by
11* the Free Software Foundation; either version 2 of the License, or
12* (at your option) any later version.
13*
14* This program is distributed in the hope that it will be useful,
15* but WITHOUT ANY WARRANTY; without even the implied warranty of
16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17* GNU General Public License for more details.
18*
19* You should have received a copy of the GNU General Public License along
20* with this program; if not, see <https://www.gnu.org/licenses/>.
21}$!*/
22
25#pragma once
26
27#include "common/FileManager.h"
28#include <QJsonArray>
29#include <QJsonObject>
30#include <QHash>
31#include <QMap>
32#include <QStandardItemModel>
33#include <QString>
34
35namespace acav {
36
47class TranslationUnitModel : public QStandardItemModel {
48 Q_OBJECT
49
50public:
51 explicit TranslationUnitModel(FileManager &fileManager, QObject *parent = nullptr);
52 ~TranslationUnitModel() override = default;
53
54 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
55 bool canFetchMore(const QModelIndex &parent) const override;
56 void fetchMore(const QModelIndex &parent) override;
57
66 void populateFromDependencies(const QJsonObject &dependenciesJson,
67 const QString &overrideProjectRoot = QString(),
68 const QString &compilationDbPath = QString());
69
73 QString getSourceFilePathFromIndex(const QModelIndex &index) const;
74
78 QStringList getIncludedHeadersForSource(const QString &sourceFilePath) const;
79
83 QModelIndex findIndexByFilePath(const QString &filePath) const;
84 QModelIndex findIndexByAnyFilePath(const QString &filePath) const;
85 QModelIndex findIndexByAnyFilePathUnder(const QString &filePath,
86 const QModelIndex &root) const;
87
91 QModelIndex findIndexByFileId(FileID fileId) const;
92
94 void clear();
95
98 QString projectRoot() const { return projectRoot_; }
99
100private:
104 QString computeProjectRoot(const QStringList &sourceFilePaths) const;
105
110 QString computeProjectRootSmart(const QStringList &sourceFilePaths,
111 const QString &compilationDbPath) const;
112
118 void buildDirectoryTree(QStandardItem *parent, const QStringList &filePaths,
119 const QString &rootPath,
120 const QHash<QString, QJsonObject> *fileDataMap);
121
127 void addHeaderCategory(QStandardItem *parent, const QString &categoryName,
128 const QStringList &headers, const QString &rootPath);
129
130 void populateHeadersForSourceItem(QStandardItem *sourceItem);
131
132 FileManager &fileManager_;
133 QString projectRoot_;
134 QHash<QString, QStandardItem *> sourceItemByPath_;
135};
136
137} // namespace acav
Centralized file registry with path-to-FileID mapping.
std::size_t FileID
Type-safe identifier for registered files. 0 is reserved for invalid.
Definition FileManager.h:38
Centralized file registry providing path-to-FileID mapping.
Definition FileManager.h:45
QString projectRoot() const
Get the computed project root directory.
QString getSourceFilePathFromIndex(const QModelIndex &index) const
Get the source file path from a model index.
QModelIndex findIndexByFilePath(const QString &filePath) const
Find model index by file path (legacy method for compatibility).
void clear()
Clear all data from the model.
QModelIndex findIndexByFileId(FileID fileId) const
Find model index by FileID.
QStringList getIncludedHeadersForSource(const QString &sourceFilePath) const
Get all included headers for a source file.
void populateFromDependencies(const QJsonObject &dependenciesJson, const QString &overrideProjectRoot=QString(), const QString &compilationDbPath=QString())
Populate model from query-dependencies JSON output.