NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxXmlOptionItem.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 /*
14  * sscXmlOptionItem.h
15  *
16  * Created on: May 28, 2010
17  * Author: christiana
18  */
19 #ifndef CXXMLOPTIONITEM_H_
20 #define CXXMLOPTIONITEM_H_
21 
22 #include "cxResourceExport.h"
23 
24 #include <QString>
25 #include <QDomElement>
26 #include <QVariant>
27 
28 namespace cx
29 {
30 
38 class cxResource_EXPORT XmlOptionItem
39 {
40 public:
42  {
43  }
44  XmlOptionItem(const QString& uid, QDomElement root);
45  QString readValue(const QString& defval) const;
46  void writeValue(const QString& val);
47 
48  QVariant readVariant(const QVariant& defval=QVariant()) const;
49  void writeVariant(const QVariant& val);
50 
51 private:
52  QDomElement findElemFromUid(const QString& uid, QDomNode root) const;
53  QString mUid;
54  QDomElement mRoot;
55 
56  static QString SerializeDataToB64String(const QVariant& data);
57  static QVariant DeserializeB64String(const QString& serializedVariant);
58 };
59 
78 class cxResource_EXPORT XmlOptionFile
79 {
80 public:
81  static XmlOptionFile createNull();
82 
83  explicit XmlOptionFile(QString filename);
84  XmlOptionFile();
85  ~XmlOptionFile();
86 
87  QString getFileName();
88 
89  bool isNull() const;
90 
91  XmlOptionFile root() const;
92  XmlOptionFile descend(QString element) const;
93  XmlOptionFile descend(QString element, QString attributeName, QString attributeValue) const; // stepdown to element with given attribute
94  XmlOptionFile ascend() const;
95  XmlOptionFile tryDescend(QString element, QString attributeName, QString attributeValue) const; // stepdown only if present
96 
97  QDomDocument getDocument();
98  QDomElement getElement();
99  QDomElement getElement(QString level1);
100  QDomElement getElement(QString level1, QString level2);
101 
102  void save();
103 
104  void removeChildren();
105  void deleteNode();
106 
107  QDomElement safeGetElement(QDomElement parent, QString childName);
108 
109  //Debugging
110  void printDocument();
111  void printElement();
112  static void printDocument(QDomDocument document);
113  static void printElement(QDomElement element);
114 
115 private:
116  void load();
117 
118  QString mFilename;
119  QDomDocument mDocument;
120  QDomElement mCurrentElement;
121 
122 };
123 
124 } // namespace cx
125 
126 #endif /* CXXMLOPTIONITEM_H_ */
cx::XmlOptionFile
Helper class for xml files used to store ssc/cx data.
Definition: cxXmlOptionItem.h:78
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::XmlOptionItem
Helper class for storing one string value in an xml document.
Definition: cxXmlOptionItem.h:38
cx::XmlOptionItem::XmlOptionItem
XmlOptionItem()
Definition: cxXmlOptionItem.h:41