Core: Rename ExternalTool::fileName() to filePath()

Also, setFilePath(), and some code cosmetics.

Change-Id: If24aa2d75276eafac4d7494153c5fc223be1ee8b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-11-24 17:29:55 +01:00
parent 67e9c2d7a0
commit ef97774122
3 changed files with 23 additions and 21 deletions

View File

@@ -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);

View File

@@ -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<ExternalTool> preset)
@@ -197,7 +197,7 @@ void ExternalTool::setPreset(QSharedPointer<ExternalTool> 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;

View File

@@ -10,13 +10,12 @@
#include <utils/id.h>
#include <QObject>
#include <QStringList>
#include <QProcess>
#include <QSharedPointer>
#include <QTextCodec>
#include <QMetaType>
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<ExternalTool> preset);
Utils::FilePath fileName() const;
Utils::FilePath filePath() const;
// all tools that are preset (changed or unchanged) have the original value here:
QSharedPointer<ExternalTool> 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;