diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-06-09 08:40:27 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-07-12 11:56:57 +0200 |
commit | e7dee15531ad357bd33ac546fb1b9332a5c1260c (patch) | |
tree | f889b50746fd393d005552cd6c3580449fc78166 /lib/converters.cpp | |
parent | 9a65bde0fa438ee4ad101b58721b77182ae1ae70 (diff) | |
download | libquotient-e7dee15531ad357bd33ac546fb1b9332a5c1260c.tar.gz libquotient-e7dee15531ad357bd33ac546fb1b9332a5c1260c.zip |
converters.*: facilities to convert enums
This introduces enumTo/FromJsonString() and flagTo/FromJsonString(),
four facility functions to simplify conversion between C++ enums and
JSON, and refactors a couple of places where it's useful.
Diffstat (limited to 'lib/converters.cpp')
-rw-r--r-- | lib/converters.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/converters.cpp b/lib/converters.cpp index 444ca4f6..b0e3a4b6 100644 --- a/lib/converters.cpp +++ b/lib/converters.cpp @@ -2,9 +2,23 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "converters.h" +#include "logging.h" #include <QtCore/QVariant> +void Quotient::_impl::warnUnknownEnumValue(const QString& stringValue, + const char* enumTypeName) +{ + qWarning(EVENTS).noquote() + << "Unknown" << enumTypeName << "value:" << stringValue; +} + +void Quotient::_impl::reportEnumOutOfBounds(uint32_t v, const char* enumTypeName) +{ + qCritical(MAIN).noquote() + << "Value" << v << "is out of bounds for enumeration" << enumTypeName; +} + QJsonValue Quotient::JsonConverter<QVariant>::dump(const QVariant& v) { return QJsonValue::fromVariant(v); |