Commit 53c85a26 authored by Tobias Hunger's avatar Tobias Hunger

Project: Use more std::unique_ptr

Change-Id: I06114e79b0a5b58b3dc4d13279232392709e9efc
Reviewed-by: default avatarJochen Becher <jochen_becher@gmx.de>
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 287ae7ae
......@@ -52,6 +52,7 @@
#include <utils/qtcassert.h>
#include <limits>
#include <memory>
/*!
\class ProjectExplorer::Project
......@@ -126,20 +127,25 @@ bool ProjectDocument::reload(QString *errorString, Core::IDocument::ReloadFlag f
class ProjectPrivate
{
public:
ProjectPrivate(Core::IDocument *document) : m_document(document) { }
ProjectPrivate(const QString &mimeType, const Utils::FileName &fileName,
const ProjectDocument::ProjectCallback &callback)
{
m_document = std::make_unique<ProjectDocument>(mimeType, fileName, callback);
}
~ProjectPrivate();
Core::Id m_id;
Core::IDocument *m_document = nullptr;
std::unique_ptr<Core::IDocument> m_document;
ProjectNode *m_rootProjectNode = nullptr;
ContainerNode *m_containerNode = nullptr;
std::unique_ptr<ContainerNode> m_containerNode;
QList<Target *> m_targets;
Target *m_activeTarget = nullptr;
EditorConfiguration m_editorConfiguration;
Core::Context m_projectContext;
Core::Context m_projectLanguages;
QVariantMap m_pluginSettings;
Internal::UserFileAccessor *m_accessor = nullptr;
std::unique_ptr<Internal::UserFileAccessor> m_accessor;
QString m_displayName;
......@@ -151,32 +157,28 @@ public:
ProjectPrivate::~ProjectPrivate()
{
qDeleteAll(m_targets);
// Make sure our root node is null when deleting
ProjectNode *oldNode = m_rootProjectNode;
m_rootProjectNode = nullptr;
delete oldNode;
delete m_containerNode;
delete m_document;
delete m_accessor;
}
Project::Project(const QString &mimeType, const Utils::FileName &fileName,
const ProjectDocument::ProjectCallback &callback) :
d(new ProjectPrivate(new ProjectDocument(mimeType, fileName, callback)))
d(new ProjectPrivate(mimeType, fileName, callback))
{
d->m_macroExpander.setDisplayName(tr("Project"));
d->m_macroExpander.registerVariable("Project:Name", tr("Project Name"),
[this] { return displayName(); });
// Only set up containernode after d is set so that it will find the project directory!
d->m_containerNode = new ContainerNode(this);
d->m_containerNode = std::make_unique<ContainerNode>(this);
}
Project::~Project()
{
qDeleteAll(d->m_targets);
delete d;
}
......@@ -194,7 +196,7 @@ Core::Id Project::id() const
Core::IDocument *Project::document() const
{
QTC_CHECK(d->m_document);
return d->m_document;
return d->m_document.get();
}
Utils::FileName Project::projectFilePath() const
......@@ -493,7 +495,7 @@ void Project::setRootProjectNode(ProjectNode *root)
ProjectNode *oldNode = d->m_rootProjectNode;
d->m_rootProjectNode = root;
if (root) {
root->setParentFolderNode(d->m_containerNode);
root->setParentFolderNode(d->m_containerNode.get());
// Only announce non-null root, null is only used when project is destroyed.
// In that case SessionManager::projectRemoved() triggers the update.
ProjectTree::emitSubtreeChanged(root);
......@@ -531,7 +533,7 @@ void Project::saveSettings()
{
emit aboutToSaveSettings();
if (!d->m_accessor)
d->m_accessor = new Internal::UserFileAccessor(this);
d->m_accessor = std::make_unique<Internal::UserFileAccessor>(this);
if (!targets().isEmpty())
d->m_accessor->saveSettings(toMap(), Core::ICore::mainWindow());
}
......@@ -539,7 +541,7 @@ void Project::saveSettings()
Project::RestoreResult Project::restoreSettings(QString *errorMessage)
{
if (!d->m_accessor)
d->m_accessor = new Internal::UserFileAccessor(this);
d->m_accessor = std::make_unique<Internal::UserFileAccessor>(this);
QVariantMap map(d->m_accessor->restoreSettings(Core::ICore::mainWindow()));
RestoreResult result = fromMap(map, errorMessage);
if (result == RestoreResult::Ok)
......@@ -633,7 +635,7 @@ ProjectNode *Project::rootProjectNode() const
ContainerNode *Project::containerNode() const
{
return d->m_containerNode;
return d->m_containerNode.get();
}
Project::RestoreResult Project::fromMap(const QVariantMap &map, QString *errorMessage)
......
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