From 219b2d9c162f780f8dd03089746ef4af01233164 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 8 Jan 2016 12:12:27 +0100 Subject: [PATCH] Project: Do not save filenames in derived classes Change-Id: I23960c61676e96c429b59ad8f8247e1b88606b1a Reviewed-by: Niels Weber Reviewed-by: Tobias Hunger --- .../autotoolsproject.cpp | 9 +++---- .../autotoolsproject.h | 2 -- .../cmakeprojectmanager/cmakeproject.cpp | 3 +-- .../cmakeprojectmanager/cmakeproject.h | 1 - .../cpptools/modelmanagertesthelper.cpp | 3 +-- .../genericprojectmanager/genericproject.cpp | 14 +++++----- .../genericprojectmanager/genericproject.h | 1 - .../pythoneditor/pythoneditorplugin.cpp | 27 +++++++++---------- src/plugins/qbsprojectmanager/qbsproject.cpp | 7 +++-- src/plugins/qbsprojectmanager/qbsproject.h | 1 - src/plugins/qmlprojectmanager/qmlproject.cpp | 14 +++++----- src/plugins/qmlprojectmanager/qmlproject.h | 1 - 12 files changed, 34 insertions(+), 49 deletions(-) diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp index ce1007456d9..e38cffcfa71 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp +++ b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp @@ -72,18 +72,17 @@ using namespace AutotoolsProjectManager::Internal; using namespace ProjectExplorer; AutotoolsProject::AutotoolsProject(AutotoolsManager *manager, const QString &fileName) : - m_fileName(fileName), m_fileWatcher(new Utils::FileSystemWatcher(this)), m_makefileParserThread(0) { setId(Constants::AUTOTOOLS_PROJECT_ID); setProjectManager(manager); - setDocument(new AutotoolsProjectFile(m_fileName)); + setDocument(new AutotoolsProjectFile(fileName)); m_rootNode = new AutotoolsProjectNode(projectFilePath()); setProjectContext(Core::Context(Constants::PROJECT_CONTEXT)); setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX)); - const QFileInfo fileInfo(m_fileName); + const QFileInfo fileInfo = projectFilePath().toFileInfo(); m_projectName = fileInfo.absoluteDir().dirName(); m_rootNode->setDisplayName(fileInfo.absoluteDir().dirName()); } @@ -161,7 +160,7 @@ void AutotoolsProject::loadProjectTree() } // Parse the makefile asynchronously in a thread - m_makefileParserThread = new MakefileParserThread(m_fileName); + m_makefileParserThread = new MakefileParserThread(projectFilePath().toString()); connect(m_makefileParserThread, &MakefileParserThread::started, this, &AutotoolsProject::makefileParsingStarted); @@ -207,7 +206,7 @@ void AutotoolsProject::makefileParsingFinished() m_watchedFiles.clear(); // Apply sources to m_files, which are returned at AutotoolsProject::files() - const QFileInfo fileInfo(m_fileName); + const QFileInfo fileInfo = projectFilePath().toFileInfo(); const QDir dir = fileInfo.absoluteDir(); QStringList files = m_makefileParserThread->sources(); foreach (const QString& file, files) diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.h b/src/plugins/autotoolsprojectmanager/autotoolsproject.h index 642da6c1bf0..d326202013f 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsproject.h +++ b/src/plugins/autotoolsprojectmanager/autotoolsproject.h @@ -135,8 +135,6 @@ private: void updateCppCodeModel(); private: - /// File name of the makefile that has been passed in the constructor - QString m_fileName; QString m_projectName; /// Return value for AutotoolsProject::files() diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 03e5ec9465b..a99f2abb598 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -88,7 +88,6 @@ using namespace Utils; \class CMakeProject */ CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName) : - m_fileName(fileName), m_rootNode(new CMakeProjectNode(fileName)), m_watcher(new QFileSystemWatcher(this)) { @@ -545,7 +544,7 @@ Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *er CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing; if (!cbpFileFi.exists()) mode = CMakeOpenProjectWizard::NeedToCreate; - else if (cbpFileFi.lastModified() < m_fileName.toFileInfo().lastModified()) + else if (cbpFileFi.lastModified() < projectFilePath().toFileInfo().lastModified()) mode = CMakeOpenProjectWizard::NeedToUpdate; if (mode != CMakeOpenProjectWizard::Nothing) { diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index 240c8116be0..91be3611007 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -147,7 +147,6 @@ private: QStringList getCXXFlagsFor(const CMakeBuildTarget &buildTarget, QByteArray *cachedBuildNinja); ProjectExplorer::Target *m_activeTarget = 0; - Utils::FileName m_fileName; // TODO probably need a CMake specific node structure Internal::CMakeProjectNode *m_rootNode; diff --git a/src/plugins/cpptools/modelmanagertesthelper.cpp b/src/plugins/cpptools/modelmanagertesthelper.cpp index 462d628e52d..2e50a6ffefa 100644 --- a/src/plugins/cpptools/modelmanagertesthelper.cpp +++ b/src/plugins/cpptools/modelmanagertesthelper.cpp @@ -42,8 +42,7 @@ Q_DECLARE_METATYPE(QSet) using namespace CppTools::Internal; using namespace CppTools::Tests; -TestProject::TestProject(const QString &name, QObject *parent) - : m_name (name) +TestProject::TestProject(const QString &name, QObject *parent) : m_name (name) { setParent(parent); setId(Core::Id::fromString(name)); diff --git a/src/plugins/genericprojectmanager/genericproject.cpp b/src/plugins/genericprojectmanager/genericproject.cpp index b430fe522b3..1e8667039bf 100644 --- a/src/plugins/genericprojectmanager/genericproject.cpp +++ b/src/plugins/genericprojectmanager/genericproject.cpp @@ -67,15 +67,15 @@ namespace Internal { // //////////////////////////////////////////////////////////////////////////////////// -GenericProject::GenericProject(Manager *manager, const QString &fileName) : m_fileName(fileName) +GenericProject::GenericProject(Manager *manager, const QString &fileName) { setId(Constants::GENERICPROJECT_ID); setProjectManager(manager); - setDocument(new GenericProjectFile(this, m_fileName, GenericProject::Everything)); + setDocument(new GenericProjectFile(this, fileName, GenericProject::Everything)); setProjectContext(Context(GenericProjectManager::Constants::PROJECTCONTEXT)); setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX)); - QFileInfo fileInfo(m_fileName); + QFileInfo fileInfo = projectFilePath().toFileInfo(); QDir dir = fileInfo.dir(); m_projectName = fileInfo.completeBaseName(); @@ -184,7 +184,7 @@ bool GenericProject::addFiles(const QStringList &filePaths) { QStringList newList = m_rawFileList; - QDir baseDir(QFileInfo(m_fileName).dir()); + QDir baseDir(projectDirectory().toString()); foreach (const QString &filePath, filePaths) newList.append(baseDir.relativeFilePath(filePath)); @@ -229,7 +229,7 @@ bool GenericProject::removeFiles(const QStringList &filePaths) bool GenericProject::setFiles(const QStringList &filePaths) { QStringList newList; - QDir baseDir(QFileInfo(m_fileName).dir()); + QDir baseDir(projectDirectory().toString()); foreach (const QString &filePath, filePaths) newList.append(baseDir.relativeFilePath(filePath)); @@ -244,7 +244,7 @@ bool GenericProject::renameFile(const QString &filePath, const QString &newFileP if (i != m_rawListEntries.end()) { int index = newList.indexOf(i.value()); if (index != -1) { - QDir baseDir(QFileInfo(m_fileName).dir()); + QDir baseDir(projectDirectory().toString()); newList.replace(index, baseDir.relativeFilePath(newFilePath)); } } @@ -316,7 +316,7 @@ QStringList GenericProject::processEntries(const QStringList &paths, QHash *map) const { const QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - const QDir projectDir(QFileInfo(m_fileName).dir()); + const QDir projectDir(projectDirectory().toString()); QFileInfo fileInfo; QStringList absolutePaths; diff --git a/src/plugins/genericprojectmanager/genericproject.h b/src/plugins/genericprojectmanager/genericproject.h index 95a2e7d7e85..f2cc2171f4d 100644 --- a/src/plugins/genericprojectmanager/genericproject.h +++ b/src/plugins/genericprojectmanager/genericproject.h @@ -96,7 +96,6 @@ private: void refreshCppCodeModel(); - QString m_fileName; QString m_filesFileName; QString m_includesFileName; QString m_configFileName; diff --git a/src/plugins/pythoneditor/pythoneditorplugin.cpp b/src/plugins/pythoneditor/pythoneditorplugin.cpp index 66b4d4085db..226d7e558b4 100644 --- a/src/plugins/pythoneditor/pythoneditorplugin.cpp +++ b/src/plugins/pythoneditor/pythoneditorplugin.cpp @@ -270,7 +270,6 @@ private: QStringList processEntries(const QStringList &paths, QHash *map = 0) const; - QString m_projectFileName; QString m_projectName; QStringList m_rawFileList; QStringList m_files; @@ -615,19 +614,17 @@ private: } }; - -PythonProject::PythonProject(PythonProjectManager *manager, const QString &fileName) : - m_projectFileName(fileName) +PythonProject::PythonProject(PythonProjectManager *manager, const QString &fileName) { setId(PythonProjectId); setProjectManager(manager); - setDocument(new PythonProjectFile(this, m_projectFileName)); + setDocument(new PythonProjectFile(this, fileName)); DocumentManager::addDocument(document()); setProjectContext(Context(PythonProjectContext)); setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX)); - QFileInfo fileInfo(m_projectFileName); + QFileInfo fileInfo = projectFilePath().toFileInfo(); m_projectName = fileInfo.completeBaseName(); m_rootNode = new PythonProjectNode(this); @@ -669,7 +666,7 @@ static QStringList readLines(const QString &absoluteFileName) bool PythonProject::saveRawFileList(const QStringList &rawFileList) { - bool result = saveRawList(rawFileList, m_projectFileName); + bool result = saveRawList(rawFileList, projectFilePath().toString()); // refresh(PythonProject::Files); return result; } @@ -694,7 +691,7 @@ bool PythonProject::addFiles(const QStringList &filePaths) { QStringList newList = m_rawFileList; - QDir baseDir(QFileInfo(m_projectFileName).dir()); + QDir baseDir(projectDirectory().toString()); foreach (const QString &filePath, filePaths) newList.append(baseDir.relativeFilePath(filePath)); @@ -706,7 +703,7 @@ bool PythonProject::addFiles(const QStringList &filePaths) toAdd << directory; } - bool result = saveRawList(newList, m_projectFileName); + bool result = saveRawList(newList, projectFilePath().toString()); refresh(); return result; @@ -728,7 +725,7 @@ bool PythonProject::removeFiles(const QStringList &filePaths) bool PythonProject::setFiles(const QStringList &filePaths) { QStringList newList; - QDir baseDir(QFileInfo(m_projectFileName).dir()); + QDir baseDir(projectFilePath().toString()); foreach (const QString &filePath, filePaths) newList.append(baseDir.relativeFilePath(filePath)); @@ -743,7 +740,7 @@ bool PythonProject::renameFile(const QString &filePath, const QString &newFilePa if (i != m_rawListEntries.end()) { int index = newList.indexOf(i.value()); if (index != -1) { - QDir baseDir(QFileInfo(m_projectFileName).dir()); + QDir baseDir(projectFilePath().toString()); newList.replace(index, baseDir.relativeFilePath(newFilePath)); } } @@ -754,8 +751,8 @@ bool PythonProject::renameFile(const QString &filePath, const QString &newFilePa void PythonProject::parseProject() { m_rawListEntries.clear(); - m_rawFileList = readLines(m_projectFileName); - m_rawFileList << FileName::fromString(m_projectFileName).fileName(); + m_rawFileList = readLines(projectFilePath().toString()); + m_rawFileList << projectFilePath().fileName(); m_files = processEntries(m_rawFileList, &m_rawListEntries); emit fileListChanged(); } @@ -781,7 +778,7 @@ void PythonProject::refresh() m_rootNode->removeFileNodes(m_rootNode->fileNodes()); parseProject(); - QDir baseDir = FileName::fromString(m_projectFileName).toFileInfo().absoluteDir(); + QDir baseDir(projectDirectory().toString()); QList fileNodes; foreach (const QString &file, m_files) { @@ -822,7 +819,7 @@ QStringList PythonProject::processEntries(const QStringList &paths, QHash *map) const { const QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - const QDir projectDir(QFileInfo(m_projectFileName).dir()); + const QDir projectDir(projectDirectory().toString()); QFileInfo fileInfo; QStringList absolutePaths; diff --git a/src/plugins/qbsprojectmanager/qbsproject.cpp b/src/plugins/qbsprojectmanager/qbsproject.cpp index b396589ed93..9d870e80a3c 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.cpp +++ b/src/plugins/qbsprojectmanager/qbsproject.cpp @@ -101,7 +101,6 @@ static const char CONFIG_PRECOMPILEDHEADER[] = "precompiledHeader"; QbsProject::QbsProject(QbsManager *manager, const QString &fileName) : m_projectName(QFileInfo(fileName).completeBaseName()), - m_fileName(fileName), m_rootProjectNode(0), m_qbsProjectParser(0), m_qbsUpdateFutureInterface(0), @@ -114,7 +113,7 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) : setId(Constants::PROJECT_ID); setProjectManager(manager); - setDocument(new QbsProjectFile(this, m_fileName)); + setDocument(new QbsProjectFile(this, fileName)); DocumentManager::addDocument(document()); setProjectContext(Context(Constants::PROJECT_ID)); @@ -458,7 +457,7 @@ void QbsProject::handleQbsParsingDone(bool success) m_rootProjectNode->update(); updateDocuments(m_qbsProject.isValid() - ? m_qbsProject.buildSystemFiles() : QSet() << m_fileName); + ? m_qbsProject.buildSystemFiles() : QSet() << projectFilePath().toString()); dataChanged = true; } } else { @@ -662,7 +661,7 @@ void QbsProject::updateDocuments(const QSet &files) { // Update documents: QSet newFiles = files; - QTC_ASSERT(!newFiles.isEmpty(), newFiles << m_fileName); + QTC_ASSERT(!newFiles.isEmpty(), newFiles << projectFilePath().toString()); QSet oldFiles; foreach (IDocument *doc, m_qbsDocuments) oldFiles.insert(doc->filePath().toString()); diff --git a/src/plugins/qbsprojectmanager/qbsproject.h b/src/plugins/qbsprojectmanager/qbsproject.h index f84c6f89fa9..3524ab0b7a4 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.h +++ b/src/plugins/qbsprojectmanager/qbsproject.h @@ -146,7 +146,6 @@ private: const qbs::GroupData &oldGroup); const QString m_projectName; - const QString m_fileName; qbs::Project m_qbsProject; qbs::ProjectData m_projectData; QSet m_qbsDocuments; diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index ef8589e7d37..ba60ebed9fe 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -59,7 +59,6 @@ namespace Internal { } // namespace Internal QmlProject::QmlProject(Internal::Manager *manager, const Utils::FileName &fileName) : - m_fileName(fileName), m_defaultImport(UnknownImport) { setId("QmlProjectManager.QmlProject"); @@ -70,8 +69,7 @@ QmlProject::QmlProject(Internal::Manager *manager, const Utils::FileName &fileNa setProjectContext(Context(QmlProjectManager::Constants::PROJECTCONTEXT)); setProjectLanguages(Context(ProjectExplorer::Constants::LANG_QMLJS)); - QFileInfo fileInfo = m_fileName.toFileInfo(); - m_projectName = fileInfo.completeBaseName(); + m_projectName = projectFilePath().toFileInfo().completeBaseName(); m_rootNode = new Internal::QmlProjectNode(this); @@ -127,7 +125,7 @@ QDir QmlProject::projectDir() const } Utils::FileName QmlProject::filesFileName() const -{ return m_fileName; } +{ return projectFilePath(); } static QmlProject::QmlImport detectImport(const QString &qml) { static QRegExp qtQuick1RegExp(QLatin1String("import\\s+QtQuick\\s+1")); @@ -148,14 +146,14 @@ void QmlProject::parseProject(RefreshOptions options) delete m_projectItem.data(); if (!m_projectItem) { QString errorMessage; - m_projectItem = QmlProjectFileFormat::parseProjectFile(m_fileName, &errorMessage); + m_projectItem = QmlProjectFileFormat::parseProjectFile(projectFilePath(), &errorMessage); if (m_projectItem) { connect(m_projectItem.data(), SIGNAL(qmlFilesChanged(QSet,QSet)), this, SLOT(refreshFiles(QSet,QSet))); } else { MessageManager::write(tr("Error while loading project file %1.") - .arg(m_fileName.toUserOutput()), + .arg(projectFilePath().toUserOutput()), MessageManager::NoModeSwitch); MessageManager::write(errorMessage); } @@ -172,7 +170,7 @@ void QmlProject::parseProject(RefreshOptions options) QString errorMessage; if (!reader.fetch(mainFilePath, &errorMessage)) { MessageManager::write(tr("Warning while loading project file %1.") - .arg(m_fileName.toUserOutput())); + .arg(projectFilePath().toUserOutput())); MessageManager::write(errorMessage); } else { m_defaultImport = detectImport(QString::fromUtf8(reader.data())); @@ -211,7 +209,7 @@ void QmlProject::refresh(RefreshOptions options) QStringList QmlProject::convertToAbsoluteFiles(const QStringList &paths) const { - const QDir projectDir(m_fileName.toFileInfo().dir()); + const QDir projectDir(projectDirectory().toString()); QStringList absolutePaths; foreach (const QString &file, paths) { QFileInfo fileInfo(projectDir, file); diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index 702837f831b..d499a8aea95 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -110,7 +110,6 @@ private: QStringList convertToAbsoluteFiles(const QStringList &paths) const; QmlJS::ModelManagerInterface *modelManager() const; - Utils::FileName m_fileName; QString m_projectName; QmlImport m_defaultImport; ProjectExplorer::Target *m_activeTarget = 0;