RedPanda-CPP/RedPandaIDE/widgets/classbrowser.h

65 lines
2.1 KiB
C
Raw Normal View History

2021-08-23 03:47:28 +08:00
#ifndef CLASSBROWSER_H
#define CLASSBROWSER_H
#include <QAbstractItemModel>
#include "parser/cppparser.h"
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>;
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 &currentFile() const;
void setCurrentFile(const QString &newCurrentFile);
void beginUpdate();
void endUpdate();
2021-09-25 23:12:36 +08:00
const std::shared_ptr<QHash<StatementKind, QColor> > &colors() const;
void setColors(const std::shared_ptr<QHash<StatementKind, QColor> > &newColors);
2021-08-23 03:47:28 +08:00
public slots:
void fillStatements();
private:
void addChild(ClassBrowserNode* node, PStatement statement);
void addMembers(const QSet<QString>& includedFiles);
void filterChildren(ClassBrowserNode * node, const StatementMap& statements);
2021-08-23 11:09:59 +08:00
PStatement createDummy(PStatement statement);
2021-08-23 03:47:28 +08:00
private:
ClassBrowserNode * mRoot;
QHash<QString,PStatement> mDummyStatements;
QVector<PClassBrowserNode> mNodes;
PCppParser mParser;
bool mUpdating;
int mUpdateCount;
QRecursiveMutex mMutex;
QString mCurrentFile;
2021-09-25 23:12:36 +08:00
std::shared_ptr<QHash<StatementKind, QColor>> mColors;
2021-09-26 12:19:46 +08:00
2021-08-23 03:47:28 +08:00
};
#endif // CLASSBROWSER_H