2 #include <QMetaProperty>
3 #include <QSequentialIterable>
9 #include <QCborStreamWriter>
11 : m_writer(new QCborStreamWriter(&m_buffer))
14 if (name.startsWith(
"V2"))
22 auto name =
Name.toUtf8();
23 m_writer->appendTextString(name.constData(), name.size());
37 if (Value.isNull() || !Value.isValid())
39 m_writer->append(QCborSimpleType::Null);
43 auto *
object = Value.value<QObject*>();
46 QVariant isNull =
object->property(
"isNull");
47 if (isNull.value<
bool>())
49 m_writer->append(QCborSimpleType::Null);
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::LongLong:
67 if (
auto value = Value.toLongLong(&ok); ok)
71 case QMetaType::ULongLong:
72 if (
auto value = Value.toULongLong(&ok); ok)
75 case QMetaType::Double:
m_writer->append(Value.toDouble());
break;
76 case QMetaType::Bool:
m_writer->append(Value.toBool());
break;
78 case QMetaType::QVariantList:
AddList(Value);
break;
79 case QMetaType::QVariantMap:
AddMap(Value.toMap());
break;
81 case QMetaType::QDateTime:
83 QDateTime dt(Value.toDateTime());
86 m_writer->append(QCborSimpleType::Null);
91 m_writer->appendTextString(name.constData(), name.size());
96 auto name = Value.toString().toUtf8();
97 m_writer->appendTextString(name.constData(), name.size());
105 const auto * metaobject = Object->metaObject();
106 int count = metaobject->propertyCount();
109 for (
int index = 0; index < count; ++index )
111 QMetaProperty metaProperty = metaobject->property(index);
113 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
114 metaProperty.isUser(Object)
116 metaProperty.isUser()
120 const char *rawname = metaProperty.name();
121 QString name(rawname);
122 if (name.compare(
"objectName") == 0)
124 auto utf8 = name.toUtf8();
125 m_writer->appendTextString(utf8.constData(), utf8.size());
126 AddValue(Object->property(rawname));
135 auto values = Values.value<QSequentialIterable>();
136 for (
const auto & value : values)
138 auto utf8 = value.toString().toUtf8();
139 m_writer->appendTextString(utf8.constData(), utf8.size());
147 auto values = Values.value<QSequentialIterable>();
148 for (
const auto & value : values)
156 for (
auto it = Map.cbegin(); it != Map.cend(); ++it)
158 auto utf8 = it.key().toUtf8();
159 m_writer->appendTextString(utf8.constData(), utf8.size());