Commit b386dd0e authored by Tobias Hunger's avatar Tobias Hunger

Project: Add setDocument method

Add setDocument method, implement document method, use this in all
projects.

Change-Id: I5018bf7c2739665c13eee340184ce7c41fd319bb
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
parent dc3ca42e
...@@ -74,14 +74,12 @@ using namespace ProjectExplorer; ...@@ -74,14 +74,12 @@ using namespace ProjectExplorer;
AutotoolsProject::AutotoolsProject(AutotoolsManager *manager, const QString &fileName) : AutotoolsProject::AutotoolsProject(AutotoolsManager *manager, const QString &fileName) :
m_manager(manager), m_manager(manager),
m_fileName(fileName), m_fileName(fileName),
m_files(),
m_file(new AutotoolsProjectFile(this, m_fileName)),
m_rootNode(new AutotoolsProjectNode(m_file->filePath())),
m_fileWatcher(new Utils::FileSystemWatcher(this)), m_fileWatcher(new Utils::FileSystemWatcher(this)),
m_watchedFiles(),
m_makefileParserThread(0) m_makefileParserThread(0)
{ {
setId(Constants::AUTOTOOLS_PROJECT_ID); setId(Constants::AUTOTOOLS_PROJECT_ID);
setDocument(new AutotoolsProjectFile(m_fileName));
m_rootNode = new AutotoolsProjectNode(projectFilePath());
setProjectContext(Core::Context(Constants::PROJECT_CONTEXT)); setProjectContext(Core::Context(Constants::PROJECT_CONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX)); setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
...@@ -112,11 +110,6 @@ QString AutotoolsProject::displayName() const ...@@ -112,11 +110,6 @@ QString AutotoolsProject::displayName() const
return m_projectName; return m_projectName;
} }
Core::IDocument *AutotoolsProject::document() const
{
return m_file;
}
IProjectManager *AutotoolsProject::projectManager() const IProjectManager *AutotoolsProject::projectManager() const
{ {
return m_manager; return m_manager;
......
...@@ -74,10 +74,9 @@ public: ...@@ -74,10 +74,9 @@ public:
~AutotoolsProject() override; ~AutotoolsProject() override;
QString displayName() const override; QString displayName() const override;
Core::IDocument *document() const override;
ProjectExplorer::IProjectManager *projectManager() const override; ProjectExplorer::IProjectManager *projectManager() const override;
ProjectExplorer::ProjectNode *rootProjectNode() const override; ProjectExplorer::ProjectNode *rootProjectNode() const override;
QStringList files(FilesMode fileMode) const; QStringList files(FilesMode fileMode) const override;
static QString defaultBuildDirectory(const QString &projectPath); static QString defaultBuildDirectory(const QString &projectPath);
QStringList buildTargets() const; QStringList buildTargets() const;
...@@ -147,9 +146,6 @@ private: ...@@ -147,9 +146,6 @@ private:
/// Return value for AutotoolsProject::files() /// Return value for AutotoolsProject::files()
QStringList m_files; QStringList m_files;
/// Return value for AutotoolsProject::file()
AutotoolsProjectFile *m_file;
/// Return value for AutotoolsProject::rootProjectNode() /// Return value for AutotoolsProject::rootProjectNode()
AutotoolsProjectNode *m_rootNode; AutotoolsProjectNode *m_rootNode;
......
...@@ -37,9 +37,7 @@ ...@@ -37,9 +37,7 @@
using namespace AutotoolsProjectManager; using namespace AutotoolsProjectManager;
using namespace AutotoolsProjectManager::Internal; using namespace AutotoolsProjectManager::Internal;
AutotoolsProjectFile::AutotoolsProjectFile(AutotoolsProject *project, const QString &fileName) : AutotoolsProjectFile::AutotoolsProjectFile(const QString &fileName)
Core::IDocument(project),
m_project(project)
{ {
setId("Autotools.ProjectFile"); setId("Autotools.ProjectFile");
setMimeType(QLatin1String(Constants::MAKEFILE_MIMETYPE)); setMimeType(QLatin1String(Constants::MAKEFILE_MIMETYPE));
......
...@@ -55,7 +55,7 @@ class AutotoolsProjectFile : public Core::IDocument ...@@ -55,7 +55,7 @@ class AutotoolsProjectFile : public Core::IDocument
Q_OBJECT Q_OBJECT
public: public:
AutotoolsProjectFile(AutotoolsProject *project, const QString &fileName); AutotoolsProjectFile(const QString &fileName);
bool save(QString *errorString, const QString &fileName, bool autoSave) override; bool save(QString *errorString, const QString &fileName, bool autoSave) override;
QString defaultPath() const override; QString defaultPath() const override;
...@@ -63,9 +63,6 @@ public: ...@@ -63,9 +63,6 @@ public:
bool isModified() const override; bool isModified() const override;
bool isSaveAsAllowed() const override; bool isSaveAsAllowed() const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
private:
AutotoolsProject *m_project;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -39,8 +39,7 @@ using namespace Utils; ...@@ -39,8 +39,7 @@ using namespace Utils;
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
CMakeFile::CMakeFile(CMakeProject *parent, const FileName &fileName) CMakeFile::CMakeFile(const FileName &fileName)
: Core::IDocument(parent), m_project(parent)
{ {
setId("Cmake.ProjectFile"); setId("Cmake.ProjectFile");
setMimeType(QLatin1String(Constants::CMAKEPROJECTMIMETYPE)); setMimeType(QLatin1String(Constants::CMAKEPROJECTMIMETYPE));
......
...@@ -42,7 +42,7 @@ class CMakeFile : public Core::IDocument ...@@ -42,7 +42,7 @@ class CMakeFile : public Core::IDocument
{ {
Q_OBJECT Q_OBJECT
public: public:
CMakeFile(CMakeProject *parent, const Utils::FileName &fileName); CMakeFile(const Utils::FileName &fileName);
bool save(QString *errorString, const QString &fileName, bool autoSave) override; bool save(QString *errorString, const QString &fileName, bool autoSave) override;
...@@ -54,9 +54,6 @@ public: ...@@ -54,9 +54,6 @@ public:
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override; ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
private:
CMakeProject *m_project;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -95,13 +95,12 @@ CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName) ...@@ -95,13 +95,12 @@ CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName)
m_watcher(new QFileSystemWatcher(this)) m_watcher(new QFileSystemWatcher(this))
{ {
setId(Constants::CMAKEPROJECT_ID); setId(Constants::CMAKEPROJECT_ID);
setDocument(new CMakeFile(fileName));
setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT)); setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX)); setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
m_rootNode->setDisplayName(fileName.parentDir().fileName()); m_rootNode->setDisplayName(fileName.parentDir().fileName());
m_file = new CMakeFile(this, fileName);
connect(this, &CMakeProject::buildTargetsChanged, this, &CMakeProject::updateRunConfigurations); connect(this, &CMakeProject::buildTargetsChanged, this, &CMakeProject::updateRunConfigurations);
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &CMakeProject::fileChanged); connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &CMakeProject::fileChanged);
} }
...@@ -512,11 +511,6 @@ QString CMakeProject::displayName() const ...@@ -512,11 +511,6 @@ QString CMakeProject::displayName() const
return m_rootNode->displayName(); return m_rootNode->displayName();
} }
Core::IDocument *CMakeProject::document() const
{
return m_file;
}
IProjectManager *CMakeProject::projectManager() const IProjectManager *CMakeProject::projectManager() const
{ {
return m_manager; return m_manager;
......
...@@ -99,7 +99,6 @@ public: ...@@ -99,7 +99,6 @@ public:
~CMakeProject() override; ~CMakeProject() override;
QString displayName() const override; QString displayName() const override;
Core::IDocument *document() const override;
ProjectExplorer::IProjectManager *projectManager() const override; ProjectExplorer::IProjectManager *projectManager() const override;
ProjectExplorer::ProjectNode *rootProjectNode() const override; ProjectExplorer::ProjectNode *rootProjectNode() const override;
...@@ -151,7 +150,6 @@ private: ...@@ -151,7 +150,6 @@ private:
Internal::CMakeManager *m_manager; Internal::CMakeManager *m_manager;
ProjectExplorer::Target *m_activeTarget; ProjectExplorer::Target *m_activeTarget;
Utils::FileName m_fileName; Utils::FileName m_fileName;
Internal::CMakeFile *m_file;
// TODO probably need a CMake specific node structure // TODO probably need a CMake specific node structure
Internal::CMakeProjectNode *m_rootNode; Internal::CMakeProjectNode *m_rootNode;
......
...@@ -50,7 +50,6 @@ public: ...@@ -50,7 +50,6 @@ public:
~TestProject() override; ~TestProject() override;
QString displayName() const override { return m_name; } QString displayName() const override { return m_name; }
Core::IDocument *document() const override { return 0; }
ProjectExplorer::IProjectManager *projectManager() const override { return 0; } ProjectExplorer::IProjectManager *projectManager() const override { return 0; }
ProjectExplorer::ProjectNode *rootProjectNode() const override { return 0; } ProjectExplorer::ProjectNode *rootProjectNode() const override { return 0; }
......
...@@ -72,6 +72,7 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName) ...@@ -72,6 +72,7 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
m_fileName(fileName) m_fileName(fileName)
{ {
setId(Constants::GENERICPROJECT_ID); setId(Constants::GENERICPROJECT_ID);
setDocument(new GenericProjectFile(this, m_fileName, GenericProject::Everything));
setProjectContext(Context(GenericProjectManager::Constants::PROJECTCONTEXT)); setProjectContext(Context(GenericProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX)); setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX));
...@@ -83,12 +84,11 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName) ...@@ -83,12 +84,11 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
m_includesFileName = QFileInfo(dir, m_projectName + QLatin1String(".includes")).absoluteFilePath(); m_includesFileName = QFileInfo(dir, m_projectName + QLatin1String(".includes")).absoluteFilePath();
m_configFileName = QFileInfo(dir, m_projectName + QLatin1String(".config")).absoluteFilePath(); m_configFileName = QFileInfo(dir, m_projectName + QLatin1String(".config")).absoluteFilePath();
m_creatorIDocument = new GenericProjectFile(this, m_fileName, GenericProject::Everything);
m_filesIDocument = new GenericProjectFile(this, m_filesFileName, GenericProject::Files); m_filesIDocument = new GenericProjectFile(this, m_filesFileName, GenericProject::Files);
m_includesIDocument = new GenericProjectFile(this, m_includesFileName, GenericProject::Configuration); m_includesIDocument = new GenericProjectFile(this, m_includesFileName, GenericProject::Configuration);
m_configIDocument = new GenericProjectFile(this, m_configFileName, GenericProject::Configuration); m_configIDocument = new GenericProjectFile(this, m_configFileName, GenericProject::Configuration);
DocumentManager::addDocument(m_creatorIDocument); DocumentManager::addDocument(document());
DocumentManager::addDocument(m_filesIDocument); DocumentManager::addDocument(m_filesIDocument);
DocumentManager::addDocument(m_includesIDocument); DocumentManager::addDocument(m_includesIDocument);
DocumentManager::addDocument(m_configIDocument); DocumentManager::addDocument(m_configIDocument);
...@@ -388,11 +388,6 @@ QString GenericProject::displayName() const ...@@ -388,11 +388,6 @@ QString GenericProject::displayName() const
return m_projectName; return m_projectName;
} }
IDocument *GenericProject::document() const
{
return m_creatorIDocument;
}
IProjectManager *GenericProject::projectManager() const IProjectManager *GenericProject::projectManager() const
{ {
return m_manager; return m_manager;
...@@ -451,8 +446,8 @@ Project::RestoreResult GenericProject::fromMap(const QVariantMap &map, QString * ...@@ -451,8 +446,8 @@ Project::RestoreResult GenericProject::fromMap(const QVariantMap &map, QString *
// //
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
GenericProjectFile::GenericProjectFile(GenericProject *parent, QString fileName, GenericProject::RefreshOptions options) GenericProjectFile::GenericProjectFile(GenericProject *parent, QString fileName,
: IDocument(parent), GenericProject::RefreshOptions options) :
m_project(parent), m_project(parent),
m_options(options) m_options(options)
{ {
......
...@@ -61,7 +61,6 @@ public: ...@@ -61,7 +61,6 @@ public:
QString configFileName() const; QString configFileName() const;
QString displayName() const override; QString displayName() const override;
Core::IDocument *document() const override;
ProjectExplorer::IProjectManager *projectManager() const override; ProjectExplorer::IProjectManager *projectManager() const override;
GenericProjectNode *rootProjectNode() const override; GenericProjectNode *rootProjectNode() const override;
...@@ -103,7 +102,6 @@ private: ...@@ -103,7 +102,6 @@ private:
QString m_includesFileName; QString m_includesFileName;
QString m_configFileName; QString m_configFileName;
QString m_projectName; QString m_projectName;
GenericProjectFile *m_creatorIDocument;
GenericProjectFile *m_filesIDocument; GenericProjectFile *m_filesIDocument;
GenericProjectFile *m_includesIDocument; GenericProjectFile *m_includesIDocument;
GenericProjectFile *m_configIDocument; GenericProjectFile *m_configIDocument;
......
...@@ -90,17 +90,17 @@ namespace ProjectExplorer { ...@@ -90,17 +90,17 @@ namespace ProjectExplorer {
class ProjectPrivate class ProjectPrivate
{ {
public: public:
ProjectPrivate();
~ProjectPrivate(); ~ProjectPrivate();
Core::Id m_id; Core::Id m_id;
Core::IDocument *m_document = 0;
QList<Target *> m_targets; QList<Target *> m_targets;
Target *m_activeTarget; Target *m_activeTarget = 0;
EditorConfiguration m_editorConfiguration; EditorConfiguration m_editorConfiguration;
Core::Context m_projectContext; Core::Context m_projectContext;
Core::Context m_projectLanguages; Core::Context m_projectLanguages;
QVariantMap m_pluginSettings; QVariantMap m_pluginSettings;
Internal::UserFileAccessor *m_accessor; Internal::UserFileAccessor *m_accessor = 0;
KitMatcher m_requiredKitMatcher; KitMatcher m_requiredKitMatcher;
KitMatcher m_preferredKitMatcher; KitMatcher m_preferredKitMatcher;
...@@ -108,13 +108,11 @@ public: ...@@ -108,13 +108,11 @@ public:
Utils::MacroExpander m_macroExpander; Utils::MacroExpander m_macroExpander;
}; };
ProjectPrivate::ProjectPrivate() :
m_activeTarget(0),
m_accessor(0)
{ }
ProjectPrivate::~ProjectPrivate() ProjectPrivate::~ProjectPrivate()
{ delete m_accessor; } {
delete m_accessor;
delete m_document;
}
Project::Project() : d(new ProjectPrivate) Project::Project() : d(new ProjectPrivate)
{ {
...@@ -135,8 +133,15 @@ Core::Id Project::id() const ...@@ -135,8 +133,15 @@ Core::Id Project::id() const
return d->m_id; return d->m_id;
} }
Core::IDocument *Project::document() const
{
QTC_CHECK(d->m_document);
return d->m_document;
}
Utils::FileName Project::projectFilePath() const Utils::FileName Project::projectFilePath() const
{ {
QTC_ASSERT(document(), return Utils::FileName());
return document()->filePath(); return document()->filePath();
} }
...@@ -412,6 +417,13 @@ void Project::setId(Core::Id id) ...@@ -412,6 +417,13 @@ void Project::setId(Core::Id id)
d->m_id = id; d->m_id = id;
} }
void Project::setDocument(Core::IDocument *doc)
{
QTC_ASSERT(doc, return);
QTC_ASSERT(!d->m_document, return);
d->m_document = doc;
}
Target *Project::restoreTarget(const QVariantMap &data) Target *Project::restoreTarget(const QVariantMap &data)
{ {
Core::Id id = idFromMap(data); Core::Id id = idFromMap(data);
......
...@@ -79,10 +79,14 @@ public: ...@@ -79,10 +79,14 @@ public:
virtual QString displayName() const = 0; virtual QString displayName() const = 0;
Core::Id id() const; Core::Id id() const;
virtual Core::IDocument *document() const = 0;
virtual IProjectManager *projectManager() const = 0;
Core::IDocument *document() const;
Utils::FileName projectFilePath() const; Utils::FileName projectFilePath() const;
// The directory that holds the project. This includes the absolute path.
Utils::FileName projectDirectory() const;
static Utils::FileName projectDirectory(const Utils::FileName &top);
virtual IProjectManager *projectManager() const = 0;
bool hasActiveBuildSettings() const; bool hasActiveBuildSettings() const;
...@@ -119,10 +123,6 @@ public: ...@@ -119,10 +123,6 @@ public:
virtual QVariantMap toMap() const; virtual QVariantMap toMap() const;
// The directory that holds the project. This includes the absolute path.
Utils::FileName projectDirectory() const;
static Utils::FileName projectDirectory(const Utils::FileName &top);
Core::Context projectContext() const; Core::Context projectContext() const;
Core::Context projectLanguages() const; Core::Context projectLanguages() const;
...@@ -173,6 +173,7 @@ protected: ...@@ -173,6 +173,7 @@ protected:
virtual bool setupTarget(Target *t); virtual bool setupTarget(Target *t);
void setId(Core::Id id); void setId(Core::Id id);
void setDocument(Core::IDocument *doc); // takes ownership!
void setProjectContext(Core::Context context); void setProjectContext(Core::Context context);
void setProjectLanguages(Core::Context language); void setProjectLanguages(Core::Context language);
void addProjectLanguage(Core::Id id); void addProjectLanguage(Core::Id id);
......
...@@ -1282,8 +1282,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er ...@@ -1282,8 +1282,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
[this]() -> QString { [this]() -> QString {
Utils::FileName projectFilePath; Utils::FileName projectFilePath;
if (Project *project = ProjectTree::currentProject()) if (Project *project = ProjectTree::currentProject())
if (IDocument *doc = project->document()) projectFilePath = project->projectFilePath();
projectFilePath = doc->filePath();
return projectFilePath.toString(); return projectFilePath.toString();
}); });
......
...@@ -1027,7 +1027,7 @@ bool SessionManager::loadSession(const QString &session) ...@@ -1027,7 +1027,7 @@ bool SessionManager::loadSession(const QString &session)
auto end = oldProjects.end(); auto end = oldProjects.end();
while (it != end) { while (it != end) {
int index = fileList.indexOf((*it)->document()->filePath().toString()); int index = fileList.indexOf((*it)->projectFilePath().toString());
if (index != -1) { if (index != -1) {
fileList.removeAt(index); fileList.removeAt(index);
it = oldProjects.erase(it); it = oldProjects.erase(it);
......
...@@ -249,7 +249,6 @@ public: ...@@ -249,7 +249,6 @@ public:
~PythonProject() override; ~PythonProject() override;
QString displayName() const override { return m_projectName; } QString displayName() const override { return m_projectName; }
IDocument *document() const override;
IProjectManager *projectManager() const override { return m_manager; } IProjectManager *projectManager() const override { return m_manager; }
ProjectNode *rootProjectNode() const override; ProjectNode *rootProjectNode() const override;
...@@ -274,7 +273,6 @@ private: ...@@ -274,7 +273,6 @@ private:
PythonProjectManager *m_manager; PythonProjectManager *m_manager;
QString m_projectFileName; QString m_projectFileName;
QString m_projectName; QString m_projectName;
PythonProjectFile *m_document;
QStringList m_rawFileList; QStringList m_rawFileList;
QStringList m_files; QStringList m_files;
QHash<QString, QString> m_rawListEntries; QHash<QString, QString> m_rawListEntries;
...@@ -285,9 +283,7 @@ private: ...@@ -285,9 +283,7 @@ private:
class PythonProjectFile : public Core::IDocument class PythonProjectFile : public Core::IDocument
{ {
public: public:
PythonProjectFile(PythonProject *parent, QString fileName) PythonProjectFile(PythonProject *parent, QString fileName) : m_project(parent)
: IDocument(parent),
m_project(parent)
{ {
setId("Generic.ProjectFile"); setId("Generic.ProjectFile");
setMimeType(QLatin1String(PythonMimeType)); setMimeType(QLatin1String(PythonMimeType));
...@@ -626,16 +622,15 @@ PythonProject::PythonProject(PythonProjectManager *manager, const QString &fileN ...@@ -626,16 +622,15 @@ PythonProject::PythonProject(PythonProjectManager *manager, const QString &fileN
m_projectFileName(fileName) m_projectFileName(fileName)
{ {
setId(PythonProjectId); setId(PythonProjectId);
setDocument(new PythonProjectFile(this, m_projectFileName));
DocumentManager::addDocument(document());
setProjectContext(Context(PythonProjectContext)); setProjectContext(Context(PythonProjectContext));
setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX)); setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX));
QFileInfo fileInfo(m_projectFileName); QFileInfo fileInfo(m_projectFileName);
m_projectName = fileInfo.completeBaseName(); m_projectName = fileInfo.completeBaseName();
m_document = new PythonProjectFile(this, m_projectFileName);
DocumentManager::addDocument(m_document);
m_rootNode = new PythonProjectNode(this); m_rootNode = new PythonProjectNode(this);
m_manager->registerProject(this); m_manager->registerProject(this);
...@@ -648,11 +643,6 @@ PythonProject::~PythonProject() ...@@ -648,11 +643,6 @@ PythonProject::~PythonProject()
delete m_rootNode; delete m_rootNode;
} }
IDocument *PythonProject::document() const
{
return m_document;
}
static QStringList readLines(const QString &absoluteFileName) static QStringList readLines(const QString &absoluteFileName)
{ {
QStringList lines; QStringList lines;
......
...@@ -113,6 +113,10 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) : ...@@ -113,6 +113,10 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
m_parsingDelay.setInterval(1000); // delay parsing by 1s. m_parsingDelay.setInterval(1000); // delay parsing by 1s.
setId(Constants::PROJECT_ID); setId(Constants::PROJECT_ID);
setDocument(new QbsProjectFile(this, m_fileName));
DocumentManager::addDocument(document());