5#include <QMetaProperty>
6#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
7#include <QSequentialIterable>
9#include <QMetaSequence>
23 m_writer.writeDTD(R
"(<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">)");
25 m_writer.writeAttribute(
"version",
"1.0");
27 m_writer.writeTextElement(
"key",
"serializerversion");
30 if (name.startsWith(
"V2"))
40 auto *
object = Value.value<QObject*>();
46 auto *
object = Value.value<QObject*>();
49 QVariant isNull =
object->property(
"isNull");
50 if (isNull.value<
bool>())
57#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
58 static_cast<QMetaType::Type
>(Value.type())
60 static_cast<QMetaType::Type
>(Value.typeId())
65 case QMetaType::QVariantList:
AddList(
Name, Value.toList());
break;
66 case QMetaType::QVariantMap:
AddMap(
Name, Value.toMap());
break;
68 case QMetaType::ULongLong:
72 m_writer.writeTextElement(
"integer", QString::number(Value.toULongLong()));
77 case QMetaType::LongLong:
78 case QMetaType::Double:
82 m_writer.writeTextElement(
"real", QString(
"%1").arg(Value.toDouble(), 0,
'f', 6));
85 case QMetaType::Float:
89 m_writer.writeTextElement(
"real", QString(
"%1").arg(Value.toFloat(), 0,
'f', 6));
92 case QMetaType::QByteArray:
94 if (!Value.toByteArray().isNull())
98 m_writer.writeTextElement(
"data", Value.toByteArray().toBase64().data());
102 case QMetaType::Bool:
106 m_writer.writeEmptyElement(Value.toBool() ?
"true" :
"false");
109 case QMetaType::QDateTime:
110 if (Value.toDateTime().isValid())
114 m_writer.writeTextElement(
"date", Value.toDateTime().toUTC().toString(
"yyyy-MM-ddThh:mm:ssZ"));
117 case QMetaType::QString:
121 m_writer.writeTextElement(
"string", Value.toString());
133 const auto * meta = Object->metaObject();
134 if (
int index = meta->indexOfClassInfo(
"Version"); index >= 0)
136 m_writer.writeTextElement(
"key",
"version");
137 m_writer.writeTextElement(
"string", meta->classInfo(index).value());
140 int count = meta->propertyCount();
141 for (
int index = 0; index < count; ++index )
143 QMetaProperty metaproperty = meta->property(index);
145#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
146 metaproperty.isUser(Object)
148 metaproperty.isUser()
152 const char *rawname = metaproperty.name();
153 QString name(rawname);
154 if (name.compare(
"objectName") == 0)
156 AddProperty(name, Object->property(rawname), meta, &metaproperty);
164 const QMetaObject* MetaObject,
const QMetaProperty *MetaProperty)
168 if (MetaProperty && (MetaProperty->isEnumType() || MetaProperty->isFlagType()))
170 QMetaEnum metaEnum = MetaProperty->enumerator();
171 value = MetaProperty->isFlagType() ? metaEnum.valueToKeys(Value.toInt()).constData() :
172 metaEnum.valueToKey(Value.toInt());
180 m_writer.writeStartElement(
"array");
181#if QT_VERSION < QT_VERSION_CHECK(6,11,0)
182 auto values = Values.value<QSequentialIterable>();
184 auto values = Values.value<QMetaSequence::Iterable>();
186 for (
const auto & value : values)
187 m_writer.writeTextElement(
"string", value.toString());
194 if (!Values.isEmpty())
196#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
197 auto type =
static_cast<QMetaType::Type
>(Values.front().type());
198 auto typesEqual = [
type](
const QVariant& value)
199 {
return (
static_cast<QMetaType::Type
>(value.type()) ==
type); };
201 auto type =
static_cast<QMetaType::Type
>(Values.front().typeId());
202 auto typesEqual = [
type](
const QVariant& value)
203 {
return (
static_cast<QMetaType::Type
>(value.typeId()) ==
type); };
205 array = std::ranges::all_of(std::as_const(Values), typesEqual);
209 m_writer.writeTextElement(
"key", name);
210 m_writer.writeStartElement(array ?
"array" :
"dict");
212 for (
const auto& variant : Values)
220 m_writer.writeTextElement(
"key", itemname);
222 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
229 QString name =
Name.startsWith(
"Q") ?
Name.mid(1) :
Name;
230 name.remove(
"DTC::");
231 if (name.startsWith(
"V2"))
233 name.remove(QChar(
'*'));
241 if (
int index = MetaObject ? MetaObject->indexOfClassInfo(
Name.toLatin1().constData()) : -1; index >= 0)
243 QStringList infos = QString(MetaObject->classInfo(index).value()).split(
';', Qt::SkipEmptyParts);
245 for (
const QString &
info : std::as_const(infos))
247 if (
info.startsWith(QStringLiteral(
"name=")))
248 if (
auto name =
info.mid(5).trimmed(); !name.isEmpty())
250 if (
info.startsWith(QStringLiteral(
"type=")))
void AddProperty(const QString &Name, const QVariant &Value, const QMetaObject *MetaObject, const QMetaProperty *MetaProperty)
static QString GetItemName(const QString &Name)
void AddStringList(const QString &Name, const QVariant &Values)
void AddList(const QString &Name, const QVariantList &Values)
void AddQObject(const QString &Name, const QObject *Object)
void AddObject(const QString &Name, const QVariant &Value)
MythXMLPListSerialiser(const QString &Name, const QVariant &Value)
void AddValue(const QString &Name, const QVariant &Value, bool NeedKey=true)
static QString GetContentName(const QString &Name, const QMetaObject *MetaObject)
FIXME We shouldn't be doing this on the fly.
QXmlStreamWriter m_writer
void AddMap(const QString &Name, const QVariantMap &Map)
#define XML_PLIST_SERIALIZER_VERSION