Commit d8090373 authored by Daniel Teske's avatar Daniel Teske

ProjectNodes: Move (add|remove)(File|Folder)Node to FolderNode

The reason they were on ProjectNode is that the signals are emitted
on the projectnode, but since I moved addFiles and others to FolderNode,
this makes more sense.

Change-Id: I918ca4d93dab78c8bb93dff03f53d1a6fbe21340
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent a6b6a99d
...@@ -313,7 +313,7 @@ void AutotoolsProject::buildFileNodeTree(const QDir &directory, ...@@ -313,7 +313,7 @@ void AutotoolsProject::buildFileNodeTree(const QDir &directory,
// AutotoolsProjectNode::addFileNodes() is a very expensive operation. It is // AutotoolsProjectNode::addFileNodes() is a very expensive operation. It is
// important to collect as much file nodes of the same parent folder as // important to collect as much file nodes of the same parent folder as
// possible before invoking it. // possible before invoking it.
m_rootNode->addFileNodes(fileNodes, oldParentFolder); oldParentFolder->addFileNodes(fileNodes);
fileNodes.clear(); fileNodes.clear();
} }
...@@ -330,7 +330,7 @@ void AutotoolsProject::buildFileNodeTree(const QDir &directory, ...@@ -330,7 +330,7 @@ void AutotoolsProject::buildFileNodeTree(const QDir &directory,
} }
if (!fileNodes.isEmpty()) if (!fileNodes.isEmpty())
m_rootNode->addFileNodes(fileNodes, parentFolder); parentFolder->addFileNodes(fileNodes);
// Remove unused file nodes and empty folder nodes // Remove unused file nodes and empty folder nodes
QHash<QString, Node *>::const_iterator it = nodeHash.constBegin(); QHash<QString, Node *>::const_iterator it = nodeHash.constBegin();
...@@ -338,12 +338,12 @@ void AutotoolsProject::buildFileNodeTree(const QDir &directory, ...@@ -338,12 +338,12 @@ void AutotoolsProject::buildFileNodeTree(const QDir &directory,
if ((*it)->nodeType() == FileNodeType) { if ((*it)->nodeType() == FileNodeType) {
FileNode *fileNode = static_cast<FileNode *>(*it); FileNode *fileNode = static_cast<FileNode *>(*it);
FolderNode* parent = fileNode->parentFolderNode(); FolderNode* parent = fileNode->parentFolderNode();
m_rootNode->removeFileNodes(QList<FileNode *>() << fileNode, parent); parent->removeFileNodes(QList<FileNode *>() << fileNode);
// Remove all empty parent folders // Remove all empty parent folders
while (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) { while (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) {
FolderNode *grandParent = parent->parentFolderNode(); FolderNode *grandParent = parent->parentFolderNode();
m_rootNode->removeFolderNodes(QList<FolderNode *>() << parent, grandParent); grandParent->removeFolderNodes(QList<FolderNode *>() << parent);
parent = grandParent; parent = grandParent;
if (parent == m_rootNode) if (parent == m_rootNode)
break; break;
...@@ -382,7 +382,7 @@ FolderNode *AutotoolsProject::insertFolderNode(const QDir &nodeDir, QHash<QStrin ...@@ -382,7 +382,7 @@ FolderNode *AutotoolsProject::insertFolderNode(const QDir &nodeDir, QHash<QStrin
} }
} }
m_rootNode->addFolderNodes(QList<FolderNode *>() << folder, parentFolder); parentFolder->addFolderNodes(QList<FolderNode *>() << folder);
nodes.insert(nodePath, folder); nodes.insert(nodePath, folder);
return folder; return folder;
......
...@@ -459,18 +459,18 @@ void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer:: ...@@ -459,18 +459,18 @@ void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::
// Get relative path to rootNode // Get relative path to rootNode
QString parentDir = QFileInfo(fn->path()).absolutePath(); QString parentDir = QFileInfo(fn->path()).absolutePath();
ProjectExplorer::FolderNode *folder = findOrCreateFolder(rootNode, parentDir); ProjectExplorer::FolderNode *folder = findOrCreateFolder(rootNode, parentDir);
rootNode->addFileNodes(QList<ProjectExplorer::FileNode *>()<< fn, folder); folder->addFileNodes(QList<ProjectExplorer::FileNode *>()<< fn);
} }
// remove old file nodes and check whether folder nodes can be removed // remove old file nodes and check whether folder nodes can be removed
foreach (ProjectExplorer::FileNode *fn, deleted) { foreach (ProjectExplorer::FileNode *fn, deleted) {
ProjectExplorer::FolderNode *parent = fn->parentFolderNode(); ProjectExplorer::FolderNode *parent = fn->parentFolderNode();
// qDebug()<<"removed"<<fn->path(); // qDebug()<<"removed"<<fn->path();
rootNode->removeFileNodes(QList<ProjectExplorer::FileNode *>() << fn, parent); parent->removeFileNodes(QList<ProjectExplorer::FileNode *>() << fn);
// Check for empty parent // Check for empty parent
while (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) { while (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) {
ProjectExplorer::FolderNode *grandparent = parent->parentFolderNode(); ProjectExplorer::FolderNode *grandparent = parent->parentFolderNode();
rootNode->removeFolderNodes(QList<ProjectExplorer::FolderNode *>() << parent, grandparent); grandparent->removeFolderNodes(QList<ProjectExplorer::FolderNode *>() << parent);
parent = grandparent; parent = grandparent;
if (parent == rootNode) if (parent == rootNode)
break; break;
...@@ -501,7 +501,7 @@ ProjectExplorer::FolderNode *CMakeProject::findOrCreateFolder(CMakeProjectNode * ...@@ -501,7 +501,7 @@ ProjectExplorer::FolderNode *CMakeProject::findOrCreateFolder(CMakeProjectNode *
// No FolderNode yet, so create it // No FolderNode yet, so create it
ProjectExplorer::FolderNode *tmp = new ProjectExplorer::FolderNode(path); ProjectExplorer::FolderNode *tmp = new ProjectExplorer::FolderNode(path);
tmp->setDisplayName(part); tmp->setDisplayName(part);
rootNode->addFolderNodes(QList<ProjectExplorer::FolderNode *>() << tmp, parent); parent->addFolderNodes(QList<ProjectExplorer::FolderNode *>() << tmp);
parent = tmp; parent = tmp;
} }
} }
......
...@@ -103,8 +103,7 @@ void GenericProjectNode::refresh(QSet<QString> oldFileList) ...@@ -103,8 +103,7 @@ void GenericProjectNode::refresh(QSet<QString> oldFileList)
addFileNodes(QList<FileNode *>() addFileNodes(QList<FileNode *>()
<< projectFilesNode << projectFilesNode
<< projectIncludesNode << projectIncludesNode
<< projectConfigNode, << projectConfigNode);
this);
} }
// Do those separately // Do those separately
...@@ -142,7 +141,7 @@ void GenericProjectNode::refresh(QSet<QString> oldFileList) ...@@ -142,7 +141,7 @@ void GenericProjectNode::refresh(QSet<QString> oldFileList)
fileNodes.append(fileNode); fileNodes.append(fileNode);
} }
addFileNodes(fileNodes, folder); folder->addFileNodes(fileNodes);
} }
filesInPaths = sortFilesIntoPaths(baseDir, removed); filesInPaths = sortFilesIntoPaths(baseDir, removed);
...@@ -161,7 +160,7 @@ void GenericProjectNode::refresh(QSet<QString> oldFileList) ...@@ -161,7 +160,7 @@ void GenericProjectNode::refresh(QSet<QString> oldFileList)
fileNodes.append(fn); fileNodes.append(fn);
} }
removeFileNodes(fileNodes, folder); folder->removeFileNodes(fileNodes);
} }
foreach (FolderNode *fn, subFolderNodes()) foreach (FolderNode *fn, subFolderNodes())
...@@ -175,7 +174,7 @@ void GenericProjectNode::removeEmptySubFolders(FolderNode *gparent, FolderNode * ...@@ -175,7 +174,7 @@ void GenericProjectNode::removeEmptySubFolders(FolderNode *gparent, FolderNode *
removeEmptySubFolders(parent, fn); removeEmptySubFolders(parent, fn);
if (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) if (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty())
removeFolderNodes(QList<FolderNode*>() << parent, gparent); gparent->removeFolderNodes(QList<FolderNode*>() << parent);
} }
FolderNode *GenericProjectNode::createFolderByName(const QStringList &components, int end) FolderNode *GenericProjectNode::createFolderByName(const QStringList &components, int end)
...@@ -198,7 +197,7 @@ FolderNode *GenericProjectNode::createFolderByName(const QStringList &components ...@@ -198,7 +197,7 @@ FolderNode *GenericProjectNode::createFolderByName(const QStringList &components
FolderNode *parent = findFolderByName(components, end - 1); FolderNode *parent = findFolderByName(components, end - 1);
if (!parent) if (!parent)
parent = createFolderByName(components, end - 1); parent = createFolderByName(components, end - 1);
addFolderNodes(QList<FolderNode*>() << folder, parent); parent->addFolderNodes(QList<FolderNode*>() << folder);
return folder; return folder;
} }
......
...@@ -146,6 +146,7 @@ public: ...@@ -146,6 +146,7 @@ public:
private: private:
// managed by ProjectNode // managed by ProjectNode
friend class FolderNode;
friend class ProjectNode; friend class ProjectNode;
FileType m_fileType; FileType m_fileType;
...@@ -178,6 +179,12 @@ public: ...@@ -178,6 +179,12 @@ public:
virtual bool deleteFiles(const QStringList &filePaths); virtual bool deleteFiles(const QStringList &filePaths);
virtual bool renameFile(const QString &filePath, const QString &newFilePath); virtual bool renameFile(const QString &filePath, const QString &newFilePath);
void addFileNodes(const QList<FileNode*> &files);
void removeFileNodes(const QList<FileNode*> &files);
void addFolderNodes(const QList<FolderNode*> &subFolders);
void removeFolderNodes(const QList<FolderNode*> &subFolders);
protected: protected:
QList<FolderNode*> m_subFolderNodes; QList<FolderNode*> m_subFolderNodes;
QList<FileNode*> m_fileNodes; QList<FileNode*> m_fileNodes;
...@@ -239,12 +246,6 @@ public: ...@@ -239,12 +246,6 @@ public:
bool isEnabled() const { return true; } bool isEnabled() const { return true; }
void addFolderNodes(const QList<FolderNode*> &subFolders, FolderNode *parentFolder);
void removeFolderNodes(const QList<FolderNode*> &subFolders, FolderNode *parentFolder);
void addFileNodes(const QList<FileNode*> &files, FolderNode *parentFolder);
void removeFileNodes(const QList<FileNode*> &files, FolderNode *parentFolder);
// to be called in implementation of // to be called in implementation of
// the corresponding public functions // the corresponding public functions
void addProjectNodes(const QList<ProjectNode*> &subProjects); void addProjectNodes(const QList<ProjectNode*> &subProjects);
......
...@@ -325,7 +325,7 @@ QbsGroupNode::QbsGroupNode(const qbs::GroupData *grp, const QString &productPath ...@@ -325,7 +325,7 @@ QbsGroupNode::QbsGroupNode(const qbs::GroupData *grp, const QString &productPath
QbsFileNode *idx = new QbsFileNode(grp->location().fileName(), QbsFileNode *idx = new QbsFileNode(grp->location().fileName(),
ProjectExplorer::ProjectFileType, false, ProjectExplorer::ProjectFileType, false,
grp->location().line()); grp->location().line());
addFileNodes(QList<ProjectExplorer::FileNode *>() << idx, this); addFileNodes(QList<ProjectExplorer::FileNode *>() << idx);
updateQbsGroupData(grp, productPath, true, true); updateQbsGroupData(grp, productPath, true, true);
} }
...@@ -435,7 +435,7 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root, ...@@ -435,7 +435,7 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
FolderNode *fn = root->findSubFolder(c->path()); FolderNode *fn = root->findSubFolder(c->path());
if (!fn) { if (!fn) {
fn = new FolderNode(c->path()); fn = new FolderNode(c->path());
root->projectNode()->addFolderNodes(QList<FolderNode *>() << fn, root); root->addFolderNodes(QList<FolderNode *>() << fn);
} else { } else {
foldersToRemove.removeOne(fn); foldersToRemove.removeOne(fn);
if (updateExisting) if (updateExisting)
...@@ -446,9 +446,9 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root, ...@@ -446,9 +446,9 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
setupFolder(fn, c, c->path(), updateExisting); setupFolder(fn, c, c->path(), updateExisting);
} }
} }
root->projectNode()->removeFileNodes(filesToRemove, root); root->removeFileNodes(filesToRemove);
root->projectNode()->removeFolderNodes(foldersToRemove, root); root->removeFolderNodes(foldersToRemove);
root->projectNode()->addFileNodes(filesToAdd, root); root->addFileNodes(filesToAdd);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
...@@ -466,7 +466,7 @@ QbsProductNode::QbsProductNode(const qbs::ProductData &prd) : ...@@ -466,7 +466,7 @@ QbsProductNode::QbsProductNode(const qbs::ProductData &prd) :
ProjectExplorer::FileNode *idx = new QbsFileNode(prd.location().fileName(), ProjectExplorer::FileNode *idx = new QbsFileNode(prd.location().fileName(),
ProjectExplorer::ProjectFileType, false, ProjectExplorer::ProjectFileType, false,
prd.location().line()); prd.location().line());
addFileNodes(QList<ProjectExplorer::FileNode *>() << idx, this); addFileNodes(QList<ProjectExplorer::FileNode *>() << idx);
setQbsProductData(prd); setQbsProductData(prd);
} }
...@@ -656,7 +656,7 @@ void QbsProjectNode::ctor() ...@@ -656,7 +656,7 @@ void QbsProjectNode::ctor()
setIcon(m_projectIcon); setIcon(m_projectIcon);
addFileNodes(QList<ProjectExplorer::FileNode *>() addFileNodes(QList<ProjectExplorer::FileNode *>()
<< new ProjectExplorer::FileNode(path(), ProjectExplorer::ProjectFileType, false), this); << new ProjectExplorer::FileNode(path(), ProjectExplorer::ProjectFileType, false));
} }
QbsProductNode *QbsProjectNode::findProductNode(const QString &name) QbsProductNode *QbsProjectNode::findProductNode(const QString &name)
......
...@@ -384,9 +384,9 @@ struct InternalNode ...@@ -384,9 +384,9 @@ struct InternalNode
} }
// Makes the projectNode's subtree below the given folder match this internal node's subtree // Makes the projectNode's subtree below the given folder match this internal node's subtree
void updateSubFolders(QmakeProjectManager::QmakePriFileNode *projectNode, ProjectExplorer::FolderNode *folder) void updateSubFolders(ProjectExplorer::FolderNode *folder)
{ {
updateFiles(projectNode, folder, type); updateFiles(folder, type);
// updateFolders // updateFolders
QMultiMap<QString, FolderNode *> existingFolderNodes; QMultiMap<QString, FolderNode *> existingFolderNodes;
...@@ -466,16 +466,16 @@ struct InternalNode ...@@ -466,16 +466,16 @@ struct InternalNode
foldersToRemove << jit.value(); foldersToRemove << jit.value();
if (!foldersToRemove.isEmpty()) if (!foldersToRemove.isEmpty())
projectNode->removeFolderNodes(foldersToRemove, folder); folder->removeFolderNodes(foldersToRemove);
if (!foldersToAdd.isEmpty()) if (!foldersToAdd.isEmpty())
projectNode->addFolderNodes(foldersToAdd, folder); folder->addFolderNodes(foldersToAdd);
foreach (const NodePair &np, nodesToUpdate) foreach (const NodePair &np, nodesToUpdate)
np.first->updateSubFolders(projectNode, np.second); np.first->updateSubFolders(np.second);
} }
// Makes the folder's files match this internal node's file list // Makes the folder's files match this internal node's file list
void updateFiles(QmakeProjectManager::QmakePriFileNode *projectNode, FolderNode *folder, FileType type) void updateFiles(FolderNode *folder, FileType type)
{ {
QList<FileNode*> existingFileNodes; QList<FileNode*> existingFileNodes;
foreach (FileNode *fileNode, folder->fileNodes()) { foreach (FileNode *fileNode, folder->fileNodes()) {
...@@ -514,9 +514,9 @@ struct InternalNode ...@@ -514,9 +514,9 @@ struct InternalNode
} }
if (!filesToRemove.isEmpty()) if (!filesToRemove.isEmpty())
projectNode->removeFileNodes(filesToRemove, folder); folder->removeFileNodes(filesToRemove);
if (!filesToAdd.isEmpty()) if (!filesToAdd.isEmpty())
projectNode->addFileNodes(filesToAdd, folder); folder->addFileNodes(filesToAdd);
} }
}; };
} }
...@@ -569,7 +569,7 @@ void QmakePriFileNode::update(ProFile *includeFileExact, QtSupport::ProFileReade ...@@ -569,7 +569,7 @@ void QmakePriFileNode::update(ProFile *includeFileExact, QtSupport::ProFileReade
{ {
// add project file node // add project file node
if (m_fileNodes.isEmpty()) if (m_fileNodes.isEmpty())
addFileNodes(QList<FileNode*>() << new ProjectExplorer::FileNode(m_projectFilePath, ProjectExplorer::ProjectFileType, false), this); addFileNodes(QList<FileNode*>() << new ProjectExplorer::FileNode(m_projectFilePath, ProjectExplorer::ProjectFileType, false));
const QString &projectDir = m_qmakeProFileNode->m_projectDir; const QString &projectDir = m_qmakeProFileNode->m_projectDir;
...@@ -695,7 +695,7 @@ void QmakePriFileNode::update(ProFile *includeFileExact, QtSupport::ProFileReade ...@@ -695,7 +695,7 @@ void QmakePriFileNode::update(ProFile *includeFileExact, QtSupport::ProFileReade
} }
} }
contents.updateSubFolders(this, this); contents.updateSubFolders(this);
} }
void QmakePriFileNode::watchFolders(const QSet<QString> &folders) void QmakePriFileNode::watchFolders(const QSet<QString> &folders)
...@@ -772,7 +772,7 @@ bool QmakePriFileNode::folderChanged(const QString &changedFolder, const QSet<Ut ...@@ -772,7 +772,7 @@ bool QmakePriFileNode::folderChanged(const QString &changedFolder, const QSet<Ut
} }
} }
contents.updateSubFolders(this, this); contents.updateSubFolders(this);
return true; return true;
} }
...@@ -1726,9 +1726,9 @@ void QmakeProFileNode::applyEvaluate(EvalResult evalResult, bool async) ...@@ -1726,9 +1726,9 @@ void QmakeProFileNode::applyEvaluate(EvalResult evalResult, bool async)
return; return;
// delete files && folders && projects // delete files && folders && projects
removeFileNodes(fileNodes(), this); removeFileNodes(fileNodes());
removeProjectNodes(subProjectNodes()); removeProjectNodes(subProjectNodes());
removeFolderNodes(subFolderNodes(), this); removeFolderNodes(subFolderNodes());
// change project type // change project type
QmakeProjectType oldType = m_projectType; QmakeProjectType oldType = m_projectType;
...@@ -1757,9 +1757,9 @@ void QmakeProFileNode::applyEvaluate(EvalResult evalResult, bool async) ...@@ -1757,9 +1757,9 @@ void QmakeProFileNode::applyEvaluate(EvalResult evalResult, bool async)
} }
} }
removeFileNodes(fileNodes(), this); removeFileNodes(fileNodes());
removeProjectNodes(subProjectNodes()); removeProjectNodes(subProjectNodes());
removeFolderNodes(subFolderNodes(), this); removeFolderNodes(subFolderNodes());
bool changesHasBuildTargets = hasBuildTargets() ^ hasBuildTargets(projectType); bool changesHasBuildTargets = hasBuildTargets() ^ hasBuildTargets(projectType);
......
...@@ -69,8 +69,8 @@ void QmlProjectNode::refresh() ...@@ -69,8 +69,8 @@ void QmlProjectNode::refresh()
using namespace ProjectExplorer; using namespace ProjectExplorer;
// remove the existing nodes. // remove the existing nodes.
removeFileNodes(fileNodes(), this); removeFileNodes(fileNodes());
removeFolderNodes(subFolderNodes(), this); removeFolderNodes(subFolderNodes());
//ProjectExplorerPlugin::instance()->setCurrentNode(0); // ### remove me //ProjectExplorerPlugin::instance()->setCurrentNode(0); // ### remove me
...@@ -82,8 +82,7 @@ void QmlProjectNode::refresh() ...@@ -82,8 +82,7 @@ void QmlProjectNode::refresh()
files.removeAll(m_project->filesFileName()); files.removeAll(m_project->filesFileName());
addFileNodes(QList<FileNode *>() addFileNodes(QList<FileNode *>()
<< projectFilesNode, << projectFilesNode);
this);
QHash<QString, QStringList> filesInDirectory; QHash<QString, QStringList> filesInDirectory;
...@@ -118,7 +117,7 @@ void QmlProjectNode::refresh() ...@@ -118,7 +117,7 @@ void QmlProjectNode::refresh()
fileNodes.append(fileNode); fileNodes.append(fileNode);
} }
addFileNodes(fileNodes, folder); folder->addFileNodes(fileNodes);
} }
m_folderByName.clear(); m_folderByName.clear();
...@@ -154,7 +153,7 @@ ProjectExplorer::FolderNode *QmlProjectNode::findOrCreateFolderByName(const QStr ...@@ -154,7 +153,7 @@ ProjectExplorer::FolderNode *QmlProjectNode::findOrCreateFolderByName(const QStr
if (! parent) if (! parent)
parent = this; parent = this;
addFolderNodes(QList<FolderNode*>() << folder, parent); parent->addFolderNodes(QList<FolderNode*>() << folder);
return folder; return folder;
} }
......
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