38 #include <QtContainerFwd>
45 T
unquote(
const T &str,
const QString "es = QChar(
'"'))
47 if (str.length() < 2)
return str;
49 for (
const QChar quote : quotes)
51 if (str.startsWith(quote) && str.endsWith(quote))
52 return str.mid(1, (str.length() - 2));
58 std::optional<bool>
parseBool(
const QString &
string);
59 std::optional<int>
parseInt(
const QString &
string);
60 std::optional<double>
parseDouble(
const QString &
string);
62 QString
join(
const QList<QStringView> &strings, QStringView separator);
66 template <
typename T,
typename std::enable_if_t<std::is_enum_v<T>,
int> = 0>
69 static_assert(std::is_same_v<
int,
typename std::underlying_type_t<T>>,
70 "Enumeration underlying type has to be int.");
72 const auto metaEnum = QMetaEnum::fromType<T>();
73 return QString::fromLatin1(metaEnum.valueToKey(
static_cast<int>(
value)));
76 template <
typename T,
typename std::enable_if_t<std::is_enum_v<T>,
int> = 0>
77 T
toEnum(
const QString &serializedValue,
const T &defaultValue)
79 static_assert(std::is_same_v<
int,
typename std::underlying_type_t<T>>,
80 "Enumeration underlying type has to be int.");
82 const auto metaEnum = QMetaEnum::fromType<T>();
84 const T
value =
static_cast<T
>(metaEnum.keyToValue(serializedValue.toLatin1().constData(), &ok));
85 return (ok ?
value : defaultValue);
std::optional< bool > parseBool(const QString &string)
QString fromEnum(const T &value)
std::optional< int > parseInt(const QString &string)
T unquote(const T &str, const QString "es=QChar('"'))
QString fromDouble(double n, int precision)
T toEnum(const QString &serializedValue, const T &defaultValue)
QString wildcardToRegexPattern(const QString &pattern)
QString join(const QList< QStringView > &strings, QStringView separator)
std::optional< double > parseDouble(const QString &string)
T value(const QString &key, const T &defaultValue={})