/*
* 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 .
*/
#ifndef CLASSBROWSER_H
#define CLASSBROWSER_H
#include
#include "parser/cppparser.h"
#include "../projectoptions.h"
struct ClassBrowserNode {
ClassBrowserNode* parent;
PStatement statement;
QVector children;
// bool childrenFetched;
};
using PClassBrowserNode = std::shared_ptr;
class ColorSchemeItem;
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;
bool hasChildren(const QModelIndex &parent) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
// void fetchMore(const QModelIndex &parent) override;
// bool canFetchMore(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
const PCppParser &parser() const;
void setParser(const PCppParser &newCppParser);
void clear();
const QString ¤tFile() const;
void setCurrentFile(const QString &newCurrentFile);
void beginUpdate();
void endUpdate();
const std::shared_ptr > > &colors() const;
void setColors(const std::shared_ptr > > &newColors);
ProjectClassBrowserType classBrowserType() const;
void setClassBrowserType(ProjectClassBrowserType newClassBrowserType);
QModelIndex modelIndexForStatement(const QString& key);
signals:
void refreshStarted();
void refreshEnd();
public slots:
void fillStatements();
private:
PClassBrowserNode addChild(ClassBrowserNode* node, const PStatement& statement);
void addMembers();
void sortNode(ClassBrowserNode * node);
void filterChildren(ClassBrowserNode * node, const StatementMap& statements);
PStatement createDummy(const PStatement& statement);
ClassBrowserNode* getParentNode(const PStatement &parentStatement, int depth);
private:
ClassBrowserNode * mRoot;
QHash mDummyStatements;
QHash mScopeNodes;
QHash mNodeIndex;
QSet mProcessedStatements;
QVector mNodes;
PCppParser mParser;
bool mUpdating;
int mUpdateCount;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QRecursiveMutex mMutex;
#else
QMutex mMutex;
#endif
QString mCurrentFile;
std::shared_ptr > > mColors;
ProjectClassBrowserType mClassBrowserType;
};
#endif // CLASSBROWSER_H