Added dedicated functions for conversions between QString and std::filesystem::path.

This commit is contained in:
Project579 2022-08-19 22:33:51 +00:00
parent c226b35f1f
commit ca14fc00dc
16 changed files with 164 additions and 88 deletions

View 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) };
}

View 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