1 | /* |
2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
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 <https://www.gnu.org/licenses/>. |
16 | */ |
17 | #ifndef CLASSBROWSER_H |
18 | #define CLASSBROWSER_H |
19 | |
20 | #include <QAbstractItemModel> |
21 | #include "parser/cppparser.h" |
22 | |
23 | struct ClassBrowserNode { |
24 | ClassBrowserNode* parent; |
25 | PStatement statement; |
26 | QVector<ClassBrowserNode *> children; |
27 | // bool childrenFetched; |
28 | }; |
29 | |
30 | using PClassBrowserNode = std::shared_ptr<ClassBrowserNode>; |
31 | |
32 | class ColorSchemeItem; |
33 | |
34 | class ClassBrowserModel : public QAbstractItemModel{ |
35 | Q_OBJECT |
36 | // QAbstractItemModel interface |
37 | public: |
38 | explicit ClassBrowserModel(QObject* parent=nullptr); |
39 | ~ClassBrowserModel(); |
40 | ClassBrowserModel& operator=(const ClassBrowserModel& model) = delete; |
41 | |
42 | QModelIndex index(int row, int column, const QModelIndex &parent) const override; |
43 | QModelIndex parent(const QModelIndex &child) const override; |
44 | bool hasChildren(const QModelIndex &parent) const override; |
45 | int rowCount(const QModelIndex &parent) const override; |
46 | int columnCount(const QModelIndex &parent) const override; |
47 | // void fetchMore(const QModelIndex &parent) override; |
48 | // bool canFetchMore(const QModelIndex &parent) const override; |
49 | QVariant data(const QModelIndex &index, int role) const override; |
50 | const PCppParser &parser() const; |
51 | void setParser(const PCppParser &newCppParser); |
52 | void clear(); |
53 | const QString ¤tFile() const; |
54 | void setCurrentFile(const QString &newCurrentFile); |
55 | void beginUpdate(); |
56 | void endUpdate(); |
57 | |
58 | |
59 | const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &colors() const; |
60 | void setColors(const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &newColors); |
61 | |
62 | public slots: |
63 | void fillStatements(); |
64 | private: |
65 | void addChild(ClassBrowserNode* node, PStatement statement); |
66 | void addMembers(); |
67 | void filterChildren(ClassBrowserNode * node, const StatementMap& statements); |
68 | PStatement createDummy(PStatement statement); |
69 | private: |
70 | ClassBrowserNode * mRoot; |
71 | QHash<QString,PStatement> mDummyStatements; |
72 | QVector<PClassBrowserNode> mNodes; |
73 | PCppParser mParser; |
74 | bool mUpdating; |
75 | int mUpdateCount; |
76 | QMutex mMutex; |
77 | QString mCurrentFile; |
78 | std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mColors; |
79 | |
80 | }; |
81 | |
82 | #endif // CLASSBROWSER_H |
83 | |