Commit 219b2d9c authored by Tobias Hunger's avatar Tobias Hunger

Project: Do not save filenames in derived classes

Change-Id: I23960c61676e96c429b59ad8f8247e1b88606b1a
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 21d204ad
......@@ -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)
......
......@@ -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()
......
......@@ -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) {
......
......@@ -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;
......
......@@ -42,8 +42,7 @@ Q_DECLARE_METATYPE(QSet<QString>)
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));
......
......@@ -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<QString, QString> *map) const
{
const QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
const QDir projectDir(QFileInfo(m_fileName).dir());
const QDir projectDir(projectDirectory().toString());
QFileInfo fileInfo;
QStringList absolutePaths;
......
......@@ -96,7 +96,6 @@ private:
void refreshCppCodeModel();
QString m_fileName;
QString m_filesFileName;
QString m_includesFileName;
QString m_configFileName;
......
......@@ -270,7 +270,6 @@ private:
QStringList processEntries(const QStringList &paths,
QHash<QString, QString> *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<FileNode *> fileNodes;
foreach (const QString &file, m_files) {
......@@ -822,7 +819,7 @@ QStringList PythonProject::processEntries(const QStringList &paths,
QHash<QString, QString> *map) const
{
const QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
const QDir projectDir(QFileInfo(m_projectFileName).dir());
const QDir projectDir(projectDirectory().toString());
QFileInfo fileInfo;
QStringList absolutePaths;
......
......@@ -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<QString>() << m_fileName);
? m_qbsProject.buildSystemFiles() : QSet<QString>() << projectFilePath().toString());
dataChanged = true;
}
} else {
......@@ -662,7 +661,7 @@ void QbsProject::updateDocuments(const QSet<QString> &files)
{
// Update documents:
QSet<QString> newFiles = files;
QTC_ASSERT(!newFiles.isEmpty(), newFiles << m_fileName);
QTC_ASSERT(!newFiles.isEmpty(), newFiles << projectFilePath().toString());
QSet<QString> oldFiles;
foreach (IDocument *doc, m_qbsDocuments)
oldFiles.insert(doc->filePath().toString());
......
......@@ -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<Core::IDocument *> m_qbsDocuments;
......
......@@ -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<QString>,QSet<QString>)),
this, SLOT(refreshFiles(QSet<QString>,QSet<QString>)));
} 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);
......
......@@ -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;
......
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