From e7dee15531ad357bd33ac546fb1b9332a5c1260c Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Thu, 9 Jun 2022 08:40:27 +0200 Subject: 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. --- lib/converters.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/converters.cpp') 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 +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::dump(const QVariant& v) { return QJsonValue::fromVariant(v); -- cgit v1.2.3