16 #include "Base/Util/Assert.h"
23 #include <QXmlStreamWriter>
27 void assertCurrentTag(QXmlStreamReader* reader,
const QString& expectedTag)
30 if (reader->name() != expectedTag) {
33 QString foundTag = reader->name().toString();
40 void assertCurrentToken(QXmlStreamReader* reader, QXmlStreamReader::TokenType token)
42 if (reader->tokenType() != token)
52 if (reader->name() != tag) {
53 if (!reader->isEndElement())
54 reader->skipCurrentElement();
55 reader->skipCurrentElement();
57 assertCurrentTag(reader, tag);
58 if (!reader->isEndElement())
59 reader->skipCurrentElement();
61 assertCurrentToken(reader, QXmlStreamReader::EndElement);
62 assertCurrentTag(reader, tag);
66 const QVariant& variant)
69 ASSERT(variant.isValid());
71 if (variant.type() == QVariant::Double)
73 else if (variant.type() == QVariant::Int)
75 else if (variant.type() == QVariant::UInt)
77 else if (variant.type() == QVariant::Bool)
78 writer->writeAttribute(attributeName, QString::number(variant.toBool()));
79 else if (variant.type() == QVariant::String)
80 writer->writeAttribute(attributeName, variant.toString());
81 else if (variant.type() == QVariant::Color) {
82 const auto col = variant.value<QColor>();
83 const QString tcol = col.isValid() ? col.name(QColor::HexArgb) :
"";
84 writer->writeAttribute(attributeName, tcol);
85 }
else if (QString(variant.typeName()) ==
"ComboProperty") {
87 writer->writeAttribute(attributeName, combo.stringOfSelections());
90 throw Error(
"GUI::Session::XML::writeVariant: Parameter type not supported "
91 + QString(variant.typeName()));
112 writer->writeAttribute(attributeName, d == 0.0 ?
"0" : QString::number(d,
'e', 12));
118 writer->writeAttribute(attributeName, QString::number(d));
124 writer->writeAttribute(attributeName, QString::number(d));
129 writer->writeAttribute(
Tags::Id,
id);
140 if (variant.isValid()) {
145 writer->writeEndElement();
151 return reader->attributes().value(attributeName).toUInt() != 0;
155 const QString& attributeName)
157 return reader->attributes().value(attributeName).toUInt();
163 *s = reader->attributes().value(attributeName).toString();
169 const QString parameter_value = reader->attributes().value(attributeName).toString();
170 *c = QColor(parameter_value);
196 *d = reader->attributes().value(attributeName).toDouble();
201 if (reader->name() != expectedTag) {
204 QString foundTag = reader->name().toString();
Defines class ComboProperty.
Defines class DeserializationException.
Defines MessageService class.
Custom property to define list of string values with multiple selections. Intended for QVariant.
static DeserializationException streamError()
void writeVariant(QXmlStreamWriter *writer, QVariant variant, int role)
Write the variant as a complete tag, including the given role.
constexpr auto ParameterTag("Parameter")
void readAttribute(QXmlStreamReader *reader, const QString &attributeName, double *d)
bool readBoolAttribute(QXmlStreamReader *reader, const QString &attributeName)
void writeUid(QXmlStreamWriter *writer, const QString &id)
void writeAttribute(QXmlStreamWriter *writer, const QString &attributeName, const QVariant &variant)
Write the variant's value as an attribute.
void gotoEndElementOfTag(QXmlStreamReader *reader, const QString &tag)
void assertExpectedTag(QXmlStreamReader *reader, const QString &tag)
unsigned readUIntAttribute(QXmlStreamReader *reader, const QString &attributeName)
QString toString(const QModelIndex &index)
Provides string representation of index data.