summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/cmakeprojectmanager/fileapidataextractor.cpp7
-rw-r--r--src/plugins/cmakeprojectmanager/projecttreehelper.cpp3
-rw-r--r--src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp11
-rw-r--r--src/plugins/modeleditor/componentviewcontroller.cpp10
-rw-r--r--src/plugins/modeleditor/modelindexer.cpp28
-rw-r--r--src/plugins/projectexplorer/projectnodes.cpp30
-rw-r--r--src/plugins/projectexplorer/projectnodes.h2
-rw-r--r--src/plugins/projectexplorer/projectwizardpage.cpp8
-rw-r--r--src/plugins/qmakeprojectmanager/qmakenodes.cpp4
-rw-r--r--src/plugins/qmakeprojectmanager/qmakenodetreebuilder.cpp3
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeproject.cpp35
-rw-r--r--src/plugins/qmldesigner/documentmanager.cpp7
-rw-r--r--src/plugins/resourceeditor/resourcenode.cpp4
13 files changed, 57 insertions, 95 deletions
diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
index cf60c0b7dc..399ed7385c 100644
--- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
+++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
@@ -497,11 +497,8 @@ FolderNode *createSourceGroupNode(const QString &sourceGroupName,
const QStringList parts = sourceGroupName.split("\\");
for (const QString &p : parts) {
- FolderNode *existingNode = Utils::findOrDefault(currentNode->folderNodes(),
- [&p](const FolderNode *fn) {
- return fn->displayName() == p;
- });
-
+ FolderNode *existingNode = currentNode->findChildFolderNode(
+ [&p](const FolderNode *fn) { return fn->displayName() == p; });
if (!existingNode) {
auto node = createCMakeVFolder(sourceDirectory, Node::DefaultFolderPriority + 5, p);
node->setListInProject(false);
diff --git a/src/plugins/cmakeprojectmanager/projecttreehelper.cpp b/src/plugins/cmakeprojectmanager/projecttreehelper.cpp
index 3fb89d9fec..4069ca6aa1 100644
--- a/src/plugins/cmakeprojectmanager/projecttreehelper.cpp
+++ b/src/plugins/cmakeprojectmanager/projecttreehelper.cpp
@@ -42,8 +42,7 @@ void addCMakeVFolder(FolderNode *base,
base->addNode(std::move(newFolder));
}
folder->addNestedNodes(std::move(files));
- for (FolderNode *fn : folder->folderNodes())
- fn->compress();
+ folder->forEachFolderNode([] (FolderNode *fn) { fn->compress(); });
}
std::vector<std::unique_ptr<FileNode>> &&removeKnownNodes(
diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
index 49712c3206..ad614e7e23 100644
--- a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
+++ b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
@@ -223,13 +223,10 @@ FolderNode *addChildFolderNode(FolderNode *parent, const QString &childName)
FolderNode *addOrGetChildFolderNode(FolderNode *parent, const QString &childName)
{
- for (FolderNode *folder : parent->folderNodes()) {
- if (folder->filePath().fileName() == childName) {
- return folder;
- }
- }
-
- return addChildFolderNode(parent, childName);
+ FolderNode *fn = parent->findChildFolderNode([&](FolderNode *folder) {
+ return folder->filePath().fileName() == childName;
+ });
+ return fn ? fn : addChildFolderNode(parent, childName);
}
// Return the node for folderPath.
diff --git a/src/plugins/modeleditor/componentviewcontroller.cpp b/src/plugins/modeleditor/componentviewcontroller.cpp
index 75495c6684..4071c5b015 100644
--- a/src/plugins/modeleditor/componentviewcontroller.cpp
+++ b/src/plugins/modeleditor/componentviewcontroller.cpp
@@ -29,6 +29,7 @@
// TODO implement removing include dependencies that are not longer used
// TODO refactor add/remove relations between ancestor packages into extra controller class
+using namespace ProjectExplorer;
using namespace Utils;
namespace ModelEditor {
@@ -217,17 +218,16 @@ QStringList UpdateIncludeDependenciesVisitor::findFilePathOfComponent(const qmt:
void UpdateIncludeDependenciesVisitor::collectElementPaths(const ProjectExplorer::FolderNode *folderNode,
QMultiHash<QString, Node> *filePathsMap)
{
- const QList<ProjectExplorer::FileNode *> fileNodes = folderNode->fileNodes();
- for (const ProjectExplorer::FileNode *fileNode : fileNodes) {
+ folderNode->forEachFileNode([&](FileNode *fileNode) {
QString elementName = qmt::NameController::convertFileNameToElementName(fileNode->filePath().toString());
QFileInfo fileInfo = fileNode->filePath().toFileInfo();
QString nodePath = fileInfo.path();
QStringList elementsPath = qmt::NameController::buildElementsPath(nodePath, false);
filePathsMap->insert(elementName, Node(fileNode->filePath().toString(), elementsPath));
- }
- const QList<ProjectExplorer::FolderNode *> subNodes = folderNode->folderNodes();
- for (const ProjectExplorer::FolderNode *subNode : subNodes)
+ });
+ folderNode->forEachFolderNode([&](FolderNode *subNode) {
collectElementPaths(subNode, filePathsMap);
+ });
}
qmt::MComponent *UpdateIncludeDependenciesVisitor::findComponentFromFilePath(const QString &filePath)
diff --git a/src/plugins/modeleditor/modelindexer.cpp b/src/plugins/modeleditor/modelindexer.cpp
index 9923782ac7..d4471fe0ec 100644
--- a/src/plugins/modeleditor/modelindexer.cpp
+++ b/src/plugins/modeleditor/modelindexer.cpp
@@ -34,6 +34,8 @@
#include <QDebug>
#include <QPointer>
+using namespace ProjectExplorer;
+
namespace ModelEditor {
namespace Internal {
@@ -447,18 +449,20 @@ QString ModelIndexer::findFirstModel(ProjectExplorer::FolderNode *folderNode,
{
if (!mimeType.isValid())
return QString();
- const QList<ProjectExplorer::FileNode *> fileNodes = folderNode->fileNodes();
- for (const ProjectExplorer::FileNode *fileNode : fileNodes) {
- if (mimeType.suffixes().contains(fileNode->filePath().completeSuffix()))
- return fileNode->filePath().toString();
- }
- const QList<ProjectExplorer::FolderNode *> subFolderNodes = folderNode->folderNodes();
- for (ProjectExplorer::FolderNode *subFolderNode : subFolderNodes) {
- QString modelFileName = findFirstModel(subFolderNode, mimeType);
- if (!modelFileName.isEmpty())
- return modelFileName;
- }
- return QString();
+
+ const QStringList suffixes = mimeType.suffixes();
+ FileNode *foundFileNode = folderNode->findChildFileNode([&](FileNode *fn) {
+ return suffixes.contains(fn->filePath().completeSuffix());
+ });
+ if (foundFileNode)
+ return foundFileNode->filePath().toString();
+
+ QString modelFileName;
+ folderNode->findChildFolderNode([&](FolderNode *fn) {
+ modelFileName = findFirstModel(fn, mimeType);
+ return !modelFileName.isEmpty();
+ });
+ return modelFileName;
}
void ModelIndexer::forgetProject(ProjectExplorer::Project *project)
diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp
index 4c82852954..e5c8a9a3c6 100644
--- a/src/plugins/projectexplorer/projectnodes.cpp
+++ b/src/plugins/projectexplorer/projectnodes.cpp
@@ -326,14 +326,13 @@ FilePath Node::pathOrDirectory(bool dir) const
FilePath location;
// Virtual Folder case
// If there are files directly below or no subfolders, take the folder path
- if (!folder->fileNodes().isEmpty() || folder->folderNodes().isEmpty()) {
+ auto Any = [](auto) { return true; };
+ if (folder->findChildFileNode(Any) || !folder->findChildFolderNode(Any)) {
location = m_filePath;
} else {
// Otherwise we figure out a commonPath from the subfolders
FilePaths list;
- const QList<FolderNode *> folders = folder->folderNodes();
- for (FolderNode *f : folders)
- list << f->filePath();
+ folder->forEachFolderNode([&](FolderNode *f) { list << f->filePath(); });
location = FileUtils::commonPath(list);
}
@@ -604,16 +603,6 @@ const QList<Node *> FolderNode::nodes() const
return Utils::toRawPointer<QList>(m_nodes);
}
-QList<FileNode *> FolderNode::fileNodes() const
-{
- QList<FileNode *> result;
- for (const std::unique_ptr<Node> &n : m_nodes) {
- if (FileNode *fn = n->asFileNode())
- result.append(fn);
- }
- return result;
-}
-
FileNode *FolderNode::fileNode(const Utils::FilePath &file) const
{
return static_cast<FileNode *>(Utils::findOrDefault(m_nodes,
@@ -623,16 +612,6 @@ FileNode *FolderNode::fileNode(const Utils::FilePath &file) const
}));
}
-QList<FolderNode *> FolderNode::folderNodes() const
-{
- QList<FolderNode *> result;
- for (const std::unique_ptr<Node> &n : m_nodes) {
- if (FolderNode *fn = n->asFolderNode())
- result.append(fn);
- }
- return result;
-}
-
FolderNode *FolderNode::folderNode(const Utils::FilePath &directory) const
{
Node *node = Utils::findOrDefault(m_nodes, [directory](const std::unique_ptr<Node> &n) {
@@ -705,8 +684,7 @@ void FolderNode::compress()
compress();
} else {
- for (FolderNode *fn : folderNodes())
- fn->compress();
+ forEachFolderNode([&](FolderNode *fn) { fn->compress(); });
}
}
diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h
index 3af72aa003..0e0068ba7b 100644
--- a/src/plugins/projectexplorer/projectnodes.h
+++ b/src/plugins/projectexplorer/projectnodes.h
@@ -236,9 +236,7 @@ public:
FolderNode *findChildFolderNode(const std::function<bool (FolderNode *)> &predicate) const; // non-recursive
FileNode *findChildFileNode(const std::function<bool (FileNode *)> &predicate) const; // non-recursive
const QList<Node *> nodes() const;
- QList<FileNode *> fileNodes() const;
FileNode *fileNode(const Utils::FilePath &file) const;
- QList<FolderNode *> folderNodes() const;
FolderNode *folderNode(const Utils::FilePath &directory) const;
using FolderNodeFactory = std::function<std::unique_ptr<FolderNode>(const Utils::FilePath &)>;
diff --git a/src/plugins/projectexplorer/projectwizardpage.cpp b/src/plugins/projectexplorer/projectwizardpage.cpp
index a648eb0981..b13bde370b 100644
--- a/src/plugins/projectexplorer/projectwizardpage.cpp
+++ b/src/plugins/projectexplorer/projectwizardpage.cpp
@@ -245,12 +245,10 @@ static AddNewTree *buildAddFilesTree(FolderNode *root, const FilePaths &files,
Node *contextNode, BestNodeSelector *selector)
{
QList<AddNewTree *> children;
- const QList<FolderNode *> folderNodes = root->folderNodes();
- for (FolderNode *fn : folderNodes) {
- AddNewTree *child = buildAddFilesTree(fn, files, contextNode, selector);
- if (child)
+ root->forEachFolderNode([&](FolderNode *fn) {
+ if (AddNewTree *child = buildAddFilesTree(fn, files, contextNode, selector))
children.append(child);
- }
+ });
if (root->supportsAction(AddNewFile, root) && !root->supportsAction(InheritedFromParent, root)) {
FolderNode::AddNewInformation info = root->addNewInformation(files, contextNode);
diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp
index 4f59d223ce..144a9cc0c9 100644
--- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp
@@ -115,9 +115,7 @@ bool QmakeBuildSystem::supportsAction(Node *context, ProjectAction action, const
const FolderNode *folder = node->asFolderNode();
if (folder) {
FilePaths list;
- const auto folderNodes = folder->folderNodes();
- for (FolderNode *f : folderNodes)
- list << f->filePath();
+ folder->forEachFolderNode([&](FolderNode *f) { list << f->filePath(); });
if (n->deploysFolder(FileUtils::commonPath(list).toString()))
addExistingFiles = false;
}
diff --git a/src/plugins/qmakeprojectmanager/qmakenodetreebuilder.cpp b/src/plugins/qmakeprojectmanager/qmakenodetreebuilder.cpp
index 752cb7c319..528b18c95e 100644
--- a/src/plugins/qmakeprojectmanager/qmakenodetreebuilder.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakenodetreebuilder.cpp
@@ -195,8 +195,7 @@ static void createTree(QmakeBuildSystem *buildSystem,
fileNode->setEnabled(fn.second == FileOrigin::ExactParse);
vfolder->addNestedNode(std::move(fileNode));
}
- for (FolderNode *fn : vfolder->folderNodes())
- fn->compress();
+ vfolder->forEachFolderNode([](FolderNode *fn) { fn->compress(); });
}
node->addNode(std::move(vfolder));
}
diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
index da68b010d5..68494eca6b 100644
--- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
@@ -777,32 +777,25 @@ Tasks QmakeProject::projectIssues(const Kit *k) const
}
// Find the folder that contains a file with a certain name (recurse down)
-static FolderNode *folderOf(FolderNode *in, const FilePath &fileName)
+static FolderNode *folderOf(FolderNode *in, const FilePath &filePath)
{
- const QList<FileNode*> fileNodeList = in->fileNodes();
- for (FileNode *fn : fileNodeList) {
- if (fn->filePath() == fileName)
- return in;
- }
- const QList<FolderNode *> folderNodeList = in->folderNodes();
- for (FolderNode *folder : folderNodeList) {
- if (FolderNode *pn = folderOf(folder, fileName))
- return pn;
- }
- return {};
+ if (in->findChildFileNode([&filePath](FileNode *fn) { return fn->filePath() == filePath; }))
+ return in;
+
+ return in->findChildFolderNode([&filePath](FolderNode *folder) {
+ return folderOf(folder, filePath);
+ });
}
// Find the QmakeProFileNode that contains a certain file.
// First recurse down to folder, then find the pro-file.
-static FileNode *fileNodeOf(FolderNode *in, const FilePath &fileName)
-{
- for (FolderNode *folder = folderOf(in, fileName); folder; folder = folder->parentFolderNode()) {
- if (auto *proFile = dynamic_cast<QmakeProFileNode *>(folder)) {
- const QList<FileNode*> fileNodeList = proFile->fileNodes();
- for (FileNode *fileNode : fileNodeList) {
- if (fileNode->filePath() == fileName)
- return fileNode;
- }
+static FileNode *fileNodeOf(FolderNode *in, const FilePath &filePath)
+{
+ for (FolderNode *folder = folderOf(in, filePath); folder; folder = folder->parentFolderNode()) {
+ if (auto proFile = dynamic_cast<QmakeProFileNode *>(folder)) {
+ return proFile->findChildFileNode([&filePath](FileNode *fn) {
+ return fn->filePath() == filePath;
+ });
}
}
return nullptr;
diff --git a/src/plugins/qmldesigner/documentmanager.cpp b/src/plugins/qmldesigner/documentmanager.cpp
index 9fdf4e4119..e3460622e7 100644
--- a/src/plugins/qmldesigner/documentmanager.cpp
+++ b/src/plugins/qmldesigner/documentmanager.cpp
@@ -32,6 +32,7 @@
#include <QMessageBox>
+using namespace ProjectExplorer;
using namespace Utils;
namespace QmlDesigner {
@@ -413,8 +414,10 @@ void DocumentManager::findPathToIsoProFile(bool *iconResourceFileAlreadyExists,
if (node->isVirtualFolderType() && node->displayName() == "Resources") {
ProjectExplorer::FolderNode *virtualFolderNode = node->asFolderNode();
if (QTC_GUARD(virtualFolderNode)) {
- for (int subFolderIndex = 0; subFolderIndex < virtualFolderNode->folderNodes().size() && !iconQrcFileNode; ++subFolderIndex) {
- ProjectExplorer::FolderNode *subFolderNode = virtualFolderNode->folderNodes().at(subFolderIndex);
+ QList<FolderNode *> folderNodes;
+ virtualFolderNode->forEachFolderNode([&](FolderNode *fn) { folderNodes.append(fn); });
+ for (int subFolderIndex = 0; subFolderIndex < folderNodes.size() && !iconQrcFileNode; ++subFolderIndex) {
+ ProjectExplorer::FolderNode *subFolderNode = folderNodes.at(subFolderIndex);
qCDebug(documentManagerLog) << "Checking if" << subFolderNode->displayName() << "("
<< subFolderNode << ") is" << isoIconsQrcFile;
diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp
index fa0e3b5e4a..d402e3ed89 100644
--- a/src/plugins/resourceeditor/resourcenode.cpp
+++ b/src/plugins/resourceeditor/resourcenode.cpp
@@ -268,9 +268,7 @@ static void compressTree(FolderNode *n)
compressable->compress();
return;
}
- const QList<FolderNode *> childFolders = n->folderNodes();
- for (FolderNode * const c : childFolders)
- compressTree(c);
+ n->forEachFolderNode([](FolderNode *c) { compressTree(c); });
}
void ResourceTopLevelNode::addInternalNodes()