mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Added dedicated functions for conversions between QString and std::filesystem::path.
This commit is contained in:
parent
c226b35f1f
commit
ca14fc00dc
16 changed files with 164 additions and 88 deletions
28
components/files/qtconversion.cpp
Normal file
28
components/files/qtconversion.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
#include "qtconversion.hpp"
|
||||
|
||||
#include <components/misc/strings/conversion.hpp>
|
||||
|
||||
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) };
|
||||
}
|
18
components/files/qtconversion.hpp
Normal file
18
components/files/qtconversion.hpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef COMPONENTS_FILES_QTCONVERSION_HPP
|
||||
#define COMPONENTS_FILES_QTCONVERSION_HPP
|
||||
|
||||
#include <QString>
|
||||
#include <filesystem>
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue