3#include <QMetaProperty>
4#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
5#include <QSequentialIterable>
7#include <QMetaSequence>
20 if (name.startsWith(
"V2"))
31 m_writer.writeAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
35 auto *
object = Value.value<QObject*>();
42 if (Value.isNull() || !Value.isValid())
44 m_writer.writeAttribute(
"xsi:nil",
"true");
48 auto *
object = Value.value<QObject*>();
51 QVariant isNull =
object->property(
"isNull");
59#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
60 static_cast<QMetaType::Type
>(Value.type())
62 static_cast<QMetaType::Type
>(Value.typeId())
67 case QMetaType::QVariantList:
AddList(
Name, Value);
break;
68 case QMetaType::QVariantMap:
AddMap(
Name, Value.toMap());
break;
69 case QMetaType::QDateTime:
71 QDateTime dt(Value.toDateTime());
73 m_writer.writeAttribute(
"xsi:nil",
"true");
78 case QMetaType::Double:
79 m_writer.writeCharacters(QString::number(Value.toDouble(),
'f',6));
81 case QMetaType::Float:
82 m_writer.writeCharacters(QString::number(Value.toFloat(),
'f',6));
85 m_writer.writeCharacters(Value.toString());
94 const auto * meta = Object->metaObject();
95 if (
int index = meta->indexOfClassInfo(
"Version"); index >= 0)
96 m_writer.writeAttribute(
"version", meta->classInfo(index).value());
98 int count = meta->propertyCount();
99 for (
int index = 0; index < count; ++index )
101 QMetaProperty metaproperty = meta->property(index);
103#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
104 metaproperty.isUser(Object)
106 metaproperty.isUser()
110 const char *rawname = metaproperty.name();
111 QString name(rawname);
112 if (name.compare(
"objectName") == 0)
114 QVariant value(Object->property(rawname));
123 const QMetaObject* MetaObject,
const QMetaProperty *MetaProperty)
126 if (MetaProperty && (MetaProperty->isEnumType() || MetaProperty->isFlagType()))
128 QMetaEnum metaEnum = MetaProperty->enumerator();
129 QString value = MetaProperty->isFlagType() ? metaEnum.valueToKeys(Value.toInt()).constData() :
130 metaEnum.valueToKey(Value.toInt());
132 m_writer.writeCharacters(value.isEmpty() ? Value.toString() : value);
141#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
142 auto values = Values.value<QSequentialIterable>();
144 auto values = Values.value<QMetaSequence::Iterable>();
146 for (
const auto & value : values)
148 m_writer.writeStartElement(
"String");
149 m_writer.writeCharacters(value.toString());
156#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
157 auto values = Values.value<QSequentialIterable>();
159 auto values = Values.value<QMetaSequence::Iterable>();
161 for (
const auto & value : values)
172 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
174 m_writer.writeStartElement(itemname);
178 m_writer.writeStartElement(
"Value");
187 QString name =
Name.startsWith(
"Q") ?
Name.mid(1) :
Name;
188 if (name.startsWith(
"V2"))
190 name.remove(QChar(
'*'));
198 if (
int index = MetaObject ? MetaObject->indexOfClassInfo(
Name.toLatin1().constData()) : -1; index >= 0)
200 QStringList infos = QString(MetaObject->classInfo(index).value()).split(
';', Qt::SkipEmptyParts);
202 for (
const QString &
info : std::as_const(infos))
204 if (
info.startsWith(QStringLiteral(
"name=")))
205 if (
auto name =
info.mid(5).trimmed(); !name.isEmpty())
207 if (
info.startsWith(QStringLiteral(
"type=")))
MythXMLSerialiser(const QString &Name, const QVariant &Value)
static QString GetContentName(const QString &Name, const QMetaObject *MetaObject)
FIXME We shouldn't be doing this on the fly.
void AddStringList(const QVariant &Values)
void AddQObject(const QObject *Object)
void AddMap(const QString &Name, const QVariantMap &Map)
void AddObject(const QString &Name, const QVariant &Value)
void AddValue(const QString &Name, const QVariant &Value)
QXmlStreamWriter m_writer
void AddProperty(const QString &Name, const QVariant &Value, const QMetaObject *MetaObject, const QMetaProperty *MetaProperty)
static QString GetItemName(const QString &Name)
void AddList(const QString &Name, const QVariant &Values)
#define XML_SERIALIZER_VERSION
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.