2 #include <QMetaProperty>
3 #include <QSequentialIterable>
15 if (name.startsWith(
"V2"))
33 if (Value.isNull() || !Value.isValid())
39 auto *
object = Value.value<QObject*>();
42 QVariant isNull =
object->property(
"isNull");
43 if (isNull.value<
bool>())
53 if (MetaProperty && (MetaProperty->isEnumType() || MetaProperty->isFlagType()))
55 QMetaEnum metaEnum = MetaProperty->enumerator();
56 QString value = MetaProperty->isFlagType() ? metaEnum.valueToKeys(Value.toInt()).constData() :
57 metaEnum.valueToKey(Value.toInt());
59 value = (value.isEmpty() ? Value.toString() : value);
65 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
66 static_cast<QMetaType::Type
>(Value.type())
68 static_cast<QMetaType::Type
>(Value.typeId())
74 case QMetaType::LongLong:
75 case QMetaType::ULongLong:
78 case QMetaType::Double:
79 m_writer << QString::number(Value.toDouble(),
'f',6);
81 case QMetaType::Float:
82 m_writer << QString::number(Value.toFloat(),
'f',6);
84 case QMetaType::Bool:
m_writer << (Value.toBool() ?
"true" :
"false");
break;
86 case QMetaType::QVariantList:
AddList(Value);
break;
87 case QMetaType::QVariantMap:
AddMap(Value.toMap());
break;
98 const auto * metaobject = Object->metaObject();
99 int count = metaobject->propertyCount();
103 for (
int index = 0; index < count; ++index )
105 QMetaProperty metaProperty = metaobject->property(index);
107 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
108 metaProperty.isUser(Object)
110 metaProperty.isUser()
114 const char *rawname = metaProperty.name();
115 QString name(rawname);
116 if (name.compare(
"objectName") == 0)
118 QVariant value(Object->property(rawname));
119 m_writer << first <<
"\"" << name <<
"\": ";
132 auto values = Values.value<QSequentialIterable>();
133 for (
const auto & value : values)
146 auto values = Values.value<QSequentialIterable>();
147 for (
const auto & value : values)
162 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
164 m_writer << first <<
"\"" << it.key() <<
"\":";
177 QString value = Value;
178 value.replace(
'\\',
"\\\\" );
179 value.replace(
'"' ,
"\\\"" );
180 value.replace(
'\b',
"\\b" );
181 value.replace(
'\f',
"\\f" );
182 value.replace(
'\n',
"\\n" );
183 value.replace(
"\r",
"\\r" );
184 value.replace(
"\t",
"\\t" );
185 value.replace(
"/",
"\\/" );
189 value.replace(QChar(
'\u0000'),
"\\u0000");
190 value.replace(QChar(
'\u0001'),
"\\u0001");
191 value.replace(QChar(
'\u0002'),
"\\u0002");
192 value.replace(QChar(
'\u0003'),
"\\u0003");
193 value.replace(QChar(
'\u0004'),
"\\u0004");
194 value.replace(QChar(
'\u0005'),
"\\u0005");
195 value.replace(QChar(
'\u0006'),
"\\u0006");
196 value.replace(QChar(
'\u0007'),
"\\u0007");
197 value.replace(QChar(
'\u000B'),
"\\u000B");
198 value.replace(QChar(
'\u000E'),
"\\u000E");
199 value.replace(QChar(
'\u000F'),
"\\u000F");
200 value.replace(QChar(
'\u0010'),
"\\u0010");
201 value.replace(QChar(
'\u0011'),
"\\u0011");
202 value.replace(QChar(
'\u0012'),
"\\u0012");
203 value.replace(QChar(
'\u0013'),
"\\u0013");
204 value.replace(QChar(
'\u0014'),
"\\u0014");
205 value.replace(QChar(
'\u0015'),
"\\u0015");
206 value.replace(QChar(
'\u0016'),
"\\u0016");
207 value.replace(QChar(
'\u0017'),
"\\u0017");
208 value.replace(QChar(
'\u0018'),
"\\u0018");
209 value.replace(QChar(
'\u0019'),
"\\u0019");
210 value.replace(QChar(
'\u001A'),
"\\u001A");
211 value.replace(QChar(
'\u001B'),
"\\u001B");
212 value.replace(QChar(
'\u001C'),
"\\u001C");
213 value.replace(QChar(
'\u001D'),
"\\u001D");
214 value.replace(QChar(
'\u001E'),
"\\u001E");
215 value.replace(QChar(
'\u001F'),
"\\u001F");