From ef9777412269f5b5cde862d133816373ef1ee57d Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 24 Nov 2022 17:29:55 +0100 Subject: [PATCH] Core: Rename ExternalTool::fileName() to filePath() Also, setFilePath(), and some code cosmetics. Change-Id: If24aa2d75276eafac4d7494153c5fc223be1ee8b Reviewed-by: Eike Ziller Reviewed-by: --- .../coreplugin/dialogs/externaltoolconfig.cpp | 20 +++++++++---------- src/plugins/coreplugin/externaltool.cpp | 11 +++++----- src/plugins/coreplugin/externaltool.h | 13 ++++++------ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp index d9d03501d0f..4f8d1e42cb8 100644 --- a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp +++ b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp @@ -323,7 +323,7 @@ void ExternalToolModel::revertTool(const QModelIndex &modelIndex) { ExternalTool *tool = toolForIndex(modelIndex); QTC_ASSERT(tool, return); - QTC_ASSERT(tool->preset() && !tool->preset()->fileName().isEmpty(), return); + QTC_ASSERT(tool->preset() && !tool->preset()->filePath().isEmpty(), return); auto resetTool = new ExternalTool(tool->preset().data()); resetTool->setPreset(tool->preset()); (*tool) = (*resetTool); @@ -832,23 +832,23 @@ void ExternalToolConfig::apply() // case 1: tool is changed preset if (tool->preset() && (*tool) != (*(tool->preset()))) { // check if we need to choose a new file name - if (tool->preset()->fileName() == tool->fileName()) { - const QString &fileName = tool->preset()->fileName().fileName(); + if (tool->preset()->filePath() == tool->filePath()) { + const QString &fileName = tool->preset()->filePath().fileName(); const FilePath &newFilePath = getUserFilePath(fileName); // TODO error handling if newFilePath.isEmpty() (i.e. failed to find a unused name) - tool->setFileName(newFilePath); + tool->setFilePath(newFilePath); } // TODO error handling tool->save(); // case 2: tool is previously changed preset but now same as preset } else if (tool->preset() && (*tool) == (*(tool->preset()))) { // check if we need to delete the changed description - if (originalTool->fileName() != tool->preset()->fileName() - && originalTool->fileName().exists()) { + if (originalTool->filePath() != tool->preset()->filePath() + && originalTool->filePath().exists()) { // TODO error handling - originalTool->fileName().removeFile(); + originalTool->filePath().removeFile(); } - tool->setFileName(tool->preset()->fileName()); + tool->setFilePath(tool->preset()->filePath()); // no need to save, it's the same as the preset // case 3: tool is custom tool } else { @@ -865,7 +865,7 @@ void ExternalToolConfig::apply() id = findUnusedId(id, newToolsMap); tool->setId(id); // TODO error handling if newFilePath.isEmpty() (i.e. failed to find a unused name) - tool->setFileName(getUserFilePath(id + QLatin1String(".xml"))); + tool->setFilePath(getUserFilePath(id + QLatin1String(".xml"))); // TODO error handling tool->save(); toolToAdd = new ExternalTool(tool); @@ -879,7 +879,7 @@ void ExternalToolConfig::apply() for (const ExternalTool *tool : std::as_const(originalTools)) { QTC_ASSERT(!tool->preset(), continue); // TODO error handling - tool->fileName().removeFile(); + tool->filePath().removeFile(); } ExternalToolManager::setToolsByCategory(resultMap); diff --git a/src/plugins/coreplugin/externaltool.cpp b/src/plugins/coreplugin/externaltool.cpp index 11be6adee7c..46da42d8d51 100644 --- a/src/plugins/coreplugin/externaltool.cpp +++ b/src/plugins/coreplugin/externaltool.cpp @@ -187,9 +187,9 @@ bool ExternalTool::modifiesCurrentDocument() const return m_modifiesCurrentDocument; } -void ExternalTool::setFileName(const Utils::FilePath &fileName) +void ExternalTool::setFilePath(const FilePath &filePath) { - m_filePath = fileName; + m_filePath = filePath; } void ExternalTool::setPreset(QSharedPointer preset) @@ -197,7 +197,7 @@ void ExternalTool::setPreset(QSharedPointer preset) m_presetTool = preset; } -Utils::FilePath ExternalTool::fileName() const +FilePath ExternalTool::filePath() const { return m_filePath; } @@ -440,9 +440,10 @@ ExternalTool * ExternalTool::createFromXml(const QByteArray &xml, QString *error return tool; } -ExternalTool * ExternalTool::createFromFile(const Utils::FilePath &fileName, QString *errorMessage, const QString &locale) +ExternalTool * ExternalTool::createFromFile(const FilePath &fileName, QString *errorMessage, + const QString &locale) { - Utils::FilePath absFileName = fileName.absoluteFilePath(); + FilePath absFileName = fileName.absoluteFilePath(); FileReader reader; if (!reader.fetch(absFileName, errorMessage)) return nullptr; diff --git a/src/plugins/coreplugin/externaltool.h b/src/plugins/coreplugin/externaltool.h index 8060f33ef62..b1a29b2468d 100644 --- a/src/plugins/coreplugin/externaltool.h +++ b/src/plugins/coreplugin/externaltool.h @@ -10,13 +10,12 @@ #include #include -#include -#include #include #include #include namespace Utils { class QtcProcess; } + namespace Core { class CORE_EXPORT ExternalTool : public QObject @@ -51,15 +50,16 @@ public: Utils::Environment baseEnvironment() const; Utils::EnvironmentItems environmentUserChanges() const; - void setFileName(const Utils::FilePath &fileName); + void setFilePath(const Utils::FilePath &filePath); void setPreset(QSharedPointer preset); - Utils::FilePath fileName() const; + Utils::FilePath filePath() const; // all tools that are preset (changed or unchanged) have the original value here: QSharedPointer preset() const; - static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = nullptr, const QString &locale = QString()); + static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = nullptr, + const QString &locale = {}); static ExternalTool *createFromFile(const Utils::FilePath &fileName, QString *errorMessage = nullptr, - const QString &locale = QString()); + const QString &locale = {}); bool save(QString *errorMessage = nullptr) const; @@ -105,6 +105,7 @@ private: class CORE_EXPORT ExternalToolRunner : public QObject { Q_OBJECT + public: ExternalToolRunner(const ExternalTool *tool); ~ExternalToolRunner() override;