From d735d3238f4dc97f2858b799fa79b9ee66f4219d Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 11 Aug 2021 09:12:01 +0200 Subject: [PATCH] Core: Use more FilePath in ShortCutSettings and ActionManager Change-Id: I0ef1afd554cf7785bb80417651f2bcf54d9cf6be Reviewed-by: Qt CI Bot Reviewed-by: Eike Ziller --- .../coreplugin/actionmanager/commandsfile.cpp | 29 ++++++------------- .../coreplugin/actionmanager/commandsfile.h | 6 ++-- .../coreplugin/dialogs/shortcutsettings.cpp | 10 +++---- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/plugins/coreplugin/actionmanager/commandsfile.cpp b/src/plugins/coreplugin/actionmanager/commandsfile.cpp index 498661d7b2d..fff6c6779f6 100644 --- a/src/plugins/coreplugin/actionmanager/commandsfile.cpp +++ b/src/plugins/coreplugin/actionmanager/commandsfile.cpp @@ -47,24 +47,13 @@ namespace Internal { struct Context // XML parsing context with strings. { - Context(); - - const QString mappingElement; - const QString shortCutElement; - const QString idAttribute; - const QString keyElement; - const QString valueAttribute; + const QString mappingElement = "mapping"; + const QString shortCutElement = "shortcut"; + const QString idAttribute = "id"; + const QString keyElement = "key"; + const QString valueAttribute = "value"; }; -Context::Context() : - mappingElement(QLatin1String("mapping")), - shortCutElement(QLatin1String("shortcut")), - idAttribute(QLatin1String("id")), - keyElement(QLatin1String("key")), - valueAttribute(QLatin1String("value")) -{ -} - /*! \class Core::Internal::CommandsFile \internal @@ -76,8 +65,8 @@ Context::Context() : /*! \internal */ -CommandsFile::CommandsFile(const QString &filename) - : m_filename(filename) +CommandsFile::CommandsFile(const FilePath &filename) + : m_filePath(filename) { } @@ -89,7 +78,7 @@ QMap> CommandsFile::importCommands() const { QMap> result; - QFile file(m_filename); + QFile file(m_filePath.toString()); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) return result; @@ -130,7 +119,7 @@ QMap> CommandsFile::importCommands() const bool CommandsFile::exportCommands(const QList &items) { - Utils::FileSaver saver(Utils::FilePath::fromString(m_filename), QIODevice::Text); + FileSaver saver(m_filePath, QIODevice::Text); if (!saver.hasError()) { const Context ctx; QXmlStreamWriter w(saver.file()); diff --git a/src/plugins/coreplugin/actionmanager/commandsfile.h b/src/plugins/coreplugin/actionmanager/commandsfile.h index cd4bceeeeb6..6713a76110e 100644 --- a/src/plugins/coreplugin/actionmanager/commandsfile.h +++ b/src/plugins/coreplugin/actionmanager/commandsfile.h @@ -25,6 +25,8 @@ #pragma once +#include + #include #include #include @@ -41,13 +43,13 @@ class CommandsFile : public QObject Q_OBJECT public: - CommandsFile(const QString &filename); + CommandsFile(const Utils::FilePath &filePath); QMap > importCommands() const; bool exportCommands(const QList &items); private: - QString m_filename; + Utils::FilePath m_filePath; }; } // namespace Internal diff --git a/src/plugins/coreplugin/dialogs/shortcutsettings.cpp b/src/plugins/coreplugin/dialogs/shortcutsettings.cpp index 5dec4bb4f9f..47931847b6c 100644 --- a/src/plugins/coreplugin/dialogs/shortcutsettings.cpp +++ b/src/plugins/coreplugin/dialogs/shortcutsettings.cpp @@ -490,10 +490,10 @@ void ShortcutSettingsWidget::resetToDefault() void ShortcutSettingsWidget::importAction() { - QString fileName = QFileDialog::getOpenFileName(ICore::dialogParent(), - tr("Import Keyboard Mapping Scheme"), - schemesPath().toString(), - tr("Keyboard Mapping Scheme (*.kms)")); + FilePath fileName = FileUtils::getOpenFilePath(nullptr, + tr("Import Keyboard Mapping Scheme"), + schemesPath(), + tr("Keyboard Mapping Scheme (*.kms)")); if (!fileName.isEmpty()) { CommandsFile cf(fileName); @@ -535,7 +535,7 @@ void ShortcutSettingsWidget::exportAction() schemesPath().toString(), tr("Keyboard Mapping Scheme (*.kms)")); if (!fileName.isEmpty()) { - CommandsFile cf(fileName); + CommandsFile cf(FilePath::fromString(fileName)); cf.exportCommands(m_scitems); } }