summaryrefslogtreecommitdiff
path: root/src/plugins/autotoolsprojectmanager
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@theqtcompany.com>2016-09-30 21:10:32 +0200
committerTobias Hunger <tobias.hunger@qt.io>2016-10-05 15:42:55 +0000
commit27a2ebb0d7cc8328e1383008e36ad0cc01ff0446 (patch)
tree4c9c3b62c26b83ecf2363195647cba1b3a4dde67 /src/plugins/autotoolsprojectmanager
parent69627e494ba539c1463b511fdc898ff95f550b51 (diff)
downloadqt-creator-27a2ebb0d7cc8328e1383008e36ad0cc01ff0446.tar.gz
Autotools: Use foldernode helpers to construct project tree
Change-Id: Id0eaebb4035e8bd2fb29cc4f0317151ab00dcce6 Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/autotoolsprojectmanager')
-rw-r--r--src/plugins/autotoolsprojectmanager/autotoolsproject.cpp148
-rw-r--r--src/plugins/autotoolsprojectmanager/autotoolsproject.h19
-rw-r--r--src/plugins/autotoolsprojectmanager/autotoolsprojectnode.cpp4
-rw-r--r--src/plugins/autotoolsprojectmanager/autotoolsprojectnode.h2
4 files changed, 13 insertions, 160 deletions
diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp
index 3470bf15d6..b66b37c106 100644
--- a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp
+++ b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp
@@ -52,6 +52,7 @@
#include <coreplugin/icontext.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
+#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <utils/filesystemwatcher.h>
@@ -74,7 +75,7 @@ AutotoolsProject::AutotoolsProject(AutotoolsManager *manager, const QString &fil
setId(Constants::AUTOTOOLS_PROJECT_ID);
setProjectManager(manager);
setDocument(new AutotoolsProjectFile(fileName));
- setRootProjectNode(new AutotoolsProjectNode(projectFilePath()));
+ setRootProjectNode(new AutotoolsProjectNode(projectDirectory()));
setProjectContext(Core::Context(Constants::PROJECT_CONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
@@ -218,7 +219,14 @@ void AutotoolsProject::makefileParsingFinished()
m_watchedFiles.append(configureAcFilePath);
}
- buildFileNodeTree(dir, files);
+ QList<FileNode *> fileNodes = Utils::transform(files, [dir](const QString &f) {
+ const Utils::FileName path = Utils::FileName::fromString(dir.absoluteFilePath(f));
+ return new FileNode(path,
+ (f == QLatin1String("Makefile.am") || f == QLatin1String("configure.ac"))
+ ? ProjectFileType : ResourceType, false);
+ });
+ rootProjectNode()->buildTree(fileNodes);
+
updateCppCodeModel();
m_makefileParserThread->deleteLater();
@@ -239,142 +247,6 @@ QStringList AutotoolsProject::buildTargets() const
return targets;
}
-void AutotoolsProject::buildFileNodeTree(const QDir &directory,
- const QStringList &files)
-{
- // Get all existing nodes and remember them in a hash table.
- // This allows to reuse existing nodes and to remove obsolete
- // nodes later.
- QHash<QString, Node *> nodeHash;
- foreach (Node *node, nodes(rootProjectNode()))
- nodeHash.insert(node->filePath().toString(), node);
-
- // Add the sources to the filenode project tree. Sources
- // inside the same directory are grouped into a folder-node.
- const QString baseDir = directory.absolutePath();
-
- QList<FileNode *> fileNodes;
- FolderNode *parentFolder = 0;
- FolderNode *oldParentFolder = 0;
-
- foreach (const QString &file, files) {
- if (file.endsWith(QLatin1String(".moc")))
- continue;
-
- QString subDir = baseDir + QLatin1Char('/') + file;
- const int lastSlashPos = subDir.lastIndexOf(QLatin1Char('/'));
- if (lastSlashPos != -1)
- subDir.truncate(lastSlashPos);
-
- // Add folder nodes, that are not already available
- oldParentFolder = parentFolder;
- parentFolder = 0;
- if (nodeHash.contains(subDir)) {
- QTC_ASSERT(nodeHash[subDir]->nodeType() == FolderNodeType, return);
- parentFolder = static_cast<FolderNode *>(nodeHash[subDir]);
- } else {
- parentFolder = insertFolderNode(QDir(subDir), nodeHash);
- if (parentFolder == 0) {
- // No node gets created for the root folder
- parentFolder = rootProjectNode();
- }
- }
- QTC_ASSERT(parentFolder, return);
- if (oldParentFolder && (oldParentFolder != parentFolder) && !fileNodes.isEmpty()) {
- // AutotoolsProjectNode::addFileNodes() is a very expensive operation. It is
- // important to collect as much file nodes of the same parent folder as
- // possible before invoking it.
- oldParentFolder->addFileNodes(fileNodes);
- fileNodes.clear();
- }
-
- // Add file node
- const QString filePath = directory.absoluteFilePath(file);
- if (nodeHash.contains(filePath)) {
- nodeHash.remove(filePath);
- } else if (file == QLatin1String("Makefile.am") || file == QLatin1String("configure.ac")) {
- fileNodes.append(new FileNode(Utils::FileName::fromString(filePath),
- ProjectFileType, false));
- } else {
- fileNodes.append(new FileNode(Utils::FileName::fromString(filePath),
- ResourceType, false));
- }
- }
-
- if (parentFolder && !fileNodes.isEmpty())
- parentFolder->addFileNodes(fileNodes);
-
- // Remove unused file nodes and empty folder nodes
- QHash<QString, Node *>::const_iterator it = nodeHash.constBegin();
- while (it != nodeHash.constEnd()) {
- if ((*it)->nodeType() == FileNodeType) {
- FileNode *fileNode = static_cast<FileNode *>(*it);
- FolderNode* parent = fileNode->parentFolderNode();
- parent->removeFileNodes(QList<FileNode *>() << fileNode);
-
- // Remove all empty parent folders
- while (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) {
- FolderNode *grandParent = parent->parentFolderNode();
- grandParent->removeFolderNodes(QList<FolderNode *>() << parent);
- parent = grandParent;
- if (parent == rootProjectNode())
- break;
- }
- }
- ++it;
- }
-}
-
-FolderNode *AutotoolsProject::insertFolderNode(const QDir &nodeDir, QHash<QString, Node *> &nodes)
-{
- const Utils::FileName nodePath = Utils::FileName::fromString(nodeDir.absolutePath());
- QFileInfo rootInfo = rootProjectNode()->filePath().toFileInfo();
- const Utils::FileName rootPath = Utils::FileName::fromString(rootInfo.absolutePath());
-
- // Do not create a folder for the root node
- if (rootPath == nodePath)
- return 0;
-
- FolderNode *folder = new FolderNode(nodePath);
- QDir dir(nodeDir);
- folder->setDisplayName(dir.dirName());
-
- // Get parent-folder. If it does not exist, create it recursively.
- // Take care that the m_rootNode is considered as top folder.
- FolderNode *parentFolder = rootProjectNode();
- if ((rootPath != folder->filePath()) && dir.cdUp()) {
- const QString parentDir = dir.absolutePath();
- if (!nodes.contains(parentDir)) {
- FolderNode *insertedFolder = insertFolderNode(parentDir, nodes);
- if (insertedFolder != 0)
- parentFolder = insertedFolder;
- } else {
- QTC_ASSERT(nodes[parentDir]->nodeType() == FolderNodeType, return 0);
- parentFolder = static_cast<FolderNode *>(nodes[parentDir]);
- }
- }
-
- parentFolder->addFolderNodes(QList<FolderNode *>() << folder);
- nodes.insert(nodePath.toString(), folder);
-
- return folder;
-}
-
-QList<Node *> AutotoolsProject::nodes(FolderNode *parent) const
-{
- QList<Node *> list;
- QTC_ASSERT(parent != 0, return list);
-
- foreach (FolderNode *folder, parent->subFolderNodes()) {
- list.append(nodes(folder));
- list.append(folder);
- }
- foreach (FileNode *file, parent->fileNodes())
- list.append(file);
-
- return list;
-}
-
static QStringList filterIncludes(const QString &absSrc, const QString &absBuild,
const QStringList &in)
{
diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.h b/src/plugins/autotoolsprojectmanager/autotoolsproject.h
index e43ee163e0..d98686a81f 100644
--- a/src/plugins/autotoolsprojectmanager/autotoolsproject.h
+++ b/src/plugins/autotoolsprojectmanager/autotoolsproject.h
@@ -103,25 +103,6 @@ private:
void onFileChanged(const QString &file);
/**
- * Creates folder-nodes and file-nodes for the project tree.
- */
- void buildFileNodeTree(const QDir &directory,
- const QStringList &files);
-
- /**
- * Helper function for buildFileNodeTree(): Inserts a new folder-node for
- * the directory \p nodeDir and inserts it into \p nodes. If no parent
- * folder exists, it will be created recursively.
- */
- ProjectExplorer::FolderNode *insertFolderNode(const QDir &nodeDir,
- QHash<QString, ProjectExplorer::Node *> &nodes);
-
- /**
- * @return All nodes (including sub-folder- and file-nodes) for the given parent folder.
- */
- QList<ProjectExplorer::Node *> nodes(ProjectExplorer::FolderNode *parent) const;
-
- /**
* This function is in charge of the code completion.
*/
void updateCppCodeModel();
diff --git a/src/plugins/autotoolsprojectmanager/autotoolsprojectnode.cpp b/src/plugins/autotoolsprojectmanager/autotoolsprojectnode.cpp
index cd4c613fa3..e98246ed52 100644
--- a/src/plugins/autotoolsprojectmanager/autotoolsprojectnode.cpp
+++ b/src/plugins/autotoolsprojectmanager/autotoolsprojectnode.cpp
@@ -34,8 +34,8 @@ using namespace AutotoolsProjectManager;
using namespace AutotoolsProjectManager::Internal;
using namespace ProjectExplorer;
-AutotoolsProjectNode::AutotoolsProjectNode(const Utils::FileName &projectFilePath) :
- ProjectNode(projectFilePath)
+AutotoolsProjectNode::AutotoolsProjectNode(const Utils::FileName &projectDirectory) :
+ ProjectNode(projectDirectory)
{ }
bool AutotoolsProjectNode::showInSimpleTree() const
diff --git a/src/plugins/autotoolsprojectmanager/autotoolsprojectnode.h b/src/plugins/autotoolsprojectmanager/autotoolsprojectnode.h
index f09681d8b4..088e007a4a 100644
--- a/src/plugins/autotoolsprojectmanager/autotoolsprojectnode.h
+++ b/src/plugins/autotoolsprojectmanager/autotoolsprojectnode.h
@@ -48,7 +48,7 @@ class AutotoolsProject;
class AutotoolsProjectNode : public ProjectExplorer::ProjectNode
{
public:
- AutotoolsProjectNode(const Utils::FileName &projectFilePath);
+ AutotoolsProjectNode(const Utils::FileName &projectDirectory);
bool showInSimpleTree() const override;
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;