diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2017-04-05 17:32:36 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2017-04-06 15:51:00 +0000 |
commit | 8634aa4cbd737f01362b6d425feda61efbeb7437 (patch) | |
tree | b00257bed4edb128e95b3e00da08d6521491cad2 /src/plugins/classview | |
parent | 60379856a40dc012948dfcd20e35e532faf8aa1d (diff) | |
download | qt-creator-8634aa4cbd737f01362b6d425feda61efbeb7437.tar.gz |
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>
Diffstat (limited to 'src/plugins/classview')
-rw-r--r-- | src/plugins/classview/classviewparser.cpp | 80 | ||||
-rw-r--r-- | src/plugins/classview/classviewparser.h | 10 |
2 files changed, 23 insertions, 67 deletions
diff --git a/src/plugins/classview/classviewparser.cpp b/src/plugins/classview/classviewparser.cpp index b60140a8c1..e633a6e5f7 100644 --- a/src/plugins/classview/classviewparser.cpp +++ b/src/plugins/classview/classviewparser.cpp @@ -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); } @@ -699,110 +700,69 @@ void Parser::emitCurrentTree() } /*! - 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. 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()); } } diff --git a/src/plugins/classview/classviewparser.h b/src/plugins/classview/classviewparser.h index cb90e4e8c7..918397b3c4 100644 --- a/src/plugins/classview/classviewparser.h +++ b/src/plugins/classview/classviewparser.h @@ -111,13 +111,9 @@ protected: ParserTreeItem::ConstPtr findItemByRoot(const QStandardItem *item, bool skipRoot = false) const; - QStringList addProjectNode(const ParserTreeItem::Ptr &item, - const ProjectExplorer::ProjectNode *node); - QStringList getAllFiles(const ProjectExplorer::ProjectNode *node); - void addFlatTree(const ParserTreeItem::Ptr &item, - const ProjectExplorer::ProjectNode *node); - - QStringList projectNodeFileList(const ProjectExplorer::FolderNode *node) const; + QStringList addProjectTree(const ParserTreeItem::Ptr &item, const ProjectExplorer::Project *project); + QStringList getAllFiles(const ProjectExplorer::Project *project); + void addFlatTree(const ParserTreeItem::Ptr &item, const ProjectExplorer::Project *project); private: //! Private class data pointer |