ProjectExplorer: Clean up Project

Change-Id: I870ef9f57e1a3ae3bc61351322c71d3ce5381d98
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Tobias Hunger
2019-08-15 12:44:13 +02:00
parent abebbdc9f7
commit 109a8b1829
2 changed files with 27 additions and 37 deletions

View File

@@ -48,6 +48,7 @@
#include <projectexplorer/kitmanager.h> #include <projectexplorer/kitmanager.h>
#include <projectexplorer/projecttree.h> #include <projectexplorer/projecttree.h>
#include <utils/algorithm.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/macroexpander.h> #include <utils/macroexpander.h>
#include <utils/pointeralgorithm.h> #include <utils/pointeralgorithm.h>
@@ -116,11 +117,28 @@ const Project::NodeMatcher Project::GeneratedFiles = [](const Node *node) {
// ProjectDocument: // ProjectDocument:
// -------------------------------------------------------------------- // --------------------------------------------------------------------
ProjectDocument::ProjectDocument(const QString &mimeType, const Utils::FilePath &fileName, class ProjectDocument : public Core::IDocument
const ProjectDocument::ProjectCallback &callback) :
m_callback(callback)
{ {
QTC_CHECK(callback); public:
ProjectDocument(const QString &mimeType, const Utils::FilePath &fileName, Project *project);
Core::IDocument::ReloadBehavior reloadBehavior(Core::IDocument::ChangeTrigger state,
Core::IDocument::ChangeType type) const final;
bool reload(QString *errorString,
Core::IDocument::ReloadFlag flag,
Core::IDocument::ChangeType type) final;
private:
Project *m_project;
};
ProjectDocument::ProjectDocument(const QString &mimeType,
const Utils::FilePath &fileName,
Project *project)
: m_project(project)
{
QTC_CHECK(project);
setFilePath(fileName); setFilePath(fileName);
setMimeType(mimeType); setMimeType(mimeType);
Core::DocumentManager::addDocument(this); Core::DocumentManager::addDocument(this);
@@ -142,7 +160,7 @@ bool ProjectDocument::reload(QString *errorString, Core::IDocument::ReloadFlag f
Q_UNUSED(flag) Q_UNUSED(flag)
Q_UNUSED(type) Q_UNUSED(type)
m_callback(); emit m_project->projectFileIsDirty(filePath());
return true; return true;
} }
@@ -190,17 +208,10 @@ ProjectPrivate::~ProjectPrivate()
} }
Project::Project(const QString &mimeType, Project::Project(const QString &mimeType,
const Utils::FilePath &fileName, const Utils::FilePath &fileName)
const ProjectDocument::ProjectCallback &callback)
: d(new ProjectPrivate) : d(new ProjectPrivate)
{ {
d->m_document = std::make_unique<ProjectDocument>(mimeType, d->m_document = std::make_unique<ProjectDocument>(mimeType, fileName, this);
fileName,
[this, fileName, callback]() {
emit projectFileIsDirty(fileName);
if (callback)
callback();
});
d->m_macroExpander.setDisplayName(tr("Project")); d->m_macroExpander.setDisplayName(tr("Project"));
d->m_macroExpander.registerVariable("Project:Name", tr("Project Name"), d->m_macroExpander.registerVariable("Project:Name", tr("Project Name"),
@@ -358,9 +369,7 @@ void Project::setExtraProjectFiles(const QVector<Utils::FilePath> &projectDocume
}); });
for (const Utils::FilePath &p : toAdd) { for (const Utils::FilePath &p : toAdd) {
d->m_extraProjectDocuments.emplace_back( d->m_extraProjectDocuments.emplace_back(
std::make_unique<ProjectDocument>(d->m_document->mimeType(), p, [this, p]() { std::make_unique<ProjectDocument>(d->m_document->mimeType(), p, this));
emit projectFileIsDirty(p);
}));
} }
} }

View File

@@ -61,24 +61,6 @@ class ProjectNode;
class ProjectPrivate; class ProjectPrivate;
class Target; class Target;
// Auto-registers with the DocumentManager if a callback is set!
class PROJECTEXPLORER_EXPORT ProjectDocument : public Core::IDocument
{
public:
using ProjectCallback = std::function<void()>;
ProjectDocument(const QString &mimeType, const Utils::FilePath &fileName,
const ProjectCallback &callback = {});
Core::IDocument::ReloadBehavior reloadBehavior(Core::IDocument::ChangeTrigger state,
Core::IDocument::ChangeType type) const final;
bool reload(QString *errorString, Core::IDocument::ReloadFlag flag,
Core::IDocument::ChangeType type) final;
private:
ProjectCallback m_callback;
};
// Documentation inside. // Documentation inside.
class PROJECTEXPLORER_EXPORT Project : public QObject class PROJECTEXPLORER_EXPORT Project : public QObject
{ {
@@ -94,8 +76,7 @@ public:
isParsingRole isParsingRole
}; };
Project(const QString &mimeType, const Utils::FilePath &fileName, Project(const QString &mimeType, const Utils::FilePath &fileName);
const ProjectDocument::ProjectCallback &callback = {});
~Project() override; ~Project() override;
QString displayName() const; QString displayName() const;