25 #include <QtCore/QXmlStreamWriter>
31 const QString uint_type_name =
"uint";
32 const QString qstring_type_name =
"QString";
46 writer->writeEndElement();
59 if (role == Qt::DisplayRole || role == Qt::EditRole)
71 writer->writeCharacters(a.toBase64());
72 writer->writeEndElement();
76 writer->writeEndElement();
81 if (variant.isValid()) {
83 QString type_name = variant.typeName();
89 QString::number(variant.toDouble(),
'e', 12));
92 QString::number(variant.toInt()));
93 }
else if (type_name == uint_type_name) {
95 QString::number(variant.toUInt()));
98 QString::number(variant.toBool()));
99 }
else if (type_name == qstring_type_name) {
101 }
else if (type_name ==
"ExternalProperty") {
105 QString tcol = prop.
color().isValid() ? prop.
color().name(QColor::HexArgb) :
"";
108 }
else if (type_name ==
"ComboProperty") {
114 throw GUIHelpers::Error(
"SessionXML::writeVariant: Parameter type not supported "
118 writer->writeEndElement();
127 while (!reader->atEnd()) {
129 if (reader->isStartElement()) {
134 QString displayName =
137 if (!topTag.isEmpty()) {
142 auto newItem = createItem(parent,
model_type, tag);
144 QString message = QString(
"Error while parsing XML. Can't create item of "
145 "modelType '%1' for tag '%2', parent '%3'")
147 report_error(messageService, parent, message);
149 reader->skipCurrentElement();
158 QString valueAsBase64 =
159 reader->readElementText(QXmlStreamReader::SkipChildElements);
160 const auto data = QByteArray::fromBase64(
161 valueAsBase64.toLatin1());
166 }
else if (reader->isEndElement()) {
168 parent = parent->
parent();
170 if (reader->name() == start_type)
179 const QString parameter_name =
181 const QString parameter_type =
187 QString(
"Attempt to set property '%1' for non existing item").arg(parameter_name);
188 report_error(messageService, item, message);
189 return parameter_name;
194 double parameter_value =
196 variant = parameter_value;
198 int parameter_value =
200 variant = parameter_value;
201 }
else if (parameter_type == uint_type_name) {
202 unsigned parameter_value =
204 variant = parameter_value;
206 bool parameter_value =
208 variant = parameter_value;
209 }
else if (parameter_type == qstring_type_name) {
210 QString parameter_value =
212 variant = parameter_value;
213 }
else if (parameter_type ==
"ExternalProperty") {
222 property.setColor(QColor(colorName));
223 property.setIdentifier(identifier);
224 variant =
property.variant();
225 }
else if (parameter_type ==
"ComboProperty") {
234 variant = combo_property.
variant();
236 QString message = QString(
"SessionModel::readProperty: parameter type not supported '"
237 + parameter_type +
"'");
241 if (variant.isValid()) {
245 return parameter_name;
251 if (messageService) {
262 if (item->
modelType() ==
"GroupProperty") {
263 if (
auto groupItem =
dynamic_cast<GroupItem*
>(item))
264 result = groupItem->getItemOfType(modelType);
271 }
catch (
const std::exception&) {
#define ASSERT(condition)
Defines class ComboProperty.
Defines class DeserializationException.
Defines class ExternalProperty.
Defines class GUIHelpers functions.
Defines class GroupItemController.
Defines class ItemFactory.
Defines MessageService class.
Defines class SessionModel.
Custom property to define list of string values with multiple selections.
void setStringOfValues(const QString &values)
Sets values from the string containing delimeter ';'.
QString stringOfSelections() const
Return string with coma separated list of selected indices.
void setStringOfSelections(const QString &values)
Sets selected indices from string.
QString stringOfValues() const
Returns a single string containing values delimited with ';'.
QVariant variant() const
Constructs variant enclosing given ComboProperty.
static DeserializationException tooNew()
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
QString identifier() const
void setText(const QString &name)
The service to collect messages from different senders.
void send_warning(QObject *sender, const QString &description)
SessionItemTags * sessionItemTags()
QVariant value() const
Get value.
QVector< int > getRoles() const
Returns vector of all present roles.
static const QString P_NAME
void setDisplayName(const QString &display_name)
Set display name.
SessionItem * parent() const
Returns parent of this item.
virtual void deserializeBinaryData(const QByteArray &data)
SessionModel * model() const
Returns model of this item.
virtual QByteArray serializeBinaryData() const
QVariant roleProperty(int role) const
Returns corresponding variant under given role, invalid variant when role is not present.
QVector< SessionItem * > children() const
Returns vector of all children.
QString modelType() const
Get model type.
QString tagFromItem(const SessionItem *item) const
Returns the tag name of given item when existing.
bool setRoleProperty(int role, const QVariant &value)
Set variant to role, create role if not present yet.
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
QString getModelName() const
QString getModelTag() const
SessionItem * insertNewItem(QString model_type, SessionItem *parent_item=nullptr, int row=-1, QString tag="")
const std::string bool_type_name
const std::string double_type_name
const std::string int_type_name
const QString Version("Version")
const QString ParameterValueAttribute("ParValue")
const QString ParameterNameAttribute("ParName")
const QString BinaryData("BinaryData")
const QString TagAttribute("Tag")
const QString ParameterExtAttribute("ParExt")
void writeVariant(QXmlStreamWriter *writer, QVariant variant, int role)
const QString ParameterTag("Parameter")
const QString ModelTypeAttribute("ModelType")
const QString ExternalPropertyColorAtt("Color")
QString readProperty(QXmlStreamReader *reader, SessionItem *item, MessageService *messageService=nullptr)
const QString ParameterRoleAttribute("ParRole")
const QString DisplayNameAttribute("DisplayName")
void writeItemAndChildItems(QXmlStreamWriter *writer, const SessionItem *item)
void readItems(QXmlStreamReader *reader, SessionItem *parent, QString topTag="", MessageService *messageService=nullptr)
void writeTo(QXmlStreamWriter *writer, SessionItem *parent)
const QString ModelNameAttribute("Name")
const QString ItemTag("Item")
const QString ParameterTypeAttribute("ParType")
const QString ExternalPropertyIdentifierAtt("Identifier")
const QString ExternalPropertyTextAtt("Text")