ProjectExplorer: Add and use addNestedNode(...) that takes unique_ptr

Change-Id: Ieb26721d053111fb350494e31d1f6da3fe642420
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Tobias Hunger
2018-04-26 15:07:56 +02:00
parent f9585d939f
commit d332954567
10 changed files with 44 additions and 39 deletions

View File

@@ -209,7 +209,8 @@ void AutotoolsProject::makefileParsingFinished()
auto newRoot = std::make_unique<AutotoolsProjectNode>(projectDirectory());
for (const QString &f : m_files) {
const Utils::FileName path = Utils::FileName::fromString(f);
newRoot->addNestedNode(new FileNode(path, FileNode::fileTypeForFileName(path), false));
newRoot->addNestedNode(std::make_unique<FileNode>(path, FileNode::fileTypeForFileName(path),
false));
}
setRootProjectNode(std::move(newRoot));

View File

@@ -899,9 +899,9 @@ void ServerModeReader::addHeaderNodes(ProjectNode *root, const QList<FileNode *>
const int count = seenHeaders.count();
seenHeaders.insert(fn->filePath());
if (seenHeaders.count() != count) {
auto node = fn->clone();
std::unique_ptr<FileNode> node(fn->clone());
node->setEnabled(false);
headerNode->addNestedNode(node);
headerNode->addNestedNode(std::move(node));
}
}

View File

@@ -345,16 +345,17 @@ void GenericProject::refresh(RefreshOptions options)
FileType fileType = FileType::Source; // ### FIXME
if (f.endsWith(".qrc"))
fileType = FileType::Resource;
newRoot->addNestedNode(new FileNode(Utils::FileName::fromString(f), fileType, false));
newRoot->addNestedNode(std::make_unique<FileNode>(FileName::fromString(f), fileType,
false));
}
newRoot->addNestedNode(new FileNode(Utils::FileName::fromString(m_filesFileName),
newRoot->addNestedNode(std::make_unique<FileNode>(FileName::fromString(m_filesFileName),
FileType::Project,
/* generated = */ false));
newRoot->addNestedNode(new FileNode(Utils::FileName::fromString(m_includesFileName),
newRoot->addNestedNode(std::make_unique<FileNode>(FileName::fromString(m_includesFileName),
FileType::Project,
/* generated = */ false));
newRoot->addNestedNode(new FileNode(Utils::FileName::fromString(m_configFileName),
newRoot->addNestedNode(std::make_unique<FileNode>(FileName::fromString(m_configFileName),
FileType::Project,
/* generated = */ false));

View File

@@ -230,10 +230,11 @@ void FlatModel::addOrRebuildProjectModel(Project *project)
trimEmptyDirectories(container);
}
if (container->childCount() == 0) {
FileNode *projectFileNode = new FileNode(project->projectFilePath(), FileType::Project, false);
project->containerNode()->addNestedNode(projectFileNode);
seen.insert(projectFileNode);
container->appendChild(new WrapperNode(projectFileNode));
auto projectFileNode = std::make_unique<FileNode>(project->projectFilePath(),
FileType::Project, false);
seen.insert(projectFileNode.get());
container->appendChild(new WrapperNode(projectFileNode.get()));
project->containerNode()->addNestedNode(std::move(projectFileNode));
}
container->sortChildren(&sortWrapperNodes);

View File

@@ -548,21 +548,23 @@ QList<FolderNode*> FolderNode::folderNodes() const
return result;
}
void FolderNode::addNestedNode(FileNode *fileNode, const Utils::FileName &overrideBaseDir,
void FolderNode::addNestedNode(std::unique_ptr<FileNode> &&fileNode,
const Utils::FileName &overrideBaseDir,
const FolderNodeFactory &factory)
{
// Get relative path to rootNode
FolderNode *folder = recursiveFindOrCreateFolderNode(this, fileNode->filePath().parentDir(),
overrideBaseDir, factory);
folder->addNode(fileNode);
folder->addNode(std::move(fileNode));
}
void FolderNode::addNestedNodes(const QList<FileNode *> &files, const Utils::FileName &overrideBaseDir,
const FolderNodeFactory &factory)
{
for (FileNode *fn : files)
addNestedNode(fn, overrideBaseDir, factory);
for (FileNode *fileNode : files) {
FolderNode *folder = recursiveFindOrCreateFolderNode(this, fileNode->filePath().parentDir(),
overrideBaseDir, factory);
folder->addNode(fileNode);
}
}
// "Compress" a tree of foldernodes such that foldernodes with exactly one foldernode as a child

View File

@@ -223,14 +223,14 @@ public:
FileNode *fileNode(const Utils::FileName &file) const;
QList<FolderNode *> folderNodes() const;
using FolderNodeFactory = std::function<std::unique_ptr<FolderNode>(const Utils::FileName &)>;
void addNestedNodes(const QList<FileNode *> &files, const Utils::FileName &overrideBaseDir = Utils::FileName(),
const FolderNodeFactory &factory = [](const Utils::FileName &fn) {
return std::make_unique<FolderNode>(fn);
});
void addNestedNode(FileNode *fileNode, const Utils::FileName &overrideBaseDir = Utils::FileName(),
const FolderNodeFactory &factory = [](const Utils::FileName &fn) {
return std::make_unique<FolderNode>(fn);
});
void addNestedNodes(const QList<FileNode *> &files,
const Utils::FileName &overrideBaseDir = Utils::FileName(),
const FolderNodeFactory &factory
= [](const Utils::FileName &fn) {return std::make_unique<FolderNode>(fn); });
void addNestedNode(std::unique_ptr<FileNode> &&fileNode,
const Utils::FileName &overrideBaseDir = Utils::FileName(),
const FolderNodeFactory &factory
= [](const Utils::FileName &fn) { return std::make_unique<FolderNode>(fn); });
void compress();
bool isAncesterOf(Node *n);

View File

@@ -461,7 +461,8 @@ void PythonProject::refresh(Target *target)
for (const QString &f : m_files) {
const QString displayName = baseDir.relativeFilePath(f);
FileType fileType = f.endsWith(".pyqtc") ? FileType::Project : FileType::Source;
newRoot->addNestedNode(new PythonFileNode(FileName::fromString(f), displayName, fileType));
newRoot->addNestedNode(std::make_unique<PythonFileNode>(FileName::fromString(f),
displayName, fileType));
if (fileType == FileType::Source) {
BuildTargetInfo bti;
bti.buildKey = f;

View File

@@ -73,10 +73,9 @@ void setupArtifacts(ProjectExplorer::FolderNode *root, const QList<qbs::Artifact
QLatin1String("linkerscript"),
QLatin1String("qrc"), QLatin1String("java.java")
};
ProjectExplorer::FileNode * const node
= new ProjectExplorer::FileNode(path, type, isGenerated);
auto node = std::make_unique<ProjectExplorer::FileNode>(path, type, isGenerated);
node->setListInProject(!isGenerated || ad.fileTags().toSet().intersects(sourceTags));
root->addNestedNode(node);
root->addNestedNode(std::move(node));
}
root->compress();
}
@@ -222,7 +221,7 @@ std::unique_ptr<QbsRootProjectNode> QbsNodeTreeBuilder::buildTree(QbsProject *pr
for (const QString &f : files) {
const Utils::FileName filePath = Utils::FileName::fromString(f);
if (filePath.isChildOf(base))
buildSystemFiles->addNestedNode(new ProjectExplorer::FileNode(filePath, ProjectExplorer::FileType::Project, false));
buildSystemFiles->addNestedNode(std::make_unique<ProjectExplorer::FileNode>(filePath, ProjectExplorer::FileType::Project, false));
}
buildSystemFiles->compress();
root->addNode(buildSystemFiles);

View File

@@ -176,7 +176,7 @@ static void createTree(const QmakePriFile *pri, QmakePriFileNode *node, const Fi
// qt quick compiler moves qrc files into it:-/ Get better data based on
// the filename.
type = FileNode::fileTypeForFileName(fn);
vfolder->addNestedNode(new FileNode(fn, type, false));
vfolder->addNestedNode(std::make_unique<FileNode>(fn, type, false));
}
for (FolderNode *fn : vfolder->folderNodes())
fn->compress();

View File

@@ -365,9 +365,9 @@ void QmlProject::generateProjectTree()
const Utils::FileName fileName = Utils::FileName::fromString(f);
const FileType fileType = (fileName == projectFilePath())
? FileType::Project : FileNode::fileTypeForFileName(fileName);
newRoot->addNestedNode(new FileNode(fileName, fileType, false));
newRoot->addNestedNode(std::make_unique<FileNode>(fileName, fileType, false));
}
newRoot->addNestedNode(new FileNode(projectFilePath(), FileType::Project, false));
newRoot->addNestedNode(std::make_unique<FileNode>(projectFilePath(), FileType::Project, false));
setRootProjectNode(std::move(newRoot));
refreshTargetDirectory();