Commit 95e2d7f5 authored by hjk's avatar hjk

ProjectExplorer: Remove ProjectNode::m_projectNodes

They are duplicated in m_folderNodes, use them.

Change-Id: I4571720f1ef3daf098870a3cf05fa28a1002bb3f
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent c985914b
......@@ -81,11 +81,6 @@ QList<Node*> FindNodesForFileVisitor::nodes() const
return m_nodes;
}
void FindNodesForFileVisitor::visitProjectNode(ProjectNode *node)
{
visitFolderNode(node);
}
void FindNodesForFileVisitor::visitFolderNode(FolderNode *node)
{
if (node->filePath() == m_path)
......@@ -96,11 +91,6 @@ void FindNodesForFileVisitor::visitFolderNode(FolderNode *node)
}
}
void FindNodesForFileVisitor::visitSessionNode(SessionNode *node)
{
visitFolderNode(node);
}
/*!
\class FindAllFilesVisitor
......@@ -112,11 +102,6 @@ Utils::FileNameList FindAllFilesVisitor::filePaths() const
return m_filePaths;
}
void FindAllFilesVisitor::visitProjectNode(ProjectNode *projectNode)
{
visitFolderNode(projectNode);
}
void FindAllFilesVisitor::visitFolderNode(FolderNode *folderNode)
{
m_filePaths.append(folderNode->filePath());
......
......@@ -36,15 +36,13 @@ namespace ProjectExplorer {
class Node;
class FileNode;
class SessionNode;
class ProjectNode;
class FolderNode;
class PROJECTEXPLORER_EXPORT NodesVisitor {
class PROJECTEXPLORER_EXPORT NodesVisitor
{
public:
virtual ~NodesVisitor();
virtual void visitSessionNode(SessionNode *) { }
virtual void visitProjectNode(ProjectNode *) { }
virtual void visitFolderNode(FolderNode *) { }
protected:
......@@ -53,26 +51,25 @@ protected:
/* useful visitors */
class PROJECTEXPLORER_EXPORT FindNodesForFileVisitor : public NodesVisitor {
class PROJECTEXPLORER_EXPORT FindNodesForFileVisitor : public NodesVisitor
{
public:
explicit FindNodesForFileVisitor(const Utils::FileName &fileToSearch);
QList<Node*> nodes() const;
void visitProjectNode(ProjectNode *node) override;
void visitFolderNode(FolderNode *node) override;
void visitSessionNode(SessionNode *node) override;
private:
Utils::FileName m_path;
QList<Node *> m_nodes;
};
class PROJECTEXPLORER_EXPORT FindAllFilesVisitor : public NodesVisitor {
class PROJECTEXPLORER_EXPORT FindAllFilesVisitor : public NodesVisitor
{
public:
Utils::FileNameList filePaths() const;
void visitProjectNode(ProjectNode *projectNode) override;
void visitFolderNode(FolderNode *folderNode) override;
private:
......
......@@ -686,24 +686,24 @@ QList<RunConfiguration *> ProjectNode::runConfigurations() const
return QList<RunConfiguration *>();
}
void ProjectNode::accept(NodesVisitor *visitor)
{
visitor->visitProjectNode(this);
foreach (FolderNode *folder, m_folderNodes)
folder->accept(visitor);
}
ProjectNode *ProjectNode::projectNode(const Utils::FileName &file) const
{
return Utils::findOrDefault(m_projectNodes, [&file](const ProjectNode *fn) {
return fn->filePath() == file;
});
for (FolderNode *node : m_folderNodes) {
if (ProjectNode *pnode = node->asProjectNode())
if (pnode->filePath() == file)
return pnode;
}
return nullptr;
}
QList<ProjectNode*> ProjectNode::projectNodes() const
QList<ProjectNode*> FolderNode::projectNodes() const
{
return m_projectNodes;
QList<ProjectNode *> nodes;
for (FolderNode *node : m_folderNodes) {
if (ProjectNode *pnode = node->asProjectNode())
nodes.append(pnode);
}
return nodes;
}
/*!
......@@ -717,31 +717,13 @@ void ProjectNode::addProjectNode(ProjectNode *subProject)
subProject->setParentFolderNode(this);
m_folderNodes.append(subProject);
m_projectNodes.append(subProject);
Utils::sort(m_folderNodes);
Utils::sort(m_projectNodes);
}
/*!
Removes all child nodes from the node hierarchy and deletes them.
*/
void ProjectNode::makeEmpty()
bool FolderNode::isEmpty() const
{
foreach (ProjectNode *subProject, m_projectNodes)
m_folderNodes.removeAll(subProject);
qDeleteAll(m_projectNodes);
m_projectNodes.clear();
FolderNode::makeEmpty();
}
bool ProjectNode::isEmpty() const
{
return m_fileNodes.isEmpty() && m_folderNodes.isEmpty() && m_projectNodes.isEmpty();
return m_fileNodes.isEmpty() && m_folderNodes.isEmpty();
}
/*!
......@@ -758,24 +740,11 @@ QList<ProjectAction> SessionNode::supportedActions(Node *node) const
return QList<ProjectAction>();
}
void SessionNode::accept(NodesVisitor *visitor)
{
visitor->visitSessionNode(this);
foreach (ProjectNode *project, m_projectNodes)
project->accept(visitor);
}
bool SessionNode::showInSimpleTree() const
{
return true;
}
QList<ProjectNode*> SessionNode::projectNodes() const
{
return m_projectNodes;
}
QString SessionNode::addFileFilter() const
{
return QString::fromLatin1("*.c; *.cc; *.cpp; *.cp; *.cxx; *.c++; *.h; *.hh; *.hpp; *.hxx;");
......@@ -787,16 +756,12 @@ void SessionNode::addProjectNode(ProjectNode *projectNode)
qDebug("Project node has already a parent folder"));
projectNode->setParentFolderNode(this);
m_folderNodes.append(projectNode);
m_projectNodes.append(projectNode);
Utils::sort(m_folderNodes);
Utils::sort(m_projectNodes);
}
void SessionNode::removeProjectNode(ProjectNode *projectNode)
{
m_folderNodes.removeOne(projectNode);
m_projectNodes.removeOne(projectNode);
}
} // namespace ProjectExplorer
......@@ -251,6 +251,9 @@ public:
void addFolderNode(FolderNode *subFolder);
void setFolderNodes(const QList<FolderNode*> &folders);
// all subFolders that are projects
QList<ProjectNode*> projectNodes() const;
void makeEmpty();
bool isEmpty() const;
......@@ -296,16 +299,8 @@ public:
virtual QList<RunConfiguration *> runConfigurations() const;
void accept(NodesVisitor *visitor) override;
ProjectNode *projectNode(const Utils::FileName &file) const;
// all subFolders that are projects
QList<ProjectNode*> projectNodes() const;
void addProjectNode(ProjectNode *subProject);
void removeProjectNode(ProjectNode *subProject);
void makeEmpty();
bool isEmpty() const;
ProjectNode *asProjectNode() final { return this; }
const ProjectNode *asProjectNode() const final { return this; }
......@@ -316,8 +311,6 @@ protected:
explicit ProjectNode(const Utils::FileName &projectFilePath);
private:
QList<ProjectNode*> m_projectNodes;
// let SessionNode call setParentFolderNode
friend class SessionNode;
};
......@@ -327,12 +320,10 @@ class PROJECTEXPLORER_EXPORT SessionNode : public FolderNode
{
public:
SessionNode();
QList<ProjectNode*> projectNodes() const;
private:
QList<ProjectAction> supportedActions(Node *node) const final;
QString addFileFilter() const final;
void accept(NodesVisitor *visitor) final;
bool showInSimpleTree() const final;
void projectDisplayNameChanged(Node *node);
......@@ -343,8 +334,6 @@ private:
friend class SessionManager;
void addProjectNode(ProjectNode *projectNode);
void removeProjectNode(ProjectNode *projectNode);
QList<ProjectNode*> m_projectNodes;
};
} // namespace ProjectExplorer
......
......@@ -36,8 +36,8 @@ QList<QmakeProFileNode *> FindQmakeProFiles::operator()(ProjectExplorer::Project
return m_proFiles;
}
void FindQmakeProFiles::visitProjectNode(ProjectExplorer::ProjectNode *projectNode)
void FindQmakeProFiles::visitFolderNode(ProjectExplorer::FolderNode *folderNode)
{
if (QmakeProFileNode *pro = dynamic_cast<QmakeProFileNode *>(projectNode))
if (QmakeProFileNode *pro = dynamic_cast<QmakeProFileNode *>(folderNode))
m_proFiles.append(pro);
}
......@@ -27,6 +27,8 @@
#include <projectexplorer/nodesvisitor.h>
namespace ProjectExplorer { class ProjectNode; }
namespace QmakeProjectManager {
class QmakeProFileNode;
namespace Internal {
......@@ -36,7 +38,7 @@ class FindQmakeProFiles: protected ProjectExplorer::NodesVisitor
public:
QList<QmakeProFileNode *> operator()(ProjectExplorer::ProjectNode *root);
protected:
virtual void visitProjectNode(ProjectExplorer::ProjectNode *projectNode);
void visitFolderNode(ProjectExplorer::FolderNode *folderNode) final;
private:
QList<QmakeProFileNode *> m_proFiles;
};
......
......@@ -1391,18 +1391,15 @@ static QmakeProjectType proFileTemplateTypeToProjectType(ProFileEvaluator::Templ
namespace {
// feed all files accepted by any of the factories to the callback.
class FindGeneratorSourcesVisitor : public NodesVisitor {
class FindGeneratorSourcesVisitor : public NodesVisitor
{
public:
FindGeneratorSourcesVisitor(
const QList<ProjectExplorer::ExtraCompilerFactory *> &factories,
std::function<void(FileNode *, ProjectExplorer::ExtraCompilerFactory *)> callback) :
factories(factories), callback(callback) {}
void visitProjectNode(ProjectNode *projectNode)
{
visitFolderNode(projectNode);
}
void visitFolderNode(FolderNode *folderNode)
void visitFolderNode(FolderNode *folderNode) final
{
foreach (FileNode *fileNode, folderNode->fileNodes()) {
foreach (ProjectExplorer::ExtraCompilerFactory *factory, factories) {
......
......@@ -161,11 +161,9 @@ class ProjectFilesVisitor : public NodesVisitor
ProjectFilesVisitor(QmakeProjectFiles *files);
public:
static void findProjectFiles(QmakeProFileNode *rootNode, QmakeProjectFiles *files);
void visitProjectNode(ProjectNode *projectNode);
void visitFolderNode(FolderNode *folderNode);
void visitFolderNode(FolderNode *folderNode) final;
private:
QmakeProjectFiles *m_files;
......@@ -199,14 +197,10 @@ void ProjectFilesVisitor::findProjectFiles(QmakeProFileNode *rootNode, QmakeProj
unique(files->proFiles);
}
void ProjectFilesVisitor::visitProjectNode(ProjectNode *projectNode)
{
m_files->proFiles.append(projectNode->filePath().toString());
visitFolderNode(projectNode);
}
void ProjectFilesVisitor::visitFolderNode(FolderNode *folderNode)
{
if (ProjectNode *projectNode = folderNode->asProjectNode())
m_files->proFiles.append(projectNode->filePath().toString());
if (dynamic_cast<ResourceEditor::ResourceTopLevelNode *>(folderNode))
m_files->files[static_cast<int>(FileType::Resource)].push_back(folderNode->filePath().toString());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment