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
|
|
|
#include "classbrowser.h"
|
|
|
|
#include "../utils.h"
|
2021-08-23 17:27:17 +08:00
|
|
|
#include <QDebug>
|
2021-09-25 23:12:36 +08:00
|
|
|
#include <QColor>
|
|
|
|
#include <QPalette>
|
|
|
|
#include "../mainwindow.h"
|
2021-09-26 16:25:17 +08:00
|
|
|
#include "../settings.h"
|
2021-10-10 21:23:25 +08:00
|
|
|
#include "../colorscheme.h"
|
2021-11-02 23:47:51 +08:00
|
|
|
#include "../utils.h"
|
2021-12-21 07:38:49 +08:00
|
|
|
#include "../iconsmanager.h"
|
2021-08-23 03:47:28 +08:00
|
|
|
|
2022-01-04 16:50:54 +08:00
|
|
|
ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent),
|
|
|
|
mMutex(QMutex::Recursive)
|
2021-08-23 03:47:28 +08:00
|
|
|
{
|
2022-10-24 10:58:30 +08:00
|
|
|
mClassBrowserType = ProjectClassBrowserType::CurrentFile;
|
2021-08-23 03:47:28 +08:00
|
|
|
mRoot = new ClassBrowserNode();
|
|
|
|
mRoot->parent = nullptr;
|
|
|
|
mRoot->statement = PStatement();
|
2021-09-26 12:19:46 +08:00
|
|
|
// mRoot->childrenFetched = true;
|
2021-08-23 03:47:28 +08:00
|
|
|
mUpdating = false;
|
|
|
|
mUpdateCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassBrowserModel::~ClassBrowserModel()
|
|
|
|
{
|
|
|
|
delete mRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex ClassBrowserModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if (!hasIndex(row,column,parent))
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
ClassBrowserNode *parentNode;
|
|
|
|
if (!parent.isValid()) { // top level
|
|
|
|
parentNode = mRoot;
|
|
|
|
} else {
|
|
|
|
parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
|
|
|
|
}
|
|
|
|
return createIndex(row,column,parentNode->children[row]);
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex ClassBrowserModel::parent(const QModelIndex &child) const
|
|
|
|
{
|
2021-08-23 17:27:17 +08:00
|
|
|
if (!child.isValid()) {
|
2021-08-23 03:47:28 +08:00
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
ClassBrowserNode *childNode = static_cast<ClassBrowserNode *>(child.internalPointer());
|
|
|
|
ClassBrowserNode *parentNode = childNode->parent;
|
|
|
|
if (parentNode->parent == nullptr) //it's root node
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
ClassBrowserNode *grandNode = parentNode->parent;
|
|
|
|
int row = grandNode->children.indexOf(parentNode);
|
|
|
|
return createIndex(row,0,parentNode);
|
|
|
|
}
|
|
|
|
|
2021-08-23 17:27:17 +08:00
|
|
|
bool ClassBrowserModel::hasChildren(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
ClassBrowserNode *parentNode;
|
|
|
|
if (!parent.isValid()) { // top level
|
2021-09-26 12:19:46 +08:00
|
|
|
return mRoot->children.count()>0;
|
2021-08-23 17:27:17 +08:00
|
|
|
} else {
|
|
|
|
parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
|
2021-09-26 12:19:46 +08:00
|
|
|
// if (parentNode->childrenFetched)
|
|
|
|
return parentNode->children.count()>0;
|
|
|
|
// if (parentNode->statement)
|
|
|
|
// return !parentNode->statement->children.isEmpty();
|
|
|
|
// return false;
|
2021-08-23 17:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-23 03:47:28 +08:00
|
|
|
int ClassBrowserModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
ClassBrowserNode *parentNode;
|
|
|
|
if (!parent.isValid()) { // top level
|
|
|
|
parentNode = mRoot;
|
|
|
|
} else {
|
|
|
|
parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
|
|
|
|
}
|
|
|
|
return parentNode->children.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ClassBrowserModel::columnCount(const QModelIndex&) const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-09-26 12:19:46 +08:00
|
|
|
//void ClassBrowserModel::fetchMore(const QModelIndex &parent)
|
|
|
|
//{
|
|
|
|
// if (!parent.isValid()) { // top level
|
|
|
|
// return;
|
|
|
|
// }
|
2021-08-23 03:47:28 +08:00
|
|
|
|
2021-09-26 12:19:46 +08:00
|
|
|
// ClassBrowserNode *parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
|
|
|
|
// if (!parentNode->childrenFetched) {
|
|
|
|
// parentNode->childrenFetched = true;
|
|
|
|
// if (parentNode->statement && !parentNode->statement->children.isEmpty()) {
|
|
|
|
// filterChildren(parentNode, parentNode->statement->children);
|
|
|
|
// beginInsertRows(parent,0,parentNode->children.count());
|
|
|
|
// endInsertRows();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
2021-08-23 03:47:28 +08:00
|
|
|
|
2021-09-26 12:19:46 +08:00
|
|
|
//bool ClassBrowserModel::canFetchMore(const QModelIndex &parent) const
|
|
|
|
//{
|
|
|
|
// if (!parent.isValid()) { // top level
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// ClassBrowserNode *parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
|
|
|
|
// if (!parentNode->childrenFetched) {
|
|
|
|
// if (parentNode->statement && !parentNode->statement->children.isEmpty())
|
|
|
|
// return true;
|
|
|
|
// else
|
|
|
|
// parentNode->childrenFetched = true;
|
|
|
|
// }
|
|
|
|
// return false;
|
|
|
|
//}
|
2021-08-23 03:47:28 +08:00
|
|
|
|
|
|
|
QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid()){
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
ClassBrowserNode *node = static_cast<ClassBrowserNode *>(index.internalPointer());
|
|
|
|
if (!node)
|
|
|
|
return QVariant();
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
if (node->statement) {
|
2022-06-23 13:05:10 +08:00
|
|
|
if (!(node->statement->type.isEmpty()) &&
|
|
|
|
((node->statement->kind == StatementKind::skFunction)
|
|
|
|
|| (node->statement->kind == StatementKind::skVariable)
|
|
|
|
|| (node->statement->kind == StatementKind::skTypedef)
|
|
|
|
)) {
|
|
|
|
return node->statement->command + node->statement->args + " : " + node->statement->type;
|
|
|
|
}
|
2021-09-26 12:19:46 +08:00
|
|
|
return node->statement->command + node->statement->args;
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
2021-09-25 23:12:36 +08:00
|
|
|
} else if (role == Qt::ForegroundRole) {
|
2021-10-31 00:08:20 +08:00
|
|
|
if (mColors && node->statement) {
|
2021-09-25 23:12:36 +08:00
|
|
|
PStatement statement = (node->statement);
|
2022-01-27 20:31:44 +08:00
|
|
|
StatementKind kind = getKindOfStatement(statement);
|
2021-09-26 16:25:17 +08:00
|
|
|
if (kind == StatementKind::skKeyword) {
|
|
|
|
if (statement->command.startsWith('#'))
|
|
|
|
kind = StatementKind::skPreprocessor;
|
|
|
|
}
|
2021-10-10 21:23:25 +08:00
|
|
|
PColorSchemeItem item = mColors->value(kind,PColorSchemeItem());
|
2021-11-04 00:57:43 +08:00
|
|
|
if (item) {
|
2021-10-10 21:23:25 +08:00
|
|
|
return item->foreground();
|
2021-11-02 23:47:51 +08:00
|
|
|
} else {
|
2021-11-03 23:27:05 +08:00
|
|
|
return pMainWindow->palette().color(QPalette::Text);
|
2021-10-10 21:23:25 +08:00
|
|
|
}
|
2021-09-25 23:12:36 +08:00
|
|
|
}
|
2021-10-31 00:08:20 +08:00
|
|
|
return pMainWindow->palette().color(QPalette::Text);
|
2021-09-26 12:19:46 +08:00
|
|
|
} else if (role == Qt::DecorationRole) {
|
|
|
|
if (node->statement) {
|
2022-01-27 20:31:44 +08:00
|
|
|
return pIconsManager->getPixmapForStatement(node->statement);
|
2021-09-26 12:19:46 +08:00
|
|
|
}
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2021-08-23 17:27:17 +08:00
|
|
|
const PCppParser &ClassBrowserModel::parser() const
|
2021-08-23 03:47:28 +08:00
|
|
|
{
|
|
|
|
return mParser;
|
|
|
|
}
|
|
|
|
|
2021-08-23 17:27:17 +08:00
|
|
|
void ClassBrowserModel::setParser(const PCppParser &newCppParser)
|
2021-08-23 03:47:28 +08:00
|
|
|
{
|
|
|
|
if (mParser) {
|
|
|
|
disconnect(mParser.get(),
|
|
|
|
&CppParser::onEndParsing,
|
|
|
|
this,
|
|
|
|
&ClassBrowserModel::fillStatements);
|
|
|
|
}
|
|
|
|
mParser = newCppParser;
|
|
|
|
if (mParser) {
|
|
|
|
connect(mParser.get(),
|
|
|
|
&CppParser::onEndParsing,
|
|
|
|
this,
|
|
|
|
&ClassBrowserModel::fillStatements);
|
2022-04-25 12:43:23 +08:00
|
|
|
} else {
|
|
|
|
clear();
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::clear()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
mRoot->children.clear();
|
|
|
|
mNodes.clear();
|
2022-10-23 16:31:05 +08:00
|
|
|
mNodeIndex.clear();
|
|
|
|
mProcessedStatements.clear();
|
2021-08-23 03:47:28 +08:00
|
|
|
mDummyStatements.clear();
|
2022-10-23 15:22:26 +08:00
|
|
|
mScopeNodes.clear();
|
2021-08-23 03:47:28 +08:00
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::fillStatements()
|
|
|
|
{
|
2021-08-23 17:27:17 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mMutex);
|
|
|
|
if (mUpdateCount!=0 || mUpdating)
|
|
|
|
return;
|
|
|
|
mUpdating = true;
|
|
|
|
}
|
2022-10-23 16:31:05 +08:00
|
|
|
emit refreshStarted();
|
2021-08-23 03:47:28 +08:00
|
|
|
beginResetModel();
|
|
|
|
clear();
|
|
|
|
{
|
|
|
|
auto action = finally([this]{
|
|
|
|
endResetModel();
|
|
|
|
mUpdating = false;
|
2022-10-23 16:31:05 +08:00
|
|
|
emit refreshEnd();
|
2021-08-23 03:47:28 +08:00
|
|
|
});
|
|
|
|
if (!mParser)
|
|
|
|
return;
|
|
|
|
if (!mParser->enabled())
|
|
|
|
return;
|
|
|
|
if (!mParser->freeze())
|
|
|
|
return;
|
2022-10-23 15:22:26 +08:00
|
|
|
QString mParserSerialId = mParser->serialId();
|
2022-10-23 21:42:11 +08:00
|
|
|
addMembers();
|
2022-10-23 15:22:26 +08:00
|
|
|
mParser->unFreeze();
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-23 15:22:26 +08:00
|
|
|
PClassBrowserNode ClassBrowserModel::addChild(ClassBrowserNode *node, const PStatement& statement)
|
2021-08-23 03:47:28 +08:00
|
|
|
{
|
|
|
|
PClassBrowserNode newNode = std::make_shared<ClassBrowserNode>();
|
|
|
|
newNode->parent = node;
|
|
|
|
newNode->statement = statement;
|
2021-09-26 12:19:46 +08:00
|
|
|
// newNode->childrenFetched = false;
|
2021-08-23 03:47:28 +08:00
|
|
|
node->children.append(newNode.get());
|
|
|
|
mNodes.append(newNode);
|
2022-10-23 21:42:11 +08:00
|
|
|
mNodeIndex.insert(
|
|
|
|
QString("%1+%2+%3")
|
|
|
|
.arg(statement->fullName)
|
|
|
|
.arg(statement->noNameArgs)
|
|
|
|
.arg((int)statement->kind),newNode);
|
2022-10-23 16:31:05 +08:00
|
|
|
mProcessedStatements.insert(statement.get());
|
2022-10-23 15:22:26 +08:00
|
|
|
if (statement->kind == StatementKind::skClass
|
2022-10-23 21:42:11 +08:00
|
|
|
|| statement->kind == StatementKind::skNamespace) {
|
2022-10-23 15:22:26 +08:00
|
|
|
mScopeNodes.insert(statement->fullName,newNode);
|
2022-10-23 21:42:11 +08:00
|
|
|
}
|
2021-09-26 19:40:52 +08:00
|
|
|
//don't show enum type's children values (they are displayed in parent scope)
|
2022-10-23 15:22:26 +08:00
|
|
|
if (statement->kind != StatementKind::skEnumType) {
|
2021-09-26 19:40:52 +08:00
|
|
|
filterChildren(newNode.get(), statement->children);
|
2022-10-23 15:22:26 +08:00
|
|
|
}
|
|
|
|
return newNode;
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
|
|
|
|
2021-10-20 18:05:43 +08:00
|
|
|
void ClassBrowserModel::addMembers()
|
2021-08-23 03:47:28 +08:00
|
|
|
{
|
2022-10-23 15:22:26 +08:00
|
|
|
if (mClassBrowserType==ProjectClassBrowserType::CurrentFile) {
|
2022-10-23 21:42:11 +08:00
|
|
|
if (mCurrentFile.isEmpty())
|
|
|
|
return;
|
2022-10-23 15:22:26 +08:00
|
|
|
// show statements in the file
|
|
|
|
PFileIncludes p = mParser->findFileIncludes(mCurrentFile);
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
filterChildren(mRoot,p->statements);
|
|
|
|
} else {
|
2022-10-23 21:42:11 +08:00
|
|
|
if (mCurrentFiles.isEmpty())
|
|
|
|
return;
|
2022-10-23 15:22:26 +08:00
|
|
|
foreach(const QString& file,mCurrentFiles) {
|
|
|
|
PFileIncludes p = mParser->findFileIncludes(file);
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
filterChildren(mRoot,p->statements);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sortNode(mRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::sortNode(ClassBrowserNode *node)
|
|
|
|
{
|
|
|
|
if (pSettings->ui().classBrowserSortAlpha()
|
|
|
|
&& pSettings->ui().classBrowserSortType()) {
|
|
|
|
std::sort(node->children.begin(),node->children.end(),
|
|
|
|
[](ClassBrowserNode* node1,ClassBrowserNode* node2) {
|
|
|
|
if (node1->statement->kind < node2->statement->kind) {
|
|
|
|
return true;
|
|
|
|
} else if (node1->statement->kind == node2->statement->kind) {
|
|
|
|
return node1->statement->command.toLower() < node2->statement->command.toLower();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (pSettings->ui().classBrowserSortAlpha()) {
|
|
|
|
std::sort(node->children.begin(),node->children.end(),
|
|
|
|
[](ClassBrowserNode* node1,ClassBrowserNode* node2) {
|
|
|
|
return node1->statement->command.toLower() < node2->statement->command.toLower();
|
|
|
|
});
|
|
|
|
} else if (pSettings->ui().classBrowserSortType()) {
|
|
|
|
std::sort(node->children.begin(),node->children.end(),
|
|
|
|
[](ClassBrowserNode* node1,ClassBrowserNode* node2) {
|
|
|
|
return node1->statement->kind < node2->statement->kind;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
foreach(ClassBrowserNode* child,node->children) {
|
|
|
|
sortNode(child);
|
|
|
|
}
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::filterChildren(ClassBrowserNode *node, const StatementMap &statements)
|
|
|
|
{
|
|
|
|
for (PStatement statement:statements) {
|
2022-10-23 15:22:26 +08:00
|
|
|
if (mClassBrowserType==ProjectClassBrowserType::WholeProject
|
|
|
|
&& !statement->inProject)
|
|
|
|
continue;
|
2022-10-23 16:31:05 +08:00
|
|
|
|
|
|
|
if (mProcessedStatements.contains(statement.get()))
|
|
|
|
continue;
|
|
|
|
|
2021-08-23 03:47:28 +08:00
|
|
|
if (statement->kind == StatementKind::skBlock)
|
|
|
|
continue;
|
2021-09-26 16:25:17 +08:00
|
|
|
if (statement->isInherited && !pSettings->ui().classBrowserShowInherited())
|
2021-08-23 03:47:28 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (statement == node->statement) // prevent infinite recursion
|
|
|
|
continue;
|
|
|
|
|
2022-11-01 09:02:17 +08:00
|
|
|
if (statement->scope == StatementScope::Local)
|
2021-08-23 03:47:28 +08:00
|
|
|
continue;
|
|
|
|
|
2022-10-23 15:22:26 +08:00
|
|
|
if (pSettings->codeCompletion().hideSymbolsStartsWithTwoUnderLine()
|
|
|
|
&& statement->command.startsWith("__"))
|
|
|
|
continue;
|
2021-08-23 03:47:28 +08:00
|
|
|
|
2022-10-23 15:22:26 +08:00
|
|
|
if (pSettings->codeCompletion().hideSymbolsStartsWithUnderLine()
|
|
|
|
&& statement->command.startsWith('_'))
|
|
|
|
continue;
|
2021-08-23 03:47:28 +08:00
|
|
|
|
2022-10-23 21:42:11 +08:00
|
|
|
ClassBrowserNode *parentNode=node;
|
2021-08-23 03:47:28 +08:00
|
|
|
// we only test and handle orphan statements in the top level (node->statement is null)
|
|
|
|
PStatement parentScope = statement->parentScope.lock();
|
2022-10-23 23:24:26 +08:00
|
|
|
if ( (parentScope!=node->statement)
|
2022-10-23 15:22:26 +08:00
|
|
|
&& (!parentScope || !node->statement
|
|
|
|
|| parentScope->fullName!=node->statement->fullName)) {
|
2021-08-23 03:47:28 +08:00
|
|
|
// //should not happend, just in case of error
|
2022-10-23 23:24:26 +08:00
|
|
|
// if (!parentScope)
|
|
|
|
// continue;
|
2021-08-23 03:47:28 +08:00
|
|
|
|
|
|
|
// Processing the orphan statement
|
|
|
|
//the statement's parent is in this file, so it's not a real orphan
|
2022-10-23 23:24:26 +08:00
|
|
|
// if ((parentScope->fileName==mCurrentFile)
|
|
|
|
// ||(parentScope->definitionFileName==mCurrentFile))
|
|
|
|
// continue;
|
2022-10-23 15:22:26 +08:00
|
|
|
|
|
|
|
ClassBrowserNode *dummyNode = getParentNode(parentScope,1);
|
|
|
|
if (dummyNode)
|
2022-10-23 21:42:11 +08:00
|
|
|
parentNode = dummyNode;
|
|
|
|
}
|
|
|
|
if (statement->kind == StatementKind::skNamespace || statement->kind == StatementKind::skClass) {
|
2022-10-23 15:22:26 +08:00
|
|
|
//PStatement dummy = mDummyStatements.value(statement->fullName,PStatement());
|
2022-10-23 23:24:26 +08:00
|
|
|
PClassBrowserNode scopeNode = mScopeNodes.value(statement->fullName,PClassBrowserNode());
|
|
|
|
if (!scopeNode) {
|
2022-10-23 15:22:26 +08:00
|
|
|
PStatement dummy = createDummy(statement);
|
2022-10-23 23:24:26 +08:00
|
|
|
scopeNode = addChild(parentNode,dummy);
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
2022-10-23 23:24:26 +08:00
|
|
|
filterChildren(scopeNode.get(),statement->children);
|
2021-08-23 03:47:28 +08:00
|
|
|
} else {
|
2022-10-23 21:42:11 +08:00
|
|
|
addChild(parentNode,statement);
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
|
|
|
}
|
2021-08-23 11:09:59 +08:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:22:26 +08:00
|
|
|
PStatement ClassBrowserModel::createDummy(const PStatement& statement)
|
2021-08-23 11:09:59 +08:00
|
|
|
{
|
|
|
|
PStatement result = std::make_shared<Statement>();
|
|
|
|
result->parentScope = statement->parentScope;
|
|
|
|
result->command = statement->command;
|
|
|
|
result->args = statement->args;
|
|
|
|
result->noNameArgs = statement->noNameArgs;
|
|
|
|
result->fullName = statement->fullName;
|
|
|
|
result->kind = statement->kind;
|
|
|
|
result->type = statement->type;
|
|
|
|
result->value = statement->value;
|
|
|
|
result->scope = statement->scope;
|
|
|
|
result->classScope = statement->classScope;
|
|
|
|
result->inProject = statement->inProject;
|
|
|
|
result->inSystemHeader = statement->inSystemHeader;
|
|
|
|
result->isStatic = statement->isStatic;
|
|
|
|
result->isInherited = statement->isInherited;
|
|
|
|
result->fileName = mCurrentFile;
|
|
|
|
result->definitionFileName = mCurrentFile;
|
|
|
|
result->line = 0;
|
|
|
|
result->definitionLine = 0;
|
|
|
|
mDummyStatements.insert(result->fullName,result);
|
|
|
|
return result;
|
2021-08-23 03:47:28 +08:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:22:26 +08:00
|
|
|
ClassBrowserNode* ClassBrowserModel::getParentNode(const PStatement &parentStatement, int depth)
|
|
|
|
{
|
|
|
|
if (depth>10)
|
|
|
|
return nullptr;
|
|
|
|
if (!parentStatement)
|
|
|
|
return mRoot;
|
|
|
|
if (parentStatement->kind!=skClass
|
2022-10-23 21:42:11 +08:00
|
|
|
&& parentStatement->kind!=skNamespace) {
|
2022-10-23 15:22:26 +08:00
|
|
|
return mRoot;
|
2022-10-23 21:42:11 +08:00
|
|
|
}
|
2022-10-23 15:22:26 +08:00
|
|
|
PClassBrowserNode parentNode = mScopeNodes.value(parentStatement->fullName,PClassBrowserNode());
|
|
|
|
if (!parentNode) {
|
|
|
|
PStatement dummyParent = createDummy(parentStatement);
|
|
|
|
ClassBrowserNode *grandNode = getParentNode(parentStatement->parentScope.lock(), depth+1);
|
|
|
|
parentNode = addChild(grandNode,dummyParent);
|
|
|
|
}
|
|
|
|
return parentNode.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList &ClassBrowserModel::currentFiles() const
|
|
|
|
{
|
|
|
|
return mCurrentFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::setCurrentFiles(const QStringList &newCurrentFiles)
|
|
|
|
{
|
|
|
|
mCurrentFiles = newCurrentFiles;
|
|
|
|
}
|
|
|
|
|
2022-10-23 21:42:11 +08:00
|
|
|
QModelIndex ClassBrowserModel::modelIndexForStatement(const QString &key)
|
2022-10-23 16:31:05 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mMutex);
|
|
|
|
if (mUpdating)
|
|
|
|
return QModelIndex();
|
2022-10-23 21:42:11 +08:00
|
|
|
PClassBrowserNode node=mNodeIndex.value(key,PClassBrowserNode());
|
2022-10-23 16:31:05 +08:00
|
|
|
if (!node)
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
ClassBrowserNode *parentNode=node->parent;
|
|
|
|
if (!parentNode)
|
|
|
|
return QModelIndex();
|
|
|
|
int row=parentNode->children.indexOf(node.get());
|
|
|
|
if (row<0)
|
|
|
|
return QModelIndex();
|
|
|
|
return createIndex(row,0,node.get());
|
|
|
|
}
|
|
|
|
|
2022-10-23 15:22:26 +08:00
|
|
|
ProjectClassBrowserType ClassBrowserModel::classBrowserType() const
|
|
|
|
{
|
|
|
|
return mClassBrowserType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::setClassBrowserType(ProjectClassBrowserType newClassBrowserType)
|
|
|
|
{
|
|
|
|
if (mClassBrowserType != newClassBrowserType) {
|
|
|
|
beginUpdate();
|
|
|
|
mClassBrowserType = newClassBrowserType;
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-10 21:23:25 +08:00
|
|
|
const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &ClassBrowserModel::colors() const
|
2021-09-25 23:12:36 +08:00
|
|
|
{
|
|
|
|
return mColors;
|
|
|
|
}
|
|
|
|
|
2021-10-10 21:23:25 +08:00
|
|
|
void ClassBrowserModel::setColors(const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &newColors)
|
2021-09-25 23:12:36 +08:00
|
|
|
{
|
|
|
|
mColors = newColors;
|
|
|
|
}
|
|
|
|
|
2021-08-23 17:27:17 +08:00
|
|
|
const QString &ClassBrowserModel::currentFile() const
|
|
|
|
{
|
|
|
|
return mCurrentFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::setCurrentFile(const QString &newCurrentFile)
|
|
|
|
{
|
|
|
|
mCurrentFile = newCurrentFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::beginUpdate()
|
|
|
|
{
|
|
|
|
mUpdateCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassBrowserModel::endUpdate()
|
|
|
|
{
|
|
|
|
mUpdateCount--;
|
|
|
|
if (mUpdateCount == 0) {
|
2021-09-11 18:42:49 +08:00
|
|
|
if (mParser && !mParser->parsing()) {
|
2022-10-23 16:31:05 +08:00
|
|
|
fillStatements();
|
2021-08-23 17:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|