forked from qt-creator/qt-creator
ClassView: Adapt to ProjectTree changes
Use functionality available on Project if possible, thus preventing a crash when trying to work with the rootProjectNode. Task-number: QTCREATORBUG-17977 Change-Id: I397bbf501dc42b306ca88a67a3b2a0c9a9334d92 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -292,11 +292,12 @@ ParserTreeItem::ConstPtr Parser::parse()
|
|||||||
item = ParserTreeItem::Ptr(new ParserTreeItem());
|
item = ParserTreeItem::Ptr(new ParserTreeItem());
|
||||||
|
|
||||||
if (d->flatMode)
|
if (d->flatMode)
|
||||||
addFlatTree(item, prj->rootProjectNode());
|
addFlatTree(item, prj);
|
||||||
else
|
else
|
||||||
addProjectNode(item, prj->rootProjectNode());
|
addProjectTree(item, prj);
|
||||||
|
|
||||||
|
item->setIcon(prj->containerNode()->icon());
|
||||||
|
|
||||||
item->setIcon(prj->rootProjectNode()->icon());
|
|
||||||
rootItem->appendChild(item, inf);
|
rootItem->appendChild(item, inf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,26 +699,6 @@ void Parser::emitCurrentTree()
|
|||||||
emit treeDataUpdate(std);
|
emit treeDataUpdate(std);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Generates a project node file list for the root node \a node.
|
|
||||||
*/
|
|
||||||
|
|
||||||
QStringList Parser::projectNodeFileList(const FolderNode *folderNode) const
|
|
||||||
{
|
|
||||||
QStringList list;
|
|
||||||
folderNode->forEachNode(
|
|
||||||
[&](FileNode *node) {
|
|
||||||
if (!node->isGenerated())
|
|
||||||
list.append(node->filePath().toString());
|
|
||||||
},
|
|
||||||
{},
|
|
||||||
[&](const FolderNode *node) {
|
|
||||||
return node->nodeType() == NodeType::Folder || node->nodeType() == NodeType::VirtualFolder;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Generates projects like the Project Explorer.
|
Generates projects like the Project Explorer.
|
||||||
\a item specifies the item and \a node specifies the root node.
|
\a item specifies the item and \a node specifies the root node.
|
||||||
@@ -725,84 +706,63 @@ QStringList Parser::projectNodeFileList(const FolderNode *folderNode) const
|
|||||||
Returns a list of projects which were added to the item.
|
Returns a list of projects which were added to the item.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QStringList Parser::addProjectNode(const ParserTreeItem::Ptr &item, const ProjectNode *node)
|
QStringList Parser::addProjectTree(const ParserTreeItem::Ptr &item, const Project *project)
|
||||||
{
|
{
|
||||||
QStringList projectList;
|
QStringList projectList;
|
||||||
if (!node)
|
if (!project)
|
||||||
return projectList;
|
return projectList;
|
||||||
|
|
||||||
const QString nodePath = node->filePath().toString();
|
const QString projectPath = project->projectFilePath().toString();
|
||||||
|
|
||||||
// our own files
|
// our own files
|
||||||
QStringList fileList;
|
QStringList fileList;
|
||||||
|
|
||||||
CitCachedPrjFileLists cit = d->cachedPrjFileLists.constFind(nodePath);
|
CitCachedPrjFileLists cit = d->cachedPrjFileLists.constFind(projectPath);
|
||||||
// try to improve parsing speed by internal cache
|
// try to improve parsing speed by internal cache
|
||||||
if (cit != d->cachedPrjFileLists.constEnd()) {
|
if (cit != d->cachedPrjFileLists.constEnd()) {
|
||||||
fileList = cit.value();
|
fileList = cit.value();
|
||||||
} else {
|
} else {
|
||||||
fileList = projectNodeFileList(node);
|
fileList = project->files(Project::SourceFiles);
|
||||||
d->cachedPrjFileLists[nodePath] = fileList;
|
d->cachedPrjFileLists[projectPath] = fileList;
|
||||||
}
|
}
|
||||||
if (fileList.count() > 0) {
|
if (fileList.count() > 0) {
|
||||||
addProject(item, fileList, node->filePath().toString());
|
addProject(item, fileList, projectPath);
|
||||||
projectList << node->filePath().toString();
|
projectList << projectPath;
|
||||||
}
|
|
||||||
|
|
||||||
// subnodes
|
|
||||||
for (const Node *n : node->nodes()) {
|
|
||||||
if (const ProjectNode *project = n->asProjectNode()) {
|
|
||||||
ParserTreeItem::Ptr itemPrj(new ParserTreeItem());
|
|
||||||
SymbolInformation information(project->displayName(), project->filePath().toString());
|
|
||||||
|
|
||||||
projectList += addProjectNode(itemPrj, project);
|
|
||||||
|
|
||||||
itemPrj->setIcon(project->icon());
|
|
||||||
|
|
||||||
// append child if item is not null and there is at least 1 child
|
|
||||||
if (!item.isNull() && itemPrj->childCount() > 0)
|
|
||||||
item->appendChild(itemPrj, information);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectList;
|
return projectList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Parser::getAllFiles(const ProjectNode *node)
|
QStringList Parser::getAllFiles(const Project *project)
|
||||||
{
|
{
|
||||||
QStringList fileList;
|
QStringList fileList;
|
||||||
|
|
||||||
if (!node)
|
if (!project)
|
||||||
return fileList;
|
return fileList;
|
||||||
|
|
||||||
const QString nodePath = node->filePath().toString();
|
const QString nodePath = project->projectFilePath().toString();
|
||||||
|
|
||||||
CitCachedPrjFileLists cit = d->cachedPrjFileLists.constFind(nodePath);
|
CitCachedPrjFileLists cit = d->cachedPrjFileLists.constFind(nodePath);
|
||||||
// try to improve parsing speed by internal cache
|
// try to improve parsing speed by internal cache
|
||||||
if (cit != d->cachedPrjFileLists.constEnd()) {
|
if (cit != d->cachedPrjFileLists.constEnd()) {
|
||||||
fileList = cit.value();
|
fileList = cit.value();
|
||||||
} else {
|
} else {
|
||||||
fileList = projectNodeFileList(node);
|
fileList = project->files(Project::SourceFiles);
|
||||||
d->cachedPrjFileLists[nodePath] = fileList;
|
d->cachedPrjFileLists[nodePath] = fileList;
|
||||||
}
|
}
|
||||||
// subnodes
|
|
||||||
|
|
||||||
for (const Node *n : node->nodes())
|
|
||||||
if (const ProjectNode *project = n->asProjectNode())
|
|
||||||
fileList += getAllFiles(project);
|
|
||||||
return fileList;
|
return fileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::addFlatTree(const ParserTreeItem::Ptr &item, const ProjectNode *node)
|
void Parser::addFlatTree(const ParserTreeItem::Ptr &item, const Project *project)
|
||||||
{
|
{
|
||||||
if (!node)
|
if (!project)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QStringList fileList = getAllFiles(node);
|
QStringList fileList = getAllFiles(project);
|
||||||
fileList.removeDuplicates();
|
fileList.removeDuplicates();
|
||||||
|
|
||||||
if (fileList.count() > 0) {
|
if (fileList.count() > 0) {
|
||||||
addProject(item, fileList, node->filePath().toString());
|
addProject(item, fileList, project->projectFilePath().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,13 +111,9 @@ protected:
|
|||||||
|
|
||||||
ParserTreeItem::ConstPtr findItemByRoot(const QStandardItem *item, bool skipRoot = false) const;
|
ParserTreeItem::ConstPtr findItemByRoot(const QStandardItem *item, bool skipRoot = false) const;
|
||||||
|
|
||||||
QStringList addProjectNode(const ParserTreeItem::Ptr &item,
|
QStringList addProjectTree(const ParserTreeItem::Ptr &item, const ProjectExplorer::Project *project);
|
||||||
const ProjectExplorer::ProjectNode *node);
|
QStringList getAllFiles(const ProjectExplorer::Project *project);
|
||||||
QStringList getAllFiles(const ProjectExplorer::ProjectNode *node);
|
void addFlatTree(const ParserTreeItem::Ptr &item, const ProjectExplorer::Project *project);
|
||||||
void addFlatTree(const ParserTreeItem::Ptr &item,
|
|
||||||
const ProjectExplorer::ProjectNode *node);
|
|
||||||
|
|
||||||
QStringList projectNodeFileList(const ProjectExplorer::FolderNode *node) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Private class data pointer
|
//! Private class data pointer
|
||||||
|
|||||||
Reference in New Issue
Block a user