ClassView: Use visitor-by-lambda

Less code, and avoiding the need to have the temporary
file and folder node lists.

Change-Id: I65e1a7ec022b61f94b01e1e8476bb932d22fd161
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
hjk
2017-02-15 12:52:44 +01:00
parent 4761c3465d
commit 1d686f9aa4

View File

@@ -711,28 +711,19 @@ void Parser::emitCurrentTree()
Generates a project node file list for the root node \a node. Generates a project node file list for the root node \a node.
*/ */
QStringList Parser::projectNodeFileList(const FolderNode *node) const QStringList Parser::projectNodeFileList(const FolderNode *folderNode) const
{ {
QStringList list; QStringList list;
if (!node) folderNode->forEachNode(
return list; [&](FileNode *node) {
if (!node->isGenerated())
QList<FileNode *> fileNodes = node->fileNodes(); list.append(node->filePath().toString());
QList<FolderNode *> subFolderNodes = node->folderNodes(); },
{},
foreach (const FileNode *file, fileNodes) { [&](const FolderNode *node) {
if (file->isGenerated()) return node->nodeType() == NodeType::Folder || node->nodeType() == NodeType::VirtualFolder;
continue; }
);
list << file->filePath().toString();
}
foreach (const FolderNode *folder, subFolderNodes) {
if (folder->nodeType() != NodeType::Folder && folder->nodeType() != NodeType::VirtualFolder)
continue;
list << projectNodeFileList(folder);
}
return list; return list;
} }
@@ -768,19 +759,19 @@ QStringList Parser::addProjectNode(const ParserTreeItem::Ptr &item, const Projec
} }
// subnodes // subnodes
QList<ProjectNode *> projectNodes = node->projectNodes(); for (const Node *n : node->nodes()) {
if (const ProjectNode *project = n->asProjectNode()) {
ParserTreeItem::Ptr itemPrj(new ParserTreeItem());
SymbolInformation information(project->displayName(), project->filePath().toString());
foreach (const ProjectNode *project, projectNodes) { projectList += addProjectNode(itemPrj, project);
ParserTreeItem::Ptr itemPrj(new ParserTreeItem());
SymbolInformation information(project->displayName(), project->filePath().toString());
projectList += addProjectNode(itemPrj, project); itemPrj->setIcon(project->icon());
itemPrj->setIcon(project->icon()); // append child if item is not null and there is at least 1 child
if (!item.isNull() && itemPrj->childCount() > 0)
// append child if item is not null and there is at least 1 child item->appendChild(itemPrj, information);
if (!item.isNull() && itemPrj->childCount() > 0) }
item->appendChild(itemPrj, information);
} }
return projectList; return projectList;
@@ -804,10 +795,10 @@ QStringList Parser::getAllFiles(const ProjectNode *node)
d->cachedPrjFileLists[nodePath] = fileList; d->cachedPrjFileLists[nodePath] = fileList;
} }
// subnodes // subnodes
QList<ProjectNode *> projectNodes = node->projectNodes();
foreach (const ProjectNode *project, projectNodes) for (const Node *n : node->nodes())
fileList += getAllFiles(project); if (const ProjectNode *project = n->asProjectNode())
fileList += getAllFiles(project);
return fileList; return fileList;
} }