BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
UtilXML.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Support/XML/UtilXML.h
6 //! @brief Defines
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_SUPPORT_XML_UTILXML_H
16 #define BORNAGAIN_GUI_SUPPORT_XML_UTILXML_H
17 
18 #include <QVariant>
19 #include <QXmlStreamWriter> // used in every including file
20 #include <heinz/Complex.h>
21 #include <heinz/Vectors3D.h>
22 
23 class QXmlStreamReader;
24 class MessageService;
25 class QUuid;
26 
27 
28 namespace GUI::Session::XML {
29 
30 namespace Tags {
31 constexpr auto Id("id");
32 constexpr auto TagAttribute("Tag");
33 constexpr auto ModelTypeAttribute("ModelType");
34 constexpr auto DisplayNameAttribute("DisplayName");
35 constexpr auto ParameterTag("Parameter");
36 constexpr auto BinaryData("BinaryData");
37 constexpr auto NonSessionItemData("NonSessionItemData");
38 constexpr auto ParameterNameAttribute("ParName");
39 constexpr auto ParameterTypeAttribute("ParType");
40 constexpr auto ParameterValueAttribute("ParValue");
41 constexpr auto ParameterRoleAttribute("ParRole");
42 constexpr auto ParameterExtAttribute("ParExt");
43 constexpr auto ExternalPropertyColorAtt("Color");
44 constexpr auto ExternalPropertyIdentifierAtt("Identifier");
45 } // namespace Tags
46 
47 constexpr auto Version("Version");
48 
49 void gotoEndElementOfTag(QXmlStreamReader* reader, const QString& tag);
50 
51 //! Write the variant as a complete tag, including the given role
52 void writeVariant(QXmlStreamWriter* writer, QVariant variant, int role);
53 
54 //! Write the variant's value as an attribute
55 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName,
56  const QVariant& variant);
57 
58 void writeUid(QXmlStreamWriter* writer, const QString& id);
59 void writeUid(QXmlStreamWriter* writer, const QUuid& id);
60 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, int d);
61 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, unsigned d);
62 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, double d);
63 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName, const R3& vec);
64 void writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName, const complex_t& c);
65 
66 bool readBoolAttribute(QXmlStreamReader* reader, const QString& attributeName);
67 unsigned readUIntAttribute(QXmlStreamReader* reader, const QString& attributeName);
68 
69 void readAttribute(QXmlStreamReader* reader, const QString& attributeName, double* d);
70 void readAttribute(QXmlStreamReader* reader, const QString& attributeName, QString* s);
71 void readAttribute(QXmlStreamReader* reader, const QString& attributeName, QColor* c);
72 void readAttribute(QXmlStreamReader* reader, const QString& attributeBaseName, R3* vec);
73 void readAttribute(QXmlStreamReader* reader, const QString& attributeBaseName, complex_t* c);
74 
75 void assertExpectedTag(QXmlStreamReader* reader, const QString& tag);
76 
77 } // namespace GUI::Session::XML
78 
79 #endif // BORNAGAIN_GUI_SUPPORT_XML_UTILXML_H
The service to collect messages from different senders.
constexpr auto ParameterRoleAttribute("ParRole")
constexpr auto ParameterTypeAttribute("ParType")
constexpr auto ParameterTag("Parameter")
constexpr auto BinaryData("BinaryData")
constexpr auto ExternalPropertyColorAtt("Color")
constexpr auto NonSessionItemData("NonSessionItemData")
constexpr auto ParameterValueAttribute("ParValue")
constexpr auto ParameterExtAttribute("ParExt")
constexpr auto Id("id")
constexpr auto DisplayNameAttribute("DisplayName")
constexpr auto ParameterNameAttribute("ParName")
constexpr auto TagAttribute("Tag")
constexpr auto ModelTypeAttribute("ModelType")
constexpr auto ExternalPropertyIdentifierAtt("Identifier")
void writeVariant(QXmlStreamWriter *writer, QVariant variant, int role)
Write the variant as a complete tag, including the given role.
Definition: UtilXML.cpp:137
void readAttribute(QXmlStreamReader *reader, const QString &attributeName, double *d)
Definition: UtilXML.cpp:193
bool readBoolAttribute(QXmlStreamReader *reader, const QString &attributeName)
Definition: UtilXML.cpp:149
void writeUid(QXmlStreamWriter *writer, const QString &id)
Definition: UtilXML.cpp:127
constexpr auto Version("Version")
void writeAttribute(QXmlStreamWriter *writer, const QString &attributeName, const QVariant &variant)
Write the variant's value as an attribute.
Definition: UtilXML.cpp:65
void gotoEndElementOfTag(QXmlStreamReader *reader, const QString &tag)
Definition: UtilXML.cpp:49
void assertExpectedTag(QXmlStreamReader *reader, const QString &tag)
Definition: UtilXML.cpp:199
unsigned readUIntAttribute(QXmlStreamReader *reader, const QString &attributeName)
Definition: UtilXML.cpp:154
Definition: JobItem.cpp:33