2 #include <QMetaProperty>
3 #include <QSequentialIterable>
15 if (name.startsWith(
"V2"))
26 m_writer.writeAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
30 auto *
object = Value.value<QObject*>();
37 if (Value.isNull() || !Value.isValid())
39 m_writer.writeAttribute(
"xsi:nil",
"true");
43 auto *
object = Value.value<QObject*>();
46 QVariant isNull =
object->property(
"isNull");
47 if (isNull.value<
bool>())
54 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
55 static_cast<QMetaType::Type
>(Value.type())
57 static_cast<QMetaType::Type
>(Value.typeId())
62 case QMetaType::QVariantList:
AddList(
Name, Value);
break;
63 case QMetaType::QVariantMap:
AddMap(
Name, Value.toMap());
break;
64 case QMetaType::QDateTime:
66 QDateTime dt(Value.toDateTime());
68 m_writer.writeAttribute(
"xsi:nil",
"true");
73 case QMetaType::Double:
74 m_writer.writeCharacters(QString::number(Value.toDouble(),
'f',6));
76 case QMetaType::Float:
77 m_writer.writeCharacters(QString::number(Value.toFloat(),
'f',6));
80 m_writer.writeCharacters(Value.toString());
89 const auto * meta = Object->metaObject();
90 if (
int index = meta->indexOfClassInfo(
"Version"); index >= 0)
91 m_writer.writeAttribute(
"version", meta->classInfo(index).value());
93 int count = meta->propertyCount();
94 for (
int index = 0; index < count; ++index )
96 QMetaProperty metaproperty = meta->property(index);
98 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
99 metaproperty.isUser(Object)
101 metaproperty.isUser()
105 const char *rawname = metaproperty.name();
106 QString name(rawname);
107 if (name.compare(
"objectName") == 0)
109 QVariant value(Object->property(rawname));
118 const QMetaObject* MetaObject,
const QMetaProperty *MetaProperty)
121 if (MetaProperty && (MetaProperty->isEnumType() || MetaProperty->isFlagType()))
123 QMetaEnum metaEnum = MetaProperty->enumerator();
124 QString value = MetaProperty->isFlagType() ? metaEnum.valueToKeys(Value.toInt()).constData() :
125 metaEnum.valueToKey(Value.toInt());
127 m_writer.writeCharacters(value.isEmpty() ? Value.toString() : value);
136 auto values = Values.value<QSequentialIterable>();
137 for (
const auto & value : values)
139 m_writer.writeStartElement(
"String");
140 m_writer.writeCharacters(value.toString());
147 auto values = Values.value<QSequentialIterable>();
148 for (
const auto & value : values)
159 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
161 m_writer.writeStartElement(itemname);
165 m_writer.writeStartElement(
"Value");
174 QString name =
Name.startsWith(
"Q") ?
Name.mid(1) :
Name;
175 if (name.startsWith(
"V2"))
177 name.remove(QChar(
'*'));
185 if (
int index = MetaObject ? MetaObject->indexOfClassInfo(
Name.toLatin1()) : -1; index >= 0)
187 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
188 QStringList infos = QString(MetaObject->classInfo(index).value()).split(
';', QString::SkipEmptyParts);
190 QStringList infos = QString(MetaObject->classInfo(index).value()).split(
';', Qt::SkipEmptyParts);
193 foreach (
const QString &info, infos)
195 if (info.startsWith(QStringLiteral(
"name=")))
196 if (
auto name = info.mid(5).trimmed(); !name.isEmpty())
198 if (info.startsWith(QStringLiteral(
"type=")))
199 type = info.mid(5).trimmed();