2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-08-23 03:47:28 +08:00
|
|
|
#ifndef CLASSBROWSER_H
|
|
|
|
#define CLASSBROWSER_H
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include "parser/cppparser.h"
|
2022-10-23 15:22:26 +08:00
|
|
|
#include "../projectoptions.h"
|
2021-08-23 03:47:28 +08:00
|
|
|
|
|
|
|
struct ClassBrowserNode {
|
|
|
|
ClassBrowserNode* parent;
|
|
|
|
PStatement statement;
|
|
|
|
QVector<ClassBrowserNode *> children;
|
2021-09-26 12:19:46 +08:00
|
|
|
// bool childrenFetched;
|
2021-08-23 03:47:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
using PClassBrowserNode = std::shared_ptr<ClassBrowserNode>;
|
|
|
|
|
2021-10-10 21:23:25 +08:00
|
|
|
class ColorSchemeItem;
|
|
|
|
|
2021-08-23 03:47:28 +08:00
|
|
|
class ClassBrowserModel : public QAbstractItemModel{
|
|
|
|
Q_OBJECT
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
explicit ClassBrowserModel(QObject* parent=nullptr);
|
|
|
|
~ClassBrowserModel();
|
|
|
|
ClassBrowserModel& operator=(const ClassBrowserModel& model) = delete;
|
|
|
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
|
|
|
|
QModelIndex parent(const QModelIndex &child) const override;
|
2021-08-23 17:27:17 +08:00
|
|
|
bool hasChildren(const QModelIndex &parent) const override;
|
2021-08-23 03:47:28 +08:00
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
2021-09-26 12:19:46 +08:00
|
|
|
// void fetchMore(const QModelIndex &parent) override;
|
|
|
|
// bool canFetchMore(const QModelIndex &parent) const override;
|
2021-08-23 03:47:28 +08:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
2021-08-23 17:27:17 +08:00
|
|
|
const PCppParser &parser() const;
|
|
|
|
void setParser(const PCppParser &newCppParser);
|
2021-08-23 03:47:28 +08:00
|
|
|
void clear();
|
2021-08-23 17:27:17 +08:00
|
|
|
const QString ¤tFile() const;
|
|
|
|
void setCurrentFile(const QString &newCurrentFile);
|
|
|
|
void beginUpdate();
|
|
|
|
void endUpdate();
|
|
|
|
|
2021-10-10 21:23:25 +08:00
|
|
|
const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &colors() const;
|
|
|
|
void setColors(const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &newColors);
|
2021-09-25 23:12:36 +08:00
|
|
|
|
2022-10-23 15:22:26 +08:00
|
|
|
ProjectClassBrowserType classBrowserType() const;
|
|
|
|
void setClassBrowserType(ProjectClassBrowserType newClassBrowserType);
|
|
|
|
|
2024-05-28 19:01:18 +08:00
|
|
|
QModelIndex modelIndexForStatement(const QString& key) const;
|
2022-10-23 16:31:05 +08:00
|
|
|
signals:
|
|
|
|
void refreshStarted();
|
|
|
|
void refreshEnd();
|
2021-08-23 03:47:28 +08:00
|
|
|
public slots:
|
|
|
|
void fillStatements();
|
|
|
|
private:
|
2022-10-23 15:22:26 +08:00
|
|
|
PClassBrowserNode addChild(ClassBrowserNode* node, const PStatement& statement);
|
2021-10-20 18:05:43 +08:00
|
|
|
void addMembers();
|
2022-10-23 15:22:26 +08:00
|
|
|
void sortNode(ClassBrowserNode * node);
|
2021-08-23 03:47:28 +08:00
|
|
|
void filterChildren(ClassBrowserNode * node, const StatementMap& statements);
|
2022-10-23 15:22:26 +08:00
|
|
|
PStatement createDummy(const PStatement& statement);
|
|
|
|
ClassBrowserNode* getParentNode(const PStatement &parentStatement, int depth);
|
2023-02-15 16:24:24 +08:00
|
|
|
bool isScopeStatement(const PStatement& statement);
|
2021-08-23 03:47:28 +08:00
|
|
|
private:
|
|
|
|
ClassBrowserNode * mRoot;
|
|
|
|
QHash<QString,PStatement> mDummyStatements;
|
2022-10-23 15:22:26 +08:00
|
|
|
QHash<QString,PClassBrowserNode> mScopeNodes;
|
2022-10-23 16:31:05 +08:00
|
|
|
QHash<QString,PClassBrowserNode> mNodeIndex;
|
|
|
|
QSet<Statement*> mProcessedStatements;
|
2021-08-23 03:47:28 +08:00
|
|
|
QVector<PClassBrowserNode> mNodes;
|
|
|
|
PCppParser mParser;
|
|
|
|
bool mUpdating;
|
|
|
|
int mUpdateCount;
|
2024-05-28 19:01:18 +08:00
|
|
|
mutable QRecursiveMutex mMutex;
|
2021-08-23 03:47:28 +08:00
|
|
|
QString mCurrentFile;
|
2021-10-10 21:23:25 +08:00
|
|
|
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mColors;
|
2022-10-23 15:22:26 +08:00
|
|
|
ProjectClassBrowserType mClassBrowserType;
|
2021-09-26 12:19:46 +08:00
|
|
|
|
2021-08-23 03:47:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CLASSBROWSER_H
|