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:
Tobias Hunger
2017-04-05 17:32:36 +02:00
parent 60379856a4
commit 8634aa4cbd
2 changed files with 23 additions and 67 deletions

View File

@@ -292,11 +292,12 @@ ParserTreeItem::ConstPtr Parser::parse()
item = ParserTreeItem::Ptr(new ParserTreeItem());
if (d->flatMode)
addFlatTree(item, prj->rootProjectNode());
addFlatTree(item, prj);
else
addProjectNode(item, prj->rootProjectNode());
addProjectTree(item, prj);
item->setIcon(prj->containerNode()->icon());
item->setIcon(prj->rootProjectNode()->icon());
rootItem->appendChild(item, inf);
}
@@ -698,26 +699,6 @@ void Parser::emitCurrentTree()
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.
\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.
*/
QStringList Parser::addProjectNode(const ParserTreeItem::Ptr &item, const ProjectNode *node)
QStringList Parser::addProjectTree(const ParserTreeItem::Ptr &item, const Project *project)
{
QStringList projectList;
if (!node)
if (!project)
return projectList;
const QString nodePath = node->filePath().toString();
const QString projectPath = project->projectFilePath().toString();
// our own files
QStringList fileList;
CitCachedPrjFileLists cit = d->cachedPrjFileLists.constFind(nodePath);
CitCachedPrjFileLists cit = d->cachedPrjFileLists.constFind(projectPath);
// try to improve parsing speed by internal cache
if (cit != d->cachedPrjFileLists.constEnd()) {
fileList = cit.value();
} else {
fileList = projectNodeFileList(node);
d->cachedPrjFileLists[nodePath] = fileList;
fileList = project->files(Project::SourceFiles);
d->cachedPrjFileLists[projectPath] = fileList;
}
if (fileList.count() > 0) {
addProject(item, fileList, node->filePath().toString());
projectList << node->filePath().toString();
}
// 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);
}
addProject(item, fileList, projectPath);
projectList << projectPath;
}
return projectList;
}
QStringList Parser::getAllFiles(const ProjectNode *node)
QStringList Parser::getAllFiles(const Project *project)
{
QStringList fileList;
if (!node)
if (!project)
return fileList;
const QString nodePath = node->filePath().toString();
const QString nodePath = project->projectFilePath().toString();
CitCachedPrjFileLists cit = d->cachedPrjFileLists.constFind(nodePath);
// try to improve parsing speed by internal cache
if (cit != d->cachedPrjFileLists.constEnd()) {
fileList = cit.value();
} else {
fileList = projectNodeFileList(node);
fileList = project->files(Project::SourceFiles);
d->cachedPrjFileLists[nodePath] = fileList;
}
// subnodes
for (const Node *n : node->nodes())
if (const ProjectNode *project = n->asProjectNode())
fileList += getAllFiles(project);
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;
QStringList fileList = getAllFiles(node);
QStringList fileList = getAllFiles(project);
fileList.removeDuplicates();
if (fileList.count() > 0) {
addProject(item, fileList, node->filePath().toString());
addProject(item, fileList, project->projectFilePath().toString());
}
}