diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index 1afc23a5a4c..b3a28c2b6a5 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -116,11 +117,28 @@ const Project::NodeMatcher Project::GeneratedFiles = [](const Node *node) { // ProjectDocument: // -------------------------------------------------------------------- -ProjectDocument::ProjectDocument(const QString &mimeType, const Utils::FilePath &fileName, - const ProjectDocument::ProjectCallback &callback) : - m_callback(callback) +class ProjectDocument : public Core::IDocument { - 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); setMimeType(mimeType); Core::DocumentManager::addDocument(this); @@ -142,7 +160,7 @@ bool ProjectDocument::reload(QString *errorString, Core::IDocument::ReloadFlag f Q_UNUSED(flag) Q_UNUSED(type) - m_callback(); + emit m_project->projectFileIsDirty(filePath()); return true; } @@ -190,17 +208,10 @@ ProjectPrivate::~ProjectPrivate() } Project::Project(const QString &mimeType, - const Utils::FilePath &fileName, - const ProjectDocument::ProjectCallback &callback) + const Utils::FilePath &fileName) : d(new ProjectPrivate) { - d->m_document = std::make_unique(mimeType, - fileName, - [this, fileName, callback]() { - emit projectFileIsDirty(fileName); - if (callback) - callback(); - }); + d->m_document = std::make_unique(mimeType, fileName, this); d->m_macroExpander.setDisplayName(tr("Project")); d->m_macroExpander.registerVariable("Project:Name", tr("Project Name"), @@ -358,9 +369,7 @@ void Project::setExtraProjectFiles(const QVector &projectDocume }); for (const Utils::FilePath &p : toAdd) { d->m_extraProjectDocuments.emplace_back( - std::make_unique(d->m_document->mimeType(), p, [this, p]() { - emit projectFileIsDirty(p); - })); + std::make_unique(d->m_document->mimeType(), p, this)); } } diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index 45c8409d767..de057147bc0 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -61,24 +61,6 @@ class ProjectNode; class ProjectPrivate; class Target; -// Auto-registers with the DocumentManager if a callback is set! -class PROJECTEXPLORER_EXPORT ProjectDocument : public Core::IDocument -{ -public: - using ProjectCallback = std::function; - - 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. class PROJECTEXPLORER_EXPORT Project : public QObject { @@ -94,8 +76,7 @@ public: isParsingRole }; - Project(const QString &mimeType, const Utils::FilePath &fileName, - const ProjectDocument::ProjectCallback &callback = {}); + Project(const QString &mimeType, const Utils::FilePath &fileName); ~Project() override; QString displayName() const;