2#include <QMetaProperty>
3#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
4#include <QSequentialIterable>
6#include <QMetaSequence>
19 if (name.startsWith(
"V2"))
37 if (Value.isNull() || !Value.isValid())
43 auto *
object = Value.value<QObject*>();
46 QVariant isNull =
object->property(
"isNull");
47 if (isNull.value<
bool>())
57 if (MetaProperty && (MetaProperty->isEnumType() || MetaProperty->isFlagType()))
59 QMetaEnum metaEnum = MetaProperty->enumerator();
60 QString value = MetaProperty->isFlagType() ? metaEnum.valueToKeys(Value.toInt()).constData() :
61 metaEnum.valueToKey(Value.toInt());
63 value = (value.isEmpty() ? Value.toString() : value);
69#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
70 static_cast<QMetaType::Type
>(Value.type())
72 static_cast<QMetaType::Type
>(Value.typeId())
78 case QMetaType::LongLong:
79 case QMetaType::ULongLong:
82 case QMetaType::Double:
83 m_writer << QString::number(Value.toDouble(),
'f',6);
85 case QMetaType::Float:
86 m_writer << QString::number(Value.toFloat(),
'f',6);
88 case QMetaType::Bool:
m_writer << (Value.toBool() ?
"true" :
"false");
break;
90 case QMetaType::QVariantList:
AddList(Value);
break;
91 case QMetaType::QVariantMap:
AddMap(Value.toMap());
break;
102 const auto * metaobject = Object->metaObject();
103 int count = metaobject->propertyCount();
107 for (
int index = 0; index < count; ++index )
109 QMetaProperty metaProperty = metaobject->property(index);
111#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
112 metaProperty.isUser(Object)
114 metaProperty.isUser()
118 const char *rawname = metaProperty.name();
119 QString name(rawname);
120 if (name.compare(
"objectName") == 0)
122 QVariant value(Object->property(rawname));
123 m_writer << first <<
"\"" << name <<
"\": ";
136#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
137 auto values = Values.value<QSequentialIterable>();
139 auto values = Values.value<QMetaSequence::Iterable>();
141 for (
const auto & value : values)
154#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
155 auto values = Values.value<QSequentialIterable>();
157 auto values = Values.value<QMetaSequence::Iterable>();
159 for (
const auto & value : values)
174 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
176 m_writer << first <<
"\"" << it.key() <<
"\":";
189 QString value = Value;
190 value.replace(
'\\',
"\\\\" );
191 value.replace(
'"' ,
"\\\"" );
192 value.replace(
'\b',
"\\b" );
193 value.replace(
'\f',
"\\f" );
194 value.replace(
'\n',
"\\n" );
195 value.replace(
"\r",
"\\r" );
196 value.replace(
"\t",
"\\t" );
197 value.replace(
"/",
"\\/" );
201 value.replace(QChar(
'\u0000'),
"\\u0000");
202 value.replace(QChar(
'\u0001'),
"\\u0001");
203 value.replace(QChar(
'\u0002'),
"\\u0002");
204 value.replace(QChar(
'\u0003'),
"\\u0003");
205 value.replace(QChar(
'\u0004'),
"\\u0004");
206 value.replace(QChar(
'\u0005'),
"\\u0005");
207 value.replace(QChar(
'\u0006'),
"\\u0006");
208 value.replace(QChar(
'\u0007'),
"\\u0007");
209 value.replace(QChar(
'\u000B'),
"\\u000B");
210 value.replace(QChar(
'\u000E'),
"\\u000E");
211 value.replace(QChar(
'\u000F'),
"\\u000F");
212 value.replace(QChar(
'\u0010'),
"\\u0010");
213 value.replace(QChar(
'\u0011'),
"\\u0011");
214 value.replace(QChar(
'\u0012'),
"\\u0012");
215 value.replace(QChar(
'\u0013'),
"\\u0013");
216 value.replace(QChar(
'\u0014'),
"\\u0014");
217 value.replace(QChar(
'\u0015'),
"\\u0015");
218 value.replace(QChar(
'\u0016'),
"\\u0016");
219 value.replace(QChar(
'\u0017'),
"\\u0017");
220 value.replace(QChar(
'\u0018'),
"\\u0018");
221 value.replace(QChar(
'\u0019'),
"\\u0019");
222 value.replace(QChar(
'\u001A'),
"\\u001A");
223 value.replace(QChar(
'\u001B'),
"\\u001B");
224 value.replace(QChar(
'\u001C'),
"\\u001C");
225 value.replace(QChar(
'\u001D'),
"\\u001D");
226 value.replace(QChar(
'\u001E'),
"\\u001E");
227 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.