Commit 21d204ad authored by Tobias Hunger's avatar Tobias Hunger

Project: Add setProjectManager method

Implement default projectManager method in Project and use
these two everywhere.

Change-Id: I27e011e6fdc17b36aff1b8b931527307320e347c
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
parent b386dd0e
......@@ -72,12 +72,12 @@ using namespace AutotoolsProjectManager::Internal;
using namespace ProjectExplorer;
AutotoolsProject::AutotoolsProject(AutotoolsManager *manager, const QString &fileName) :
m_manager(manager),
m_fileName(fileName),
m_fileWatcher(new Utils::FileSystemWatcher(this)),
m_makefileParserThread(0)
{
setId(Constants::AUTOTOOLS_PROJECT_ID);
setProjectManager(manager);
setDocument(new AutotoolsProjectFile(m_fileName));
m_rootNode = new AutotoolsProjectNode(projectFilePath());
setProjectContext(Core::Context(Constants::PROJECT_CONTEXT));
......@@ -110,11 +110,6 @@ QString AutotoolsProject::displayName() const
return m_projectName;
}
IProjectManager *AutotoolsProject::projectManager() const
{
return m_manager;
}
QString AutotoolsProject::defaultBuildDirectory(const QString &projectPath)
{
return QFileInfo(projectPath).absolutePath();
......
......@@ -74,7 +74,6 @@ public:
~AutotoolsProject() override;
QString displayName() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
ProjectExplorer::ProjectNode *rootProjectNode() const override;
QStringList files(FilesMode fileMode) const override;
static QString defaultBuildDirectory(const QString &projectPath);
......@@ -136,9 +135,6 @@ private:
void updateCppCodeModel();
private:
/// Project manager that has been passed in the constructor
AutotoolsManager *m_manager;
/// File name of the makefile that has been passed in the constructor
QString m_fileName;
QString m_projectName;
......
......@@ -87,14 +87,13 @@ using namespace Utils;
/*!
\class CMakeProject
*/
CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName)
: m_manager(manager),
m_activeTarget(0),
m_fileName(fileName),
m_rootNode(new CMakeProjectNode(fileName)),
m_watcher(new QFileSystemWatcher(this))
CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName) :
m_fileName(fileName),
m_rootNode(new CMakeProjectNode(fileName)),
m_watcher(new QFileSystemWatcher(this))
{
setId(Constants::CMAKEPROJECT_ID);
setProjectManager(manager);
setDocument(new CMakeFile(fileName));
setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
......@@ -511,11 +510,6 @@ QString CMakeProject::displayName() const
return m_rootNode->displayName();
}
IProjectManager *CMakeProject::projectManager() const
{
return m_manager;
}
ProjectExplorer::ProjectNode *CMakeProject::rootProjectNode() const
{
return m_rootNode;
......
......@@ -99,7 +99,6 @@ public:
~CMakeProject() override;
QString displayName() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
ProjectExplorer::ProjectNode *rootProjectNode() const override;
......@@ -147,8 +146,7 @@ private:
void updateApplicationAndDeploymentTargets();
QStringList getCXXFlagsFor(const CMakeBuildTarget &buildTarget, QByteArray *cachedBuildNinja);
Internal::CMakeManager *m_manager;
ProjectExplorer::Target *m_activeTarget;
ProjectExplorer::Target *m_activeTarget = 0;
Utils::FileName m_fileName;
// TODO probably need a CMake specific node structure
......
......@@ -50,7 +50,6 @@ public:
~TestProject() override;
QString displayName() const override { return m_name; }
ProjectExplorer::IProjectManager *projectManager() const override { return 0; }
ProjectExplorer::ProjectNode *rootProjectNode() const override { return 0; }
QStringList files(FilesMode fileMode) const override { Q_UNUSED(fileMode); return QStringList(); }
......
......@@ -67,11 +67,10 @@ namespace Internal {
//
////////////////////////////////////////////////////////////////////////////////////
GenericProject::GenericProject(Manager *manager, const QString &fileName)
: m_manager(manager),
m_fileName(fileName)
GenericProject::GenericProject(Manager *manager, const QString &fileName) : m_fileName(fileName)
{
setId(Constants::GENERICPROJECT_ID);
setProjectManager(manager);
setDocument(new GenericProjectFile(this, m_fileName, GenericProject::Everything));
setProjectContext(Context(GenericProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX));
......@@ -112,13 +111,13 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
<< projectIncludesNode
<< projectConfigNode);
m_manager->registerProject(this);
projectManager()->registerProject(this);
}
GenericProject::~GenericProject()
{
m_codeModelFuture.cancel();
m_manager->unregisterProject(this);
projectManager()->unregisterProject(this);
delete m_rootNode;
}
......@@ -388,9 +387,9 @@ QString GenericProject::displayName() const
return m_projectName;
}
IProjectManager *GenericProject::projectManager() const
Manager *GenericProject::projectManager() const
{
return m_manager;
return static_cast<Manager *>(Project::projectManager());
}
GenericProjectNode *GenericProject::rootProjectNode() const
......
......@@ -61,7 +61,7 @@ public:
QString configFileName() const;
QString displayName() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
Manager *projectManager() const override;
GenericProjectNode *rootProjectNode() const override;
QStringList files(FilesMode fileMode) const override;
......@@ -96,7 +96,6 @@ private:
void refreshCppCodeModel();
Manager *m_manager;
QString m_fileName;
QString m_filesFileName;
QString m_includesFileName;
......
......@@ -94,6 +94,7 @@ public:
Core::Id m_id;
Core::IDocument *m_document = 0;
IProjectManager *m_manager = 0;
QList<Target *> m_targets;
Target *m_activeTarget = 0;
EditorConfiguration m_editorConfiguration;
......@@ -424,6 +425,13 @@ void Project::setDocument(Core::IDocument *doc)
d->m_document = doc;
}
void Project::setProjectManager(IProjectManager *manager)
{
QTC_ASSERT(manager, return);
QTC_ASSERT(!d->m_manager, return);
d->m_manager = manager;
}
Target *Project::restoreTarget(const QVariantMap &data)
{
Core::Id id = idFromMap(data);
......@@ -508,6 +516,11 @@ Utils::FileName Project::projectDirectory(const Utils::FileName &top)
return Utils::FileName::fromString(top.toFileInfo().absoluteDir().path());
}
IProjectManager *Project::projectManager() const
{
QTC_CHECK(d->m_manager);
return d->m_manager;
}
Project::RestoreResult Project::fromMap(const QVariantMap &map, QString *errorMessage)
{
......
......@@ -86,7 +86,7 @@ public:
Utils::FileName projectDirectory() const;
static Utils::FileName projectDirectory(const Utils::FileName &top);
virtual IProjectManager *projectManager() const = 0;
virtual IProjectManager *projectManager() const;
bool hasActiveBuildSettings() const;
......@@ -174,6 +174,7 @@ protected:
void setId(Core::Id id);
void setDocument(Core::IDocument *doc); // takes ownership!
void setProjectManager(IProjectManager *manager);
void setProjectContext(Core::Context context);
void setProjectLanguages(Core::Context language);
void addProjectLanguage(Core::Id id);
......
......@@ -249,7 +249,7 @@ public:
~PythonProject() override;
QString displayName() const override { return m_projectName; }
IProjectManager *projectManager() const override { return m_manager; }
PythonProjectManager *projectManager() const override;
ProjectNode *rootProjectNode() const override;
QStringList files(FilesMode) const override { return m_files; }
......@@ -270,7 +270,6 @@ private:
QStringList processEntries(const QStringList &paths,
QHash<QString, QString> *map = 0) const;
PythonProjectManager *m_manager;
QString m_projectFileName;
QString m_projectName;
QStringList m_rawFileList;
......@@ -617,11 +616,11 @@ private:
};
PythonProject::PythonProject(PythonProjectManager *manager, const QString &fileName)
: m_manager(manager),
m_projectFileName(fileName)
PythonProject::PythonProject(PythonProjectManager *manager, const QString &fileName) :
m_projectFileName(fileName)
{
setId(PythonProjectId);
setProjectManager(manager);
setDocument(new PythonProjectFile(this, m_projectFileName));
DocumentManager::addDocument(document());
......@@ -633,16 +632,21 @@ PythonProject::PythonProject(PythonProjectManager *manager, const QString &fileN
m_projectName = fileInfo.completeBaseName();
m_rootNode = new PythonProjectNode(this);
m_manager->registerProject(this);
projectManager()->registerProject(this);
}
PythonProject::~PythonProject()
{
m_manager->unregisterProject(this);
projectManager()->unregisterProject(this);
delete m_rootNode;
}
PythonProjectManager *PythonProject::projectManager() const
{
return static_cast<PythonProjectManager *>(Project::projectManager());
}
static QStringList readLines(const QString &absoluteFileName)
{
QStringList lines;
......
......@@ -100,7 +100,6 @@ static const char CONFIG_PRECOMPILEDHEADER[] = "precompiledHeader";
// --------------------------------------------------------------------
QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
m_manager(manager),
m_projectName(QFileInfo(fileName).completeBaseName()),
m_fileName(fileName),
m_rootProjectNode(0),
......@@ -113,6 +112,7 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
m_parsingDelay.setInterval(1000); // delay parsing by 1s.
setId(Constants::PROJECT_ID);
setProjectManager(manager);
setDocument(new QbsProjectFile(this, m_fileName));
DocumentManager::addDocument(document());
......@@ -157,7 +157,7 @@ QString QbsProject::displayName() const
QbsManager *QbsProject::projectManager() const
{
return m_manager;
return static_cast<QbsManager *>(Project::projectManager());
}
ProjectNode *QbsProject::rootProjectNode() const
......@@ -402,7 +402,7 @@ qbs::InstallJob *QbsProject::install(const qbs::InstallOptions &opts)
QString QbsProject::profileForTarget(const Target *t) const
{
return m_manager->profileForKit(t->kit());
return projectManager()->profileForKit(t->kit());
}
bool QbsProject::isParsing() const
......
......@@ -145,7 +145,6 @@ private:
qbs::GroupData reRetrieveGroupData(const qbs::ProductData &oldProduct,
const qbs::GroupData &oldGroup);
QbsManager *const m_manager;
const QString m_projectName;
const QString m_fileName;
qbs::Project m_qbsProject;
......
......@@ -1180,7 +1180,7 @@ bool QmakePriFileNode::saveModifiedEditors()
// force instant reload of ourselves
QtSupport::ProFileCacheManager::instance()->discardFile(m_projectFilePath.toString());
m_project->qmakeProjectManager()->notifyChanged(m_projectFilePath);
m_project->projectManager()->notifyChanged(m_projectFilePath);
return true;
}
......@@ -1369,7 +1369,7 @@ void QmakePriFileNode::save(const QStringList &lines)
saver.write(lines.join(QLatin1Char('\n')).toLocal8Bit());
saver.finalize(Core::ICore::mainWindow());
m_project->qmakeProjectManager()->notifyChanged(m_projectFilePath);
m_project->projectManager()->notifyChanged(m_projectFilePath);
Core::DocumentManager::unexpectFileChange(m_projectFilePath.toString());
// This is a hack.
// We are saving twice in a very short timeframe, once the editor and once the ProFile.
......
......@@ -308,11 +308,11 @@ bool QmakeProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType
*/
QmakeProject::QmakeProject(QmakeManager *manager, const QString &fileName) :
m_manager(manager),
m_projectFiles(new QmakeProjectFiles),
m_qmakeVfs(new QMakeVfs)
{
setId(Constants::QMAKEPROJECT_ID);
setProjectManager(manager);
setDocument(new QmakeProjectFile(fileName));
setProjectContext(Core::Context(QmakeProjectManager::Constants::PROJECT_ID));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
......@@ -334,7 +334,7 @@ QmakeProject::~QmakeProject()
{
m_codeModelFuture.cancel();
m_asyncUpdateState = ShuttingDown;
m_manager->unregisterProject(this);
projectManager()->unregisterProject(this);
delete m_projectFiles;
m_cancelEvaluate = true;
// Deleting the root node triggers a few things, make sure rootProjectNode
......@@ -374,7 +374,7 @@ Project::RestoreResult QmakeProject::fromMap(const QVariantMap &map, QString *er
}
}
m_manager->registerProject(this);
projectManager()->registerProject(this);
m_rootProjectNode = new QmakeProFileNode(this, projectFilePath());
......@@ -825,14 +825,9 @@ void QmakeProject::buildFinished(bool success)
m_qmakeVfs->invalidateContents();
}
IProjectManager *QmakeProject::projectManager() const
QmakeManager *QmakeProject::projectManager() const
{
return m_manager;
}
QmakeManager *QmakeProject::qmakeProjectManager() const
{
return m_manager;
return static_cast<QmakeManager *>(Project::projectManager());
}
bool QmakeProject::supportsKit(Kit *k, QString *errorMessage) const
......
......@@ -32,6 +32,7 @@
#define QMAKEPROJECT_H
#include "qmakeprojectmanager_global.h"
#include "qmakeprojectmanager.h"
#include "qmakenodes.h"
#include <projectexplorer/project.h>
......@@ -52,7 +53,6 @@ namespace QtSupport { class ProFileReader; }
namespace QmakeProjectManager {
class QmakeBuildConfiguration;
class QmakeManager;
class QmakePriFileNode;
class QmakeProFileNode;
......@@ -72,8 +72,7 @@ public:
~QmakeProject() override;
QString displayName() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
QmakeManager *qmakeProjectManager() const;
QmakeManager *projectManager() const override;
bool supportsKit(ProjectExplorer::Kit *k, QString *errorMesage) const override;
......@@ -181,7 +180,6 @@ private:
void startAsyncTimer(QmakeProFileNode::AsyncUpdateDelay delay);
bool matchesKit(const ProjectExplorer::Kit *kit);
QmakeManager *m_manager;
QmakeProFileNode *m_rootProjectNode = 0;
// Current configuration
......
......@@ -58,13 +58,12 @@ namespace Internal {
} // namespace Internal
QmlProject::QmlProject(Internal::Manager *manager, const Utils::FileName &fileName)
: m_manager(manager),
m_fileName(fileName),
m_defaultImport(UnknownImport),
m_activeTarget(0)
QmlProject::QmlProject(Internal::Manager *manager, const Utils::FileName &fileName) :
m_fileName(fileName),
m_defaultImport(UnknownImport)
{
setId("QmlProjectManager.QmlProject");
setProjectManager(manager);
setDocument(new Internal::QmlProjectFile(this, fileName));
DocumentManager::addDocument(document(), true);
......@@ -76,12 +75,12 @@ QmlProject::QmlProject(Internal::Manager *manager, const Utils::FileName &fileNa
m_rootNode = new Internal::QmlProjectNode(this);
m_manager->registerProject(this);
projectManager()->registerProject(this);
}
QmlProject::~QmlProject()
{
m_manager->unregisterProject(this);
projectManager()->unregisterProject(this);
delete m_projectItem.data();
delete m_rootNode;
......@@ -290,9 +289,9 @@ QString QmlProject::displayName() const
return m_projectName;
}
IProjectManager *QmlProject::projectManager() const
Internal::Manager *QmlProject::projectManager() const
{
return m_manager;
return static_cast<Internal::Manager *>(Project::projectManager());
}
bool QmlProject::supportsKit(Kit *k, QString *errorMessage) const
......
......@@ -33,6 +33,8 @@
#include "qmlprojectmanager_global.h"
#include "qmlprojectmanager.h"
#include <projectexplorer/project.h>
#include <QPointer>
......@@ -46,7 +48,6 @@ namespace QmlProjectManager {
class QmlProjectItem;
namespace Internal {
class Manager;
class QmlProjectFile;
class QmlProjectNode;
} // namespace Internal
......@@ -62,7 +63,7 @@ public:
Utils::FileName filesFileName() const;
QString displayName() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
Internal::Manager *projectManager() const override;
bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage) const override;
......@@ -109,11 +110,10 @@ private:
QStringList convertToAbsoluteFiles(const QStringList &paths) const;
QmlJS::ModelManagerInterface *modelManager() const;
Internal::Manager *m_manager;
Utils::FileName m_fileName;
QString m_projectName;
QmlImport m_defaultImport;
ProjectExplorer::Target *m_activeTarget;
ProjectExplorer::Target *m_activeTarget = 0;
// plain format
QStringList m_files;
......
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