2 #include <QMetaProperty>
3 #include <QSequentialIterable>
16 m_writer.writeDTD(R
"(<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">)");
18 m_writer.writeAttribute(
"version",
"1.0");
20 m_writer.writeTextElement(
"key",
"serializerversion");
23 if (name.startsWith(
"V2"))
33 auto *
object = Value.value<QObject*>();
39 auto *
object = Value.value<QObject*>();
42 QVariant isNull =
object->property(
"isNull");
43 if (isNull.value<
bool>())
50 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
51 static_cast<QMetaType::Type
>(Value.type())
53 static_cast<QMetaType::Type
>(Value.typeId())
58 case QMetaType::QVariantList:
AddList(
Name, Value.toList());
break;
59 case QMetaType::QVariantMap:
AddMap(
Name, Value.toMap());
break;
61 case QMetaType::ULongLong:
65 m_writer.writeTextElement(
"integer", QString::number(Value.toULongLong()));
70 case QMetaType::LongLong:
71 case QMetaType::Double:
75 m_writer.writeTextElement(
"real", QString(
"%1").arg(Value.toDouble(), 0,
'f', 6));
78 case QMetaType::Float:
82 m_writer.writeTextElement(
"real", QString(
"%1").arg(Value.toFloat(), 0,
'f', 6));
85 case QMetaType::QByteArray:
87 if (!Value.toByteArray().isNull())
91 m_writer.writeTextElement(
"data", Value.toByteArray().toBase64().data());
99 m_writer.writeEmptyElement(Value.toBool() ?
"true" :
"false");
102 case QMetaType::QDateTime:
103 if (Value.toDateTime().isValid())
107 m_writer.writeTextElement(
"date", Value.toDateTime().toUTC().toString(
"yyyy-MM-ddThh:mm:ssZ"));
110 case QMetaType::QString:
114 m_writer.writeTextElement(
"string", Value.toString());
126 const auto * meta = Object->metaObject();
127 if (
int index = meta->indexOfClassInfo(
"Version"); index >= 0)
129 m_writer.writeTextElement(
"key",
"version");
130 m_writer.writeTextElement(
"string", meta->classInfo(index).value());
133 int count = meta->propertyCount();
134 for (
int index = 0; index < count; ++index )
136 QMetaProperty metaproperty = meta->property(index);
138 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
139 metaproperty.isUser(Object)
141 metaproperty.isUser()
145 const char *rawname = metaproperty.name();
146 QString name(rawname);
147 if (name.compare(
"objectName") == 0)
149 AddProperty(name, Object->property(rawname), meta, &metaproperty);
157 const QMetaObject* MetaObject,
const QMetaProperty *MetaProperty)
161 if (MetaProperty && (MetaProperty->isEnumType() || MetaProperty->isFlagType()))
163 QMetaEnum metaEnum = MetaProperty->enumerator();
164 value = MetaProperty->isFlagType() ? metaEnum.valueToKeys(Value.toInt()).constData() :
165 metaEnum.valueToKey(Value.toInt());
173 m_writer.writeStartElement(
"array");
174 auto values = Values.value<QSequentialIterable>();
175 for (
const auto & value : values)
176 m_writer.writeTextElement(
"string", value.toString());
183 if (!Values.isEmpty())
185 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
186 auto type =
static_cast<QMetaType::Type
>(Values.front().type());
187 auto typesEqual = [
type](
const QVariant& value)
188 {
return (
static_cast<QMetaType::Type
>(value.type()) ==
type); };
190 auto type =
static_cast<QMetaType::Type
>(Values.front().typeId());
191 auto typesEqual = [
type](
const QVariant& value)
192 {
return (
static_cast<QMetaType::Type
>(value.typeId()) ==
type); };
194 array = std::all_of(Values.cbegin(), Values.cend(), typesEqual);
198 m_writer.writeTextElement(
"key", name);
199 m_writer.writeStartElement(array ?
"array" :
"dict");
201 QListIterator<QVariant> it(Values);
210 m_writer.writeTextElement(
"key", itemname);
212 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
219 QString name =
Name.startsWith(
"Q") ?
Name.mid(1) :
Name;
220 name.remove(
"DTC::");
221 if (name.startsWith(
"V2"))
223 name.remove(QChar(
'*'));
231 if (
int index = MetaObject ? MetaObject->indexOfClassInfo(
Name.toLatin1()) : -1; index >= 0)
233 QStringList infos = QString(MetaObject->classInfo(index).value()).split(
';', Qt::SkipEmptyParts);
235 foreach (
const QString &
info, infos)
237 if (
info.startsWith(QStringLiteral(
"name=")))
238 if (
auto name =
info.mid(5).trimmed(); !name.isEmpty())
240 if (
info.startsWith(QStringLiteral(
"type=")))