23static void writeAttribute(QXmlStreamWriter *stream,
const QVariant &attribute)
25 const QString unsignedFormat(QStringLiteral(
"0x%1"));
27 switch (attribute.typeId()) {
29 stream->writeEmptyElement(QStringLiteral(
"nil"));
31 case QMetaType::UChar:
32 stream->writeEmptyElement(QStringLiteral(
"uint8"));
33 stream->writeAttribute(QStringLiteral(
"value"),
34 unsignedFormat.arg(attribute.value<quint8>(), 2, 16,
37 case QMetaType::UShort:
38 stream->writeEmptyElement(QStringLiteral(
"uint16"));
39 stream->writeAttribute(QStringLiteral(
"value"),
40 unsignedFormat.arg(attribute.value<quint16>(), 4, 16,
44 stream->writeEmptyElement(QStringLiteral(
"uint32"));
45 stream->writeAttribute(QStringLiteral(
"value"),
46 unsignedFormat.arg(attribute.value<quint32>(), 8, 16,
50 stream->writeEmptyElement(QStringLiteral(
"int8"));
51 stream->writeAttribute(QStringLiteral(
"value"),
52 QString::number(attribute.value<qint8>()));
54 case QMetaType::Short:
55 stream->writeEmptyElement(QStringLiteral(
"int16"));
56 stream->writeAttribute(QStringLiteral(
"value"),
57 QString::number(attribute.value<qint16>()));
60 stream->writeEmptyElement(QStringLiteral(
"int32"));
61 stream->writeAttribute(QStringLiteral(
"value"),
62 QString::number(attribute.value<qint32>()));
64 case QMetaType::QByteArray:
65 stream->writeEmptyElement(QStringLiteral(
"text"));
66 stream->writeAttribute(QStringLiteral(
"value"),
67 QString::fromLatin1(attribute.value<QByteArray>().toHex().constData()));
68 stream->writeAttribute(QStringLiteral(
"encoding"), QStringLiteral(
"hex"));
70 case QMetaType::QString:
71 stream->writeEmptyElement(QStringLiteral(
"text"));
72 stream->writeAttribute(QStringLiteral(
"value"), attribute.value<QString>());
73 stream->writeAttribute(QStringLiteral(
"encoding"), QStringLiteral(
"normal"));
76 stream->writeEmptyElement(QStringLiteral(
"boolean"));
77 if (attribute.value<
bool>())
78 stream->writeAttribute(QStringLiteral(
"value"), QStringLiteral(
"true"));
80 stream->writeAttribute(QStringLiteral(
"value"), QStringLiteral(
"false"));
83 stream->writeEmptyElement(QStringLiteral(
"url"));
84 stream->writeAttribute(QStringLiteral(
"value"), attribute.value<QUrl>().toString());
87 if (attribute.userType() == qMetaTypeId<QBluetoothUuid>()) {
88 stream->writeEmptyElement(QStringLiteral(
"uuid"));
90 QBluetoothUuid uuid = attribute.value<QBluetoothUuid>();
91 switch (uuid.minimumSize()) {
93 stream->writeAttribute(QStringLiteral(
"value"),
94 unsignedFormat.arg(quint16(0), 4, 16, QLatin1Char(
'0')));
97 stream->writeAttribute(QStringLiteral(
"value"),
98 unsignedFormat.arg(uuid.toUInt16(), 4, 16,
102 stream->writeAttribute(QStringLiteral(
"value"),
103 unsignedFormat.arg(uuid.toUInt32(), 8, 16,
107 stream->writeAttribute(QStringLiteral(
"value"), uuid.toString().mid(1, 36));
110 stream->writeAttribute(QStringLiteral(
"value"), uuid.toString().mid(1, 36));
112 }
else if (attribute.userType() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) {
113 stream->writeStartElement(QStringLiteral(
"sequence"));
114 const QBluetoothServiceInfo::Sequence *sequence =
115 static_cast<
const QBluetoothServiceInfo::Sequence *>(attribute.data());
116 for (
const QVariant &v : *sequence)
117 writeAttribute(stream, v);
118 stream->writeEndElement();
119 }
else if (attribute.userType() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) {
120 const QBluetoothServiceInfo::Alternative *alternative =
121 static_cast<
const QBluetoothServiceInfo::Alternative *>(attribute.data());
122 for (
const QVariant &v : *alternative)
123 writeAttribute(stream, v);
124 stream->writeEndElement();
126 qCWarning(QT_BT_BLUEZ) <<
"Unknown variant type" << attribute.userType();