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;
AutotoolsProject::AutotoolsProject(AutotoolsManager *manager, const QString &fileName) :
m_manager(manager),
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_watchedFiles(),
m_makefileParserThread(0)
{
setId(Constants::AUTOTOOLS_PROJECT_ID);
setDocument(new AutotoolsProjectFile(m_fileName));
m_rootNode = new AutotoolsProjectNode(projectFilePath());
setProjectContext(Core::Context(Constants::PROJECT_CONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
......@@ -112,11 +110,6 @@ QString AutotoolsProject::displayName() const
return m_projectName;
}
Core::IDocument *AutotoolsProject::document() const
{
return m_file;
}
IProjectManager *AutotoolsProject::projectManager() const
{
return m_manager;
......
......@@ -74,10 +74,9 @@ public:
~AutotoolsProject() override;
QString displayName() const override;
Core::IDocument *document() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
ProjectExplorer::ProjectNode *rootProjectNode() const override;
QStringList files(FilesMode fileMode) const;
QStringList files(FilesMode fileMode) const override;
static QString defaultBuildDirectory(const QString &projectPath);
QStringList buildTargets() const;
......@@ -147,9 +146,6 @@ private:
/// Return value for AutotoolsProject::files()
QStringList m_files;
/// Return value for AutotoolsProject::file()
AutotoolsProjectFile *m_file;
/// Return value for AutotoolsProject::rootProjectNode()
AutotoolsProjectNode *m_rootNode;
......
......@@ -37,9 +37,7 @@
using namespace AutotoolsProjectManager;
using namespace AutotoolsProjectManager::Internal;
AutotoolsProjectFile::AutotoolsProjectFile(AutotoolsProject *project, const QString &fileName) :
Core::IDocument(project),
m_project(project)
AutotoolsProjectFile::AutotoolsProjectFile(const QString &fileName)
{
setId("Autotools.ProjectFile");
setMimeType(QLatin1String(Constants::MAKEFILE_MIMETYPE));
......
......@@ -55,7 +55,7 @@ class AutotoolsProjectFile : public Core::IDocument
Q_OBJECT
public:
AutotoolsProjectFile(AutotoolsProject *project, const QString &fileName);
AutotoolsProjectFile(const QString &fileName);
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
QString defaultPath() const override;
......@@ -63,9 +63,6 @@ public:
bool isModified() const override;
bool isSaveAsAllowed() const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
private:
AutotoolsProject *m_project;
};
} // namespace Internal
......
......@@ -39,8 +39,7 @@ using namespace Utils;
namespace CMakeProjectManager {
namespace Internal {
CMakeFile::CMakeFile(CMakeProject *parent, const FileName &fileName)
: Core::IDocument(parent), m_project(parent)
CMakeFile::CMakeFile(const FileName &fileName)
{
setId("Cmake.ProjectFile");
setMimeType(QLatin1String(Constants::CMAKEPROJECTMIMETYPE));
......
......@@ -42,7 +42,7 @@ class CMakeFile : public Core::IDocument
{
Q_OBJECT
public:
CMakeFile(CMakeProject *parent, const Utils::FileName &fileName);
CMakeFile(const Utils::FileName &fileName);
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
......@@ -54,9 +54,6 @@ public:
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
private:
CMakeProject *m_project;
};
} // namespace Internal
......
......@@ -95,13 +95,12 @@ CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName)
m_watcher(new QFileSystemWatcher(this))
{
setId(Constants::CMAKEPROJECT_ID);
setDocument(new CMakeFile(fileName));
setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
m_rootNode->setDisplayName(fileName.parentDir().fileName());
m_file = new CMakeFile(this, fileName);
connect(this, &CMakeProject::buildTargetsChanged, this, &CMakeProject::updateRunConfigurations);
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &CMakeProject::fileChanged);
}
......@@ -512,11 +511,6 @@ QString CMakeProject::displayName() const
return m_rootNode->displayName();
}
Core::IDocument *CMakeProject::document() const
{
return m_file;
}
IProjectManager *CMakeProject::projectManager() const
{
return m_manager;
......
......@@ -99,7 +99,6 @@ public:
~CMakeProject() override;
QString displayName() const override;
Core::IDocument *document() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
ProjectExplorer::ProjectNode *rootProjectNode() const override;
......@@ -151,7 +150,6 @@ private:
Internal::CMakeManager *m_manager;
ProjectExplorer::Target *m_activeTarget;
Utils::FileName m_fileName;
Internal::CMakeFile *m_file;
// TODO probably need a CMake specific node structure
Internal::CMakeProjectNode *m_rootNode;
......
......@@ -50,7 +50,6 @@ public:
~TestProject() override;
QString displayName() const override { return m_name; }
Core::IDocument *document() const override { return 0; }
ProjectExplorer::IProjectManager *projectManager() const override { return 0; }
ProjectExplorer::ProjectNode *rootProjectNode() const override { return 0; }
......
......@@ -72,6 +72,7 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
m_fileName(fileName)
{
setId(Constants::GENERICPROJECT_ID);
setDocument(new GenericProjectFile(this, m_fileName, GenericProject::Everything));
setProjectContext(Context(GenericProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX));
......@@ -83,12 +84,11 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
m_includesFileName = QFileInfo(dir, m_projectName + QLatin1String(".includes")).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_includesIDocument = new GenericProjectFile(this, m_includesFileName, 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_includesIDocument);
DocumentManager::addDocument(m_configIDocument);
......@@ -388,11 +388,6 @@ QString GenericProject::displayName() const
return m_projectName;
}
IDocument *GenericProject::document() const
{
return m_creatorIDocument;
}
IProjectManager *GenericProject::projectManager() const
{
return m_manager;
......@@ -451,8 +446,8 @@ Project::RestoreResult GenericProject::fromMap(const QVariantMap &map, QString *
//
////////////////////////////////////////////////////////////////////////////////////
GenericProjectFile::GenericProjectFile(GenericProject *parent, QString fileName, GenericProject::RefreshOptions options)
: IDocument(parent),
GenericProjectFile::GenericProjectFile(GenericProject *parent, QString fileName,
GenericProject::RefreshOptions options) :
m_project(parent),
m_options(options)
{
......
......@@ -61,7 +61,6 @@ public:
QString configFileName() const;
QString displayName() const override;
Core::IDocument *document() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
GenericProjectNode *rootProjectNode() const override;
......@@ -103,7 +102,6 @@ private:
QString m_includesFileName;
QString m_configFileName;
QString m_projectName;
GenericProjectFile *m_creatorIDocument;
GenericProjectFile *m_filesIDocument;
GenericProjectFile *m_includesIDocument;
GenericProjectFile *m_configIDocument;
......
......@@ -90,17 +90,17 @@ namespace ProjectExplorer {
class ProjectPrivate
{
public:
ProjectPrivate();
~ProjectPrivate();
Core::Id m_id;
Core::IDocument *m_document = 0;
QList<Target *> m_targets;
Target *m_activeTarget;
Target *m_activeTarget = 0;
EditorConfiguration m_editorConfiguration;
Core::Context m_projectContext;
Core::Context m_projectLanguages;
QVariantMap m_pluginSettings;
Internal::UserFileAccessor *m_accessor;
Internal::UserFileAccessor *m_accessor = 0;
KitMatcher m_requiredKitMatcher;
KitMatcher m_preferredKitMatcher;
......@@ -108,13 +108,11 @@ public:
Utils::MacroExpander m_macroExpander;
};
ProjectPrivate::ProjectPrivate() :
m_activeTarget(0),
m_accessor(0)
{ }
ProjectPrivate::~ProjectPrivate()
{ delete m_accessor; }
{
delete m_accessor;
delete m_document;
}
Project::Project() : d(new ProjectPrivate)
{
......@@ -135,8 +133,15 @@ Core::Id Project::id() const
return d->m_id;
}
Core::IDocument *Project::document() const
{
QTC_CHECK(d->m_document);
return d->m_document;
}
Utils::FileName Project::projectFilePath() const
{
QTC_ASSERT(document(), return Utils::FileName());
return document()->filePath();
}
......@@ -412,6 +417,13 @@ void Project::setId(Core::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)
{
Core::Id id = idFromMap(data);
......
......@@ -79,10 +79,14 @@ public:
virtual QString displayName() const = 0;
Core::Id id() const;
virtual Core::IDocument *document() const = 0;
virtual IProjectManager *projectManager() const = 0;
Core::IDocument *document() 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;
......@@ -119,10 +123,6 @@ public:
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 projectLanguages() const;
......@@ -173,6 +173,7 @@ protected:
virtual bool setupTarget(Target *t);
void setId(Core::Id id);
void setDocument(Core::IDocument *doc); // takes ownership!
void setProjectContext(Core::Context context);
void setProjectLanguages(Core::Context language);
void addProjectLanguage(Core::Id id);
......
......@@ -1282,8 +1282,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
[this]() -> QString {
Utils::FileName projectFilePath;
if (Project *project = ProjectTree::currentProject())
if (IDocument *doc = project->document())
projectFilePath = doc->filePath();
projectFilePath = project->projectFilePath();
return projectFilePath.toString();
});
......
......@@ -1027,7 +1027,7 @@ bool SessionManager::loadSession(const QString &session)
auto end = oldProjects.end();
while (it != end) {
int index = fileList.indexOf((*it)->document()->filePath().toString());
int index = fileList.indexOf((*it)->projectFilePath().toString());
if (index != -1) {
fileList.removeAt(index);
it = oldProjects.erase(it);
......
......@@ -249,7 +249,6 @@ public:
~PythonProject() override;
QString displayName() const override { return m_projectName; }
IDocument *document() const override;
IProjectManager *projectManager() const override { return m_manager; }
ProjectNode *rootProjectNode() const override;
......@@ -274,7 +273,6 @@ private:
PythonProjectManager *m_manager;
QString m_projectFileName;
QString m_projectName;
PythonProjectFile *m_document;
QStringList m_rawFileList;
QStringList m_files;
QHash<QString, QString> m_rawListEntries;
......@@ -285,9 +283,7 @@ private:
class PythonProjectFile : public Core::IDocument
{
public:
PythonProjectFile(PythonProject *parent, QString fileName)
: IDocument(parent),
m_project(parent)
PythonProjectFile(PythonProject *parent, QString fileName) : m_project(parent)
{
setId("Generic.ProjectFile");
setMimeType(QLatin1String(PythonMimeType));
......@@ -626,16 +622,15 @@ PythonProject::PythonProject(PythonProjectManager *manager, const QString &fileN
m_projectFileName(fileName)
{
setId(PythonProjectId);
setDocument(new PythonProjectFile(this, m_projectFileName));
DocumentManager::addDocument(document());
setProjectContext(Context(PythonProjectContext));
setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX));
QFileInfo fileInfo(m_projectFileName);
m_projectName = fileInfo.completeBaseName();
m_document = new PythonProjectFile(this, m_projectFileName);
DocumentManager::addDocument(m_document);
m_rootNode = new PythonProjectNode(this);
m_manager->registerProject(this);
......@@ -648,11 +643,6 @@ PythonProject::~PythonProject()
delete m_rootNode;
}
IDocument *PythonProject::document() const
{
return m_document;
}
static QStringList readLines(const QString &absoluteFileName)
{
QStringList lines;
......
......@@ -113,6 +113,10 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
m_parsingDelay.setInterval(1000); // delay parsing by 1s.
setId(Constants::PROJECT_ID);
setDocument(new QbsProjectFile(this, m_fileName));
DocumentManager::addDocument(document());
setProjectContext(Context(Constants::PROJECT_ID));
setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX));
......@@ -124,8 +128,6 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
connect(&m_parsingDelay, SIGNAL(timeout()), this, SLOT(startParsing()));
updateDocuments(QSet<QString>() << fileName);
// NOTE: QbsProjectNode does not use this as a parent!
m_rootProjectNode = new QbsRootProjectNode(this); // needs documents to be initialized!
}
......@@ -153,15 +155,6 @@ QString QbsProject::displayName() const
return m_projectName;
}
IDocument *QbsProject::document() const
{
foreach (IDocument *doc, m_qbsDocuments) {
if (doc->filePath().toString() == m_fileName)
return doc;
}
QTC_ASSERT(false, return 0);
}
QbsManager *QbsProject::projectManager() const
{
return m_manager;
......
......@@ -66,7 +66,6 @@ public:
~QbsProject() override;
QString displayName() const override;
Core::IDocument *document() const override;
QbsManager *projectManager() const override;
ProjectExplorer::ProjectNode *rootProjectNode() const override;
......
......@@ -98,7 +98,7 @@ class QmakeProjectFile : public Core::IDocument
Q_OBJECT
public:
QmakeProjectFile(const QString &filePath, QObject *parent = 0);
QmakeProjectFile(const QString &filePath);
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
......@@ -251,8 +251,7 @@ void ProjectFilesVisitor::visitFolderNode(FolderNode *folderNode)
// ----------- QmakeProjectFile
namespace Internal {
QmakeProjectFile::QmakeProjectFile(const QString &filePath, QObject *parent)
: Core::IDocument(parent)
QmakeProjectFile::QmakeProjectFile(const QString &filePath)
{
setId("Qmake.ProFile");
setMimeType(QLatin1String(QmakeProjectManager::Constants::PROFILE_MIMETYPE));
......@@ -310,11 +309,11 @@ bool QmakeProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType
QmakeProject::QmakeProject(QmakeManager *manager, const QString &fileName) :
m_manager(manager),
m_fileInfo(new QmakeProjectFile(fileName, this)),
m_projectFiles(new QmakeProjectFiles),
m_qmakeVfs(new QMakeVfs)
{
setId(Constants::QMAKEPROJECT_ID);
setDocument(new QmakeProjectFile(fileName));
setProjectContext(Core::Context(QmakeProjectManager::Constants::PROJECT_ID));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
setRequiredKitMatcher(QtSupport::QtKitInformation::qtVersionMatcher());
......@@ -377,7 +376,7 @@ Project::RestoreResult QmakeProject::fromMap(const QVariantMap &map, QString *er
m_manager->registerProject(this);
m_rootProjectNode = new QmakeProFileNode(this, m_fileInfo->filePath());
m_rootProjectNode = new QmakeProFileNode(this, projectFilePath());
// On active buildconfiguration changes, reevaluate the .pro files
m_activeTarget = activeTarget();
......@@ -849,11 +848,6 @@ QString QmakeProject::displayName() const
return projectFilePath().toFileInfo().completeBaseName();
}
Core::IDocument *QmakeProject::document() const
{
return m_fileInfo;
}
QStringList QmakeProject::files(FilesMode fileMode) const
{
QStringList files;
......@@ -986,7 +980,7 @@ void QmakeProject::destroyProFileReader(QtSupport::ProFileReader *reader)
{
delete reader;
if (!--m_qmakeGlobalsRefCnt) {
QString dir = m_fileInfo->filePath().toFileInfo().absolutePath();
QString dir = projectFilePath().toString();
if (!dir.endsWith(QLatin1Char('/')))
dir += QLatin1Char('/');
QtSupport::ProFileCacheManager::instance()->discardFiles(dir);
......
......@@ -58,9 +58,9 @@ class QmakeProFileNode;
namespace Internal {
class CentralizedFolderWatcher;
class QmakeProjectFile;
class QmakeProjectFiles;
class QmakeProjectConfigWidget;
class QmakeProjectFile;
}
class QMAKEPROJECTMANAGER_EXPORT QmakeProject : public ProjectExplorer::Project
......@@ -72,7 +72,6 @@ public:
~QmakeProject() override;
QString displayName() const override;
Core::IDocument *document() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
QmakeManager *qmakeProjectManager() const;
......@@ -185,8 +184,6 @@ private:
QmakeManager *m_manager;
QmakeProFileNode *m_rootProjectNode = 0;
Internal::QmakeProjectFile *m_fileInfo = nullptr;
// Current configuration
QString m_oldQtIncludePath;
QString m_oldQtLibsPath;
......
......@@ -65,17 +65,17 @@ QmlProject::QmlProject(Internal::Manager *manager, const Utils::FileName &fileNa
m_activeTarget(0)
{
setId("QmlProjectManager.QmlProject");
setDocument(new Internal::QmlProjectFile(this, fileName));
DocumentManager::addDocument(document(), true);
setProjectContext(Context(QmlProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Context(ProjectExplorer::Constants::LANG_QMLJS));
QFileInfo fileInfo = m_fileName.toFileInfo();
m_projectName = fileInfo.completeBaseName();
m_file = new Internal::QmlProjectFile(this, fileName);
m_rootNode = new Internal::QmlProjectNode(this);
DocumentManager::addDocument(m_file, true);
m_manager->registerProject(this);
}
......@@ -83,8 +83,6 @@ QmlProject::~QmlProject()
{
m_manager->unregisterProject(this);
DocumentManager::removeDocument(m_file);
delete m_projectItem.data();
delete m_rootNode;
}
......@@ -292,11 +290,6 @@ QString QmlProject::displayName() const
return m_projectName;
}
IDocument *QmlProject::document() const
{
return m_file;
}
IProjectManager *QmlProject::projectManager() const
{
return m_manager;
......
......@@ -62,7 +62,6 @@ public:
Utils::FileName filesFileName() const;
QString displayName() const override;
Core::IDocument *document() const override;
ProjectExplorer::IProjectManager *projectManager() const override;
bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage) const override;
......@@ -112,7 +111,6 @@ private:
Internal::Manager *m_manager;
Utils::FileName m_fileName;
Internal::QmlProjectFile *m_file;
QString m_projectName;
QmlImport m_defaultImport;
ProjectExplorer::Target *m_activeTarget;
......
......@@ -36,9 +36,8 @@
namespace QmlProjectManager {
namespace Internal {
QmlProjectFile::QmlProjectFile(QmlProject *parent, const Utils::FileName &fileName)
: Core::IDocument(parent),
m_project(parent)
QmlProjectFile::QmlProjectFile(QmlProject *parent, const Utils::FileName &fileName) :
m_project(parent)
{
QTC_CHECK(m_project);
QTC_CHECK(!fileName.isEmpty());
......
......@@ -676,7 +676,7 @@ void VcsBasePlugin::createRepository()
// Find current starting directory
QString directory;
if (const Project *currentProject = ProjectTree::currentProject())
directory = currentProject->document()->filePath().toFileInfo().absolutePath();
directory = currentProject->projectFilePath().toString();
// Prompt for a directory that is not under version control yet
QWidget *mw = ICore::mainWindow();
do {
......
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