ProjectExplorer: Make FolderNodeFactory return an unique_ptr

Change-Id: I9b611c4a3ff0928b2078dc30a44eb39df67c8d89
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Tobias Hunger
2018-04-26 14:57:12 +02:00
parent 04057106ba
commit 147e6078ad
3 changed files with 15 additions and 13 deletions

View File

@@ -727,16 +727,14 @@ ServerModeReader::addCMakeLists(CMakeProjectNode *root, const QList<FileNode *>
= Utils::transform<QSet>(cmakeLists, [](const Node *n) { return n->filePath().parentDir(); });
root->addNestedNodes(cmakeLists, Utils::FileName(),
[&cmakeDirs, &cmakeListsNodes](const Utils::FileName &fp)
-> ProjectExplorer::FolderNode * {
FolderNode *fn = nullptr;
-> std::unique_ptr<ProjectExplorer::FolderNode> {
if (cmakeDirs.contains(fp)) {
CMakeListsNode *n = new CMakeListsNode(fp);
cmakeListsNodes.insert(fp, n);
fn = n;
} else {
fn = new FolderNode(fp);
auto fn = std::make_unique<CMakeListsNode>(fp);
cmakeListsNodes.insert(fp, fn.get());
return fn;
}
return fn;
return std::make_unique<FolderNode>(fp);
});
root->compress();
return cmakeListsNodes;

View File

@@ -96,8 +96,8 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
// No FolderNode yet, so create it
auto tmp = factory(path);
tmp->setDisplayName(part);
parent->addNode(tmp);
next = tmp;
next = tmp.get();
parent->addNode(std::move(tmp));
}
parent = next;
}

View File

@@ -221,11 +221,15 @@ public:
QList<FileNode *> fileNodes() const;
FileNode *fileNode(const Utils::FileName &file) const;
QList<FolderNode *> folderNodes() const;
using FolderNodeFactory = std::function<FolderNode *(const Utils::FileName &)>;
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 new FolderNode(fn); });
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 new FolderNode(fn); });
const FolderNodeFactory &factory = [](const Utils::FileName &fn) {
return std::make_unique<FolderNode>(fn);
});
void compress();
bool isAncesterOf(Node *n);