From ca14fc00dccadf31bb1de1b3547bf45cac200fb1 Mon Sep 17 00:00:00 2001 From: Project579 Date: Fri, 19 Aug 2022 22:33:51 +0000 Subject: [PATCH] Added dedicated functions for conversions between QString and std::filesystem::path. --- apps/launcher/datafilespage.cpp | 11 ++++--- apps/launcher/maindialog.cpp | 29 ++++++++++-------- apps/launcher/settingspage.cpp | 11 +++++-- apps/opencs/editor.cpp | 17 +++++++---- apps/opencs/model/doc/runner.cpp | 16 +++++----- apps/opencs/view/doc/adjusterwidget.cpp | 12 ++++---- apps/opencs/view/doc/loader.cpp | 13 ++++---- apps/opencs/view/doc/viewmanager.cpp | 6 ++-- apps/opencs/view/tools/merge.cpp | 15 ++++++---- apps/wizard/mainwizard.cpp | 40 ++++++++++++------------- apps/wizard/mainwizard.hpp | 3 -- components/CMakeLists.txt | 4 +++ components/config/gamesettings.cpp | 25 +++++++--------- components/config/launchersettings.cpp | 4 ++- components/files/qtconversion.cpp | 28 +++++++++++++++++ components/files/qtconversion.hpp | 18 +++++++++++ 16 files changed, 164 insertions(+), 88 deletions(-) create mode 100644 components/files/qtconversion.cpp create mode 100644 components/files/qtconversion.hpp diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 7d00c05bba..e7b03164b6 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -19,13 +19,15 @@ #include #include -#include #include +#include +#include #include +#include #include -#include "utils/textinputdialog.hpp" #include "utils/profilescombobox.hpp" +#include "utils/textinputdialog.hpp" #include "ui_directorypicker.h" @@ -232,7 +234,7 @@ void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName) const auto& globalDataDir = mGameSettings.getGlobalDataDir(); if (!globalDataDir.empty()) - directories.insert(0, QString::fromStdU32String(globalDataDir.u32string())); + directories.insert(0, Files::pathToQString(globalDataDir)); // normalize user supplied directories: resolve symlink, convert to native separator, make absolute for (auto& currentDir : directories) @@ -264,7 +266,8 @@ void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName) } // deactivate data-local and global data directory: they are always included - if (currentDir == mDataLocal || std::filesystem::path(currentDir.toStdU32String()) == globalDataDir) + const auto tmp = currentDir.toUtf8(); + if (currentDir == mDataLocal || std::filesystem::path(Misc::StringUtils::stringToU8String(tmp)) == globalDataDir) { auto flags = item->flags(); item->setFlags(flags & ~(Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::ItemIsEnabled)); diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 830a80d01d..a8e7a89b54 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -13,12 +13,13 @@ #include #include #include +#include -#include "playpage.hpp" -#include "graphicspage.hpp" -#include "datafilespage.hpp" -#include "settingspage.hpp" #include "advancedpage.hpp" +#include "datafilespage.hpp" +#include "graphicspage.hpp" +#include "playpage.hpp" +#include "settingspage.hpp" using namespace Process; @@ -163,7 +164,7 @@ Launcher::FirstRunDialogResult Launcher::MainDialog::showFirstRunDialog() cfgError(tr("Error opening OpenMW configuration file"), tr("
Could not create directory %0

\ Please make sure you have the right permissions \ - and try again.
").arg(QString::fromStdU32String(canonical(userConfigDir).u32string())) + and try again.
").arg(Files::pathToQString(canonical(userConfigDir))) ); return FirstRunDialogResultFailure; } @@ -296,7 +297,7 @@ bool Launcher::MainDialog::setupLauncherSettings() mLauncherSettings.setMultiValueEnabled(true); - QString userPath = QString::fromStdU32String(mCfgMgr.getUserConfigPath().u32string()); + const auto userPath = Files::pathToQString(mCfgMgr.getUserConfigPath()); QStringList paths; paths.append(QString(Config::LauncherSettings::sLauncherConfigFileName)); @@ -329,9 +330,9 @@ bool Launcher::MainDialog::setupGameSettings() { mGameSettings.clear(); - QString localPath = QString::fromStdU32String(mCfgMgr.getLocalPath().u32string()); - QString userPath = QString::fromStdU32String(mCfgMgr.getUserConfigPath().u32string()); - QString globalPath = QString::fromStdU32String(mCfgMgr.getGlobalPath().u32string()); + const auto localPath = Files::pathToQString(mCfgMgr.getLocalPath()); + const auto userPath = Files::pathToQString(mCfgMgr.getUserConfigPath()); + const auto globalPath = Files::pathToQString(mCfgMgr.getGlobalPath()); QFile file; @@ -487,13 +488,17 @@ bool Launcher::MainDialog::writeSettings() cfgError(tr("Error creating OpenMW configuration directory"), tr("
Could not create %0

\ Please make sure you have the right permissions \ - and try again.
").arg(QString::fromStdU32String(userPath.u32string()))); + and try again.
").arg(Files::pathToQString(userPath))); return false; } } // Game settings - QFile file(QString::fromStdU32String((userPath / "openmw.cfg").u32string())); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QFile file(userPath / "openmw.cfg"); +#else + QFile file(Files::pathToQString(userPath / "openmw.cfg")); +#endif if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { // File cannot be opened or created @@ -521,7 +526,7 @@ bool Launcher::MainDialog::writeSettings() } // Launcher settings - file.setFileName(QString::fromStdU32String((userPath / Config::LauncherSettings::sLauncherConfigFileName).u32string())); + file.setFileName(Files::pathToQString(userPath / Config::LauncherSettings::sLauncherConfigFileName)); if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { // File cannot be opened or created diff --git a/apps/launcher/settingspage.cpp b/apps/launcher/settingspage.cpp index 325fa4dfa1..474b1a1c72 100644 --- a/apps/launcher/settingspage.cpp +++ b/apps/launcher/settingspage.cpp @@ -5,6 +5,9 @@ #include #include +#include +#include + #include "utils/textinputdialog.hpp" #include "datafilespage.hpp" @@ -104,7 +107,11 @@ void Launcher::SettingsPage::on_importerButton_clicked() // Create the file if it doesn't already exist, else the importer will fail auto path = mCfgMgr.getUserConfigPath(); path /= "openmw.cfg"; - QFile file(QString::fromStdU32String(path.u32string())); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QFile file(path); +#else + QFile file(Files::pathToQString(path)); +#endif if (!file.exists()) { if (!file.open(QIODevice::ReadWrite)) { @@ -137,7 +144,7 @@ void Launcher::SettingsPage::on_importerButton_clicked() arguments.append(QString("--ini")); arguments.append(settingsComboBox->currentText()); arguments.append(QString("--cfg")); - arguments.append(QString::fromStdU32String(path.u32string())); + arguments.append(Files::pathToQString(path)); qDebug() << "arguments " << arguments; diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 5f165a95a4..24d328e0c5 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -10,7 +10,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -230,8 +233,9 @@ void CS::Editor::openFiles (const std::filesystem::path &savePath, const std::ve if(discoveredFiles.empty()) { - for (const QString &path : mFileDialog.selectedFilePaths()) - files.emplace_back(path.toStdU32String()); + for (const QString &path : mFileDialog.selectedFilePaths()) { + files.emplace_back(Files::pathFromQString(path)); + } } else { @@ -248,7 +252,7 @@ void CS::Editor::createNewFile (const std::filesystem::path &savePath) std::vector files; for (const QString &path : mFileDialog.selectedFilePaths()) { - files.emplace_back(path.toStdU32String()); + files.emplace_back(Files::pathFromQString(path)); } files.push_back (savePath); @@ -320,12 +324,13 @@ bool CS::Editor::makeIPCServer() mServer->close(); fullPath.remove(QRegExp("dummy$")); fullPath += mIpcServerName; - if(std::filesystem::exists(fullPath.toUtf8().constData())) + const auto path = Files::pathFromQString(fullPath); + if(exists(path)) { // TODO: compare pid of the current process with that in the file Log(Debug::Info) << "Detected unclean shutdown."; // delete the stale file - if(remove(fullPath.toUtf8().constData())) + if(remove(path)) Log(Debug::Error) << "Error: can not remove stale connection file."; } } @@ -390,7 +395,7 @@ int CS::Editor::run() } discoveredFiles.push_back(mFileToLoad); - QString extension = QString::fromStdU32String(mFileToLoad.extension().u32string()).toLower(); + const auto extension = Files::pathToQString(mFileToLoad.extension()).toLower(); if (extension == ".esm") { mFileToLoad.replace_extension(".omwgame"); diff --git a/apps/opencs/model/doc/runner.cpp b/apps/opencs/model/doc/runner.cpp index dd99ede234..435a32d920 100644 --- a/apps/opencs/model/doc/runner.cpp +++ b/apps/opencs/model/doc/runner.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + #include "operationholder.hpp" CSMDoc::Runner::Runner (std::filesystem::path projectPath) @@ -80,22 +83,21 @@ void CSMDoc::Runner::start (bool delayed) else arguments << "--new-game=1"; - arguments << ("--script-run="+mStartup->fileName()); + arguments << ("--script-run=" + mStartup->fileName()); - arguments << - QString::fromStdU32String (U"--data=\""+mProjectPath.parent_path().u32string()+U"\""); + arguments << "--data=\"" + Files::pathToQString(mProjectPath.parent_path()) + "\""; arguments << "--replace=content"; - for (const auto & mContentFile : mContentFiles) + for (const auto& mContentFile : mContentFiles) { - arguments << QString::fromStdU32String (U"--content="+mContentFile.u32string()); + arguments << "--content=" + Files::pathToQString(mContentFile); } arguments - << QString::fromStdU32String (U"--content="+mProjectPath.filename().u32string()); + << "--content=" + Files::pathToQString(mProjectPath.filename()); - mProcess.start (path, arguments); + mProcess.start(path, arguments); } mRunning = true; diff --git a/apps/opencs/view/doc/adjusterwidget.cpp b/apps/opencs/view/doc/adjusterwidget.cpp index 791a1c556d..6dfd6b9d3e 100644 --- a/apps/opencs/view/doc/adjusterwidget.cpp +++ b/apps/opencs/view/doc/adjusterwidget.cpp @@ -1,12 +1,14 @@ #include "adjusterwidget.hpp" #include -#include - #include #include #include +#include +#include +#include + CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent) : QWidget (parent), mValid (false), mAction (ContentAction_Undefined) { @@ -68,7 +70,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) } else { - std::filesystem::path path (name.toStdU32String()); + auto path = Files::pathFromQString(name); const auto extension = Misc::StringUtils::lowerCase(path.extension().u8string()); @@ -85,7 +87,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) if (!isFilePathChanged && !isLegacyPath) { // path already points to the local data directory - message = QString::fromStdU32String (U"Will be saved as: " + path.u32string()); + message = "Will be saved as: " + Files::pathToQString(path); mResultPath = path; } //in all other cases, ensure the path points to data-local and do an existing file check @@ -95,7 +97,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) if (isFilePathChanged) path = mLocalData / path.filename(); - message = QString::fromStdU32String (U"Will be saved as: " + path.u32string()); + message = "Will be saved as: " + Files::pathToQString(path); mResultPath = path; if (std::filesystem::exists (path)) diff --git a/apps/opencs/view/doc/loader.cpp b/apps/opencs/view/doc/loader.cpp index 4e8eab0541..dd37176d76 100644 --- a/apps/opencs/view/doc/loader.cpp +++ b/apps/opencs/view/doc/loader.cpp @@ -8,6 +8,9 @@ #include #include +#include +#include + #include "../../model/doc/document.hpp" void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event) @@ -19,7 +22,7 @@ void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event) CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document) : mDocument (document), mTotalRecordsLabel (0), mRecordsLabel (0), mAborted (false), mMessages (nullptr), mRecords(0) { - setWindowTitle (QString::fromStdU32String(U"Opening " + document->getSavePath().filename().u32string())); + setWindowTitle ("Opening " + Files::pathToQString(document->getSavePath().filename())); setMinimumWidth (400); @@ -89,16 +92,16 @@ void CSVDoc::LoadingDocument::nextStage (const std::string& name, int fileRecord mRecords = fileRecords; } -void CSVDoc::LoadingDocument::nextRecord (int records) +void CSVDoc::LoadingDocument::nextRecord(int records) { if (records <= mRecords) { - mTotalProgress->setValue (mTotalRecords+records); + mTotalProgress->setValue(mTotalRecords + records); mRecordProgress->setValue(records); - mRecordsLabel->setText(QString::fromStdString( - "Records: "+std::to_string(records)+" of "+std::to_string(mRecords))); + mRecordsLabel->setText( + "Records: " + QString::number(records) + " of " + QString::number(mRecords)); } } diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 358bc05e8b..0c4c6a6d56 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -7,8 +7,10 @@ #include #include -#include "../../model/doc/documentmanager.hpp" +#include + #include "../../model/doc/document.hpp" +#include "../../model/doc/documentmanager.hpp" #include "../../model/doc/state.hpp" #include "../../model/world/columns.hpp" @@ -261,7 +263,7 @@ bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (CSVDoc::View *view) QMessageBox messageBox(view); CSMDoc::Document *document = view->getDocument(); - messageBox.setWindowTitle (QString::fromStdU32String(document->getSavePath().filename().u32string())); + messageBox.setWindowTitle (Files::pathToQString(document->getSavePath().filename())); messageBox.setText ("The document has been modified."); messageBox.setInformativeText ("Do you want to save your changes?"); messageBox.setStandardButtons (QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); diff --git a/apps/opencs/view/tools/merge.cpp b/apps/opencs/view/tools/merge.cpp index 8e78364cea..35f4b6c1d0 100644 --- a/apps/opencs/view/tools/merge.cpp +++ b/apps/opencs/view/tools/merge.cpp @@ -1,13 +1,16 @@ #include "merge.hpp" -#include #include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include + +#include +#include #include "../../model/doc/document.hpp" #include "../../model/doc/documentmanager.hpp" @@ -102,7 +105,7 @@ void CSVTools::Merge::configure (CSMDoc::Document *document) for (std::vector::const_iterator iter (files.begin()); iter!=files.end(); ++iter) - mFiles->addItem (QString::fromStdU32String(iter->filename().u32string())); + mFiles->addItem (Files::pathToQString(iter->filename())); } void CSVTools::Merge::setLocalData (const std::filesystem::path& localData) diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index aa25f1fd3e..39d0c4a90a 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -1,19 +1,22 @@ #include "mainwizard.hpp" -#include #include +#include +#include #include #include -#include -#include "intropage.hpp" -#include "methodselectionpage.hpp" -#include "languageselectionpage.hpp" -#include "existinginstallationpage.hpp" -#include "installationtargetpage.hpp" +#include +#include + #include "componentselectionpage.hpp" -#include "importpage.hpp" #include "conclusionpage.hpp" +#include "existinginstallationpage.hpp" +#include "importpage.hpp" +#include "installationtargetpage.hpp" +#include "intropage.hpp" +#include "languageselectionpage.hpp" +#include "methodselectionpage.hpp" #ifdef OPENMW_USE_UNSHIELD #include "installationpage.hpp" @@ -67,7 +70,7 @@ Wizard::MainWizard::MainWizard(QWidget *parent) : if (!installationPath.empty()) { const std::filesystem::path& dataPath = installationPath / "Data Files"; - addInstallation(toQString(dataPath)); + addInstallation(Files::pathToQString(dataPath)); } } @@ -78,7 +81,7 @@ Wizard::MainWizard::~MainWizard() void Wizard::MainWizard::setupLog() { - QString logPath(toQString(mCfgMgr.getLogPath())); + QString logPath(Files::pathToQString(mCfgMgr.getLogPath())); logPath.append(QLatin1String("wizard.log")); QFile file(logPath); @@ -101,7 +104,7 @@ void Wizard::MainWizard::setupLog() void Wizard::MainWizard::addLogText(const QString &text) { - QString logPath(toQString(mCfgMgr.getLogPath())); + QString logPath(Files::pathToQString(mCfgMgr.getLogPath())); logPath.append(QLatin1String("wizard.log")); QFile file(logPath); @@ -131,8 +134,8 @@ void Wizard::MainWizard::addLogText(const QString &text) void Wizard::MainWizard::setupGameSettings() { - QString userPath(toQString(mCfgMgr.getUserConfigPath())); - QString globalPath(toQString(mCfgMgr.getGlobalPath())); + QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath())); + QString globalPath(Files::pathToQString(mCfgMgr.getGlobalPath())); QString message(tr("

Could not open %1 for reading

\

Please make sure you have the right permissions \ and try again.

")); @@ -196,7 +199,7 @@ void Wizard::MainWizard::setupGameSettings() void Wizard::MainWizard::setupLauncherSettings() { - QString path(toQString(mCfgMgr.getUserConfigPath())); + QString path(Files::pathToQString(mCfgMgr.getUserConfigPath())); path.append(QLatin1String(Config::LauncherSettings::sLauncherConfigFileName)); QString message(tr("

Could not open %1 for reading

\ @@ -246,7 +249,7 @@ void Wizard::MainWizard::runSettingsImporter() QString path(field(QLatin1String("installation.path")).toString()); - QString userPath(toQString(mCfgMgr.getUserConfigPath())); + QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath())); QFile file(userPath + QLatin1String("openmw.cfg")); // Construct the arguments to run the importer @@ -392,7 +395,7 @@ void Wizard::MainWizard::writeSettings() mGameSettings.removeDataDir(path); mGameSettings.addDataDir(path); - QString userPath(toQString(mCfgMgr.getUserConfigPath())); + QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath())); QDir dir(userPath); if (!dir.exists()) { @@ -468,8 +471,3 @@ bool Wizard::MainWizard::findFiles(const QString &name, const QString &path) return (dir.entryList().contains(name + QLatin1String(".esm"), Qt::CaseInsensitive) && dir.entryList().contains(name + QLatin1String(".bsa"), Qt::CaseInsensitive)); } - -QString Wizard::MainWizard::toQString(const std::filesystem::path& path) -{ - return QString::fromStdU32String(path.u32string()); -} diff --git a/apps/wizard/mainwizard.hpp b/apps/wizard/mainwizard.hpp index 1316aa2ec0..cae446862b 100644 --- a/apps/wizard/mainwizard.hpp +++ b/apps/wizard/mainwizard.hpp @@ -58,9 +58,6 @@ namespace Wizard void addLogText(const QString &text); private: - /// convert std::filesystem::path to QString - QString toQString(const std::filesystem::path& path); - void setupLog(); void setupGameSettings(); void setupLauncherSettings(); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 9ddfc4eb5b..e9f5fdf6e4 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -379,6 +379,10 @@ if (USE_QT) helpviewer ) + add_component_qt_dir (files + qtconversion + ) + QT5_WRAP_UI(ESM_UI_HDR ${ESM_UI}) endif() diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index 36f0cdad08..3f844e01b5 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -4,9 +4,11 @@ #include #include #include -#include #include +#include +#include +#include const char Config::GameSettings::sArchiveKey[] = "fallback-archive"; const char Config::GameSettings::sContentKey[] = "content"; @@ -24,19 +26,16 @@ void Config::GameSettings::validatePaths() for (const QString &path : paths) { - dataDirs.emplace_back(path.toStdU32String()); + dataDirs.emplace_back(Files::pathFromQString(path)); } // Parse the data dirs to convert the tokenized paths mCfgMgr.processPaths(dataDirs, /*basePath=*/""); mDataDirs.clear(); - for (auto & dataDir : dataDirs) { - QString path = QString::fromStdU32String(dataDir.u32string()); - - QDir dir(path); - if (dir.exists()) - mDataDirs.append(path); + for (const auto & dataDir : dataDirs) { + if (is_directory(dataDir)) + mDataDirs.append(Files::pathToQString(dataDir)); } // Do the same for data-local @@ -51,16 +50,14 @@ void Config::GameSettings::validatePaths() return; dataDirs.clear(); - dataDirs.emplace_back(local.toStdU32String()); + dataDirs.emplace_back(Files::pathFromQString(local)); mCfgMgr.processPaths(dataDirs, /*basePath=*/""); if (!dataDirs.empty()) { - QString path = QString::fromStdU32String(dataDirs.front().u32string()); - - QDir dir(path); - if (dir.exists()) - mDataLocal = path; + const auto& path = dataDirs.front(); + if (is_directory(path)) + mDataLocal = Files::pathToQString(path); } } diff --git a/components/config/launchersettings.cpp b/components/config/launchersettings.cpp index b06203c2a2..f2f1275666 100644 --- a/components/config/launchersettings.cpp +++ b/components/config/launchersettings.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include const char Config::LauncherSettings::sCurrentContentListKey[] = "Profiles/currentprofile"; const char Config::LauncherSettings::sLauncherConfigFileName[] = "launcher.cfg"; @@ -119,7 +121,7 @@ void Config::LauncherSettings::setContentList(const GameSettings& gameSettings) } // global and local data directories are not part of any profile - const auto globalDataDir = QString::fromStdU32String(gameSettings.getGlobalDataDir().u32string()); + const auto globalDataDir = Files::pathToQString(gameSettings.getGlobalDataDir()); const auto dataLocal = gameSettings.getDataLocal(); dirs.removeAll(globalDataDir); dirs.removeAll(dataLocal); diff --git a/components/files/qtconversion.cpp b/components/files/qtconversion.cpp new file mode 100644 index 0000000000..d56832cb78 --- /dev/null +++ b/components/files/qtconversion.cpp @@ -0,0 +1,28 @@ + +#include "qtconversion.hpp" + +#include + +QString Files::pathToQString(const std::filesystem::path& path) +{ + const auto tmp = path.u8string(); + return QString::fromUtf8(Misc::StringUtils::u8StringToString(tmp.data()), tmp.size()); +} + +QString Files::pathToQString(std::filesystem::path&& path) +{ + const auto tmp = path.u8string(); + return QString::fromUtf8(Misc::StringUtils::u8StringToString(tmp.data()), tmp.size()); +} + +std::filesystem::path Files::pathFromQString(QStringView path) +{ + const auto tmp = path.toUtf8(); + return std::filesystem::path{ Misc::StringUtils::stringToU8String(tmp) }; +} + +std::filesystem::path Files::pathFromQString(QString&& path) +{ + const auto tmp = path.toUtf8(); + return std::filesystem::path{ Misc::StringUtils::stringToU8String(tmp) }; +} diff --git a/components/files/qtconversion.hpp b/components/files/qtconversion.hpp new file mode 100644 index 0000000000..0a4598073e --- /dev/null +++ b/components/files/qtconversion.hpp @@ -0,0 +1,18 @@ +#ifndef COMPONENTS_FILES_QTCONVERSION_HPP +#define COMPONENTS_FILES_QTCONVERSION_HPP + +#include +#include + +namespace Files +{ + QString pathToQString(const std::filesystem::path& path); + + QString pathToQString(std::filesystem::path&& path); + + std::filesystem::path pathFromQString(QStringView path); + + std::filesystem::path pathFromQString(QString&& path); +} + +#endif // COMPONENTS_FILES_QTCONVERSION_HPP