2#include <QMetaProperty>
3#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
4#include <QSequentialIterable>
6#include <QMetaSequence>
19 if (name.startsWith(
"V2"))
30 m_writer.writeAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
34 auto *
object = Value.value<QObject*>();
41 if (Value.isNull() || !Value.isValid())
43 m_writer.writeAttribute(
"xsi:nil",
"true");
47 auto *
object = Value.value<QObject*>();
50 QVariant isNull =
object->property(
"isNull");
51 if (isNull.value<
bool>())
58#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
59 static_cast<QMetaType::Type
>(Value.type())
61 static_cast<QMetaType::Type
>(Value.typeId())
66 case QMetaType::QVariantList:
AddList(
Name, Value);
break;
67 case QMetaType::QVariantMap:
AddMap(
Name, Value.toMap());
break;
68 case QMetaType::QDateTime:
70 QDateTime dt(Value.toDateTime());
72 m_writer.writeAttribute(
"xsi:nil",
"true");
77 case QMetaType::Double:
78 m_writer.writeCharacters(QString::number(Value.toDouble(),
'f',6));
80 case QMetaType::Float:
81 m_writer.writeCharacters(QString::number(Value.toFloat(),
'f',6));
84 m_writer.writeCharacters(Value.toString());
93 const auto * meta = Object->metaObject();
94 if (
int index = meta->indexOfClassInfo(
"Version"); index >= 0)
95 m_writer.writeAttribute(
"version", meta->classInfo(index).value());
97 int count = meta->propertyCount();
98 for (
int index = 0; index < count; ++index )
100 QMetaProperty metaproperty = meta->property(index);
102#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
103 metaproperty.isUser(Object)
105 metaproperty.isUser()
109 const char *rawname = metaproperty.name();
110 QString name(rawname);
111 if (name.compare(
"objectName") == 0)
113 QVariant value(Object->property(rawname));
122 const QMetaObject* MetaObject,
const QMetaProperty *MetaProperty)
125 if (MetaProperty && (MetaProperty->isEnumType() || MetaProperty->isFlagType()))
127 QMetaEnum metaEnum = MetaProperty->enumerator();
128 QString value = MetaProperty->isFlagType() ? metaEnum.valueToKeys(Value.toInt()).constData() :
129 metaEnum.valueToKey(Value.toInt());
131 m_writer.writeCharacters(value.isEmpty() ? Value.toString() : value);
140#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
141 auto values = Values.value<QSequentialIterable>();
143 auto values = Values.value<QMetaSequence::Iterable>();
145 for (
const auto & value : values)
147 m_writer.writeStartElement(
"String");
148 m_writer.writeCharacters(value.toString());
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)
171 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
173 m_writer.writeStartElement(itemname);
177 m_writer.writeStartElement(
"Value");
186 QString name =
Name.startsWith(
"Q") ?
Name.mid(1) :
Name;
187 if (name.startsWith(
"V2"))
189 name.remove(QChar(
'*'));
197 if (
int index = MetaObject ? MetaObject->indexOfClassInfo(
Name.toLatin1().constData()) : -1; index >= 0)
199 QStringList infos = QString(MetaObject->classInfo(index).value()).split(
';', Qt::SkipEmptyParts);
201 for (
const QString &
info : std::as_const(infos))
203 if (
info.startsWith(QStringLiteral(
"name=")))
204 if (
auto name =
info.mid(5).trimmed(); !name.isEmpty())
206 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.