3#include <QMetaProperty>
4#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
5#include <QSequentialIterable>
7#include <QMetaSequence>
20 if (name.startsWith(
"V2"))
38 if (Value.isNull() || !Value.isValid())
44 auto *
object = Value.value<QObject*>();
47 QVariant isNull =
object->property(
"isNull");
48 if (isNull.value<
bool>())
58 if (MetaProperty && (MetaProperty->isEnumType() || MetaProperty->isFlagType()))
60 QMetaEnum metaEnum = MetaProperty->enumerator();
61 QString value = MetaProperty->isFlagType() ? metaEnum.valueToKeys(Value.toInt()).constData() :
62 metaEnum.valueToKey(Value.toInt());
64 value = (value.isEmpty() ? Value.toString() : value);
70#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
71 static_cast<QMetaType::Type
>(Value.type())
73 static_cast<QMetaType::Type
>(Value.typeId())
79 case QMetaType::LongLong:
80 case QMetaType::ULongLong:
83 case QMetaType::Double:
84 m_writer << QString::number(Value.toDouble(),
'f',6);
86 case QMetaType::Float:
87 m_writer << QString::number(Value.toFloat(),
'f',6);
89 case QMetaType::Bool:
m_writer << (Value.toBool() ?
"true" :
"false");
break;
91 case QMetaType::QVariantList:
AddList(Value);
break;
92 case QMetaType::QVariantMap:
AddMap(Value.toMap());
break;
103 const auto * metaobject = Object->metaObject();
104 int count = metaobject->propertyCount();
108 for (
int index = 0; index < count; ++index )
110 QMetaProperty metaProperty = metaobject->property(index);
112#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
113 metaProperty.isUser(Object)
115 metaProperty.isUser()
119 const char *rawname = metaProperty.name();
120 QString name(rawname);
121 if (name.compare(
"objectName") == 0)
123 QVariant value(Object->property(rawname));
124 m_writer << first <<
"\"" << name <<
"\": ";
137#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
138 auto values = Values.value<QSequentialIterable>();
140 auto values = Values.value<QMetaSequence::Iterable>();
142 for (
const auto & value : values)
155#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
156 auto values = Values.value<QSequentialIterable>();
158 auto values = Values.value<QMetaSequence::Iterable>();
160 for (
const auto & value : values)
175 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
177 m_writer << first <<
"\"" << it.key() <<
"\":";
190 QString value = Value;
191 value.replace(
'\\',
"\\\\" );
192 value.replace(
'"' ,
"\\\"" );
193 value.replace(
'\b',
"\\b" );
194 value.replace(
'\f',
"\\f" );
195 value.replace(
'\n',
"\\n" );
196 value.replace(
"\r",
"\\r" );
197 value.replace(
"\t",
"\\t" );
198 value.replace(
"/",
"\\/" );
202 value.replace(QChar(
'\u0000'),
"\\u0000");
203 value.replace(QChar(
'\u0001'),
"\\u0001");
204 value.replace(QChar(
'\u0002'),
"\\u0002");
205 value.replace(QChar(
'\u0003'),
"\\u0003");
206 value.replace(QChar(
'\u0004'),
"\\u0004");
207 value.replace(QChar(
'\u0005'),
"\\u0005");
208 value.replace(QChar(
'\u0006'),
"\\u0006");
209 value.replace(QChar(
'\u0007'),
"\\u0007");
210 value.replace(QChar(
'\u000B'),
"\\u000B");
211 value.replace(QChar(
'\u000E'),
"\\u000E");
212 value.replace(QChar(
'\u000F'),
"\\u000F");
213 value.replace(QChar(
'\u0010'),
"\\u0010");
214 value.replace(QChar(
'\u0011'),
"\\u0011");
215 value.replace(QChar(
'\u0012'),
"\\u0012");
216 value.replace(QChar(
'\u0013'),
"\\u0013");
217 value.replace(QChar(
'\u0014'),
"\\u0014");
218 value.replace(QChar(
'\u0015'),
"\\u0015");
219 value.replace(QChar(
'\u0016'),
"\\u0016");
220 value.replace(QChar(
'\u0017'),
"\\u0017");
221 value.replace(QChar(
'\u0018'),
"\\u0018");
222 value.replace(QChar(
'\u0019'),
"\\u0019");
223 value.replace(QChar(
'\u001A'),
"\\u001A");
224 value.replace(QChar(
'\u001B'),
"\\u001B");
225 value.replace(QChar(
'\u001C'),
"\\u001C");
226 value.replace(QChar(
'\u001D'),
"\\u001D");
227 value.replace(QChar(
'\u001E'),
"\\u001E");
228 value.replace(QChar(
'\u001F'),
"\\u001F");
void AddObject(const QString &Name, const QVariant &Value)
std::stack< bool > m_first
void AddMap(const QVariantMap &Map)
void AddQObject(const QObject *Object)
void AddValue(const QVariant &Value, const QMetaProperty *MetaProperty=nullptr)
void AddStringList(const QVariant &Values)
MythJSONSerialiser(const QString &Name, const QVariant &Value)
static QString Encode(const QString &Value)
void AddList(const QVariant &Values)
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.