Fraxinus  17.12-rc1
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 /*
35  * sscXmlOptionItem.h
36  *
37  * Created on: May 28, 2010
38  * Author: christiana
39  */
40 #ifndef CXXMLOPTIONITEM_H_
41 #define CXXMLOPTIONITEM_H_
42 
43 #include "cxResourceExport.h"
44 
45 #include <QString>
46 #include <QDomElement>
47 #include <QVariant>
48 
49 namespace cx
50 {
51 
59 class cxResource_EXPORT XmlOptionItem
60 {
61 public:
63  {
64  }
65  XmlOptionItem(const QString& uid, QDomElement root);
66  QString readValue(const QString& defval) const;
67  void writeValue(const QString& val);
68 
69  QVariant readVariant(const QVariant& defval=QVariant()) const;
70  void writeVariant(const QVariant& val);
71 
72 private:
73  QDomElement findElemFromUid(const QString& uid, QDomNode root) const;
74  QString mUid;
75  QDomElement mRoot;
76 
77  static QString SerializeDataToB64String(const QVariant& data);
78  static QVariant DeserializeB64String(const QString& serializedVariant);
79 };
80 
99 class cxResource_EXPORT XmlOptionFile
100 {
101 public:
102  static XmlOptionFile createNull();
103 
104  explicit XmlOptionFile(QString filename);
105  XmlOptionFile();
106  ~XmlOptionFile();
107 
108  QString getFileName();
109 
110  bool isNull() const;
111 
112  XmlOptionFile root() const;
113  XmlOptionFile descend(QString element) const;
114  XmlOptionFile descend(QString element, QString attributeName, QString attributeValue) const; // stepdown to element with given attribute
115  XmlOptionFile ascend() const;
116  XmlOptionFile tryDescend(QString element, QString attributeName, QString attributeValue) const; // stepdown only if present
117 
118  QDomDocument getDocument();
119  QDomElement getElement();
120  QDomElement getElement(QString level1);
121  QDomElement getElement(QString level1, QString level2);
122 
123  void save();
124 
125  void removeChildren();
126  void deleteNode();
127 
128  QDomElement safeGetElement(QDomElement parent, QString childName);
129 
130  //Debugging
131  void printDocument();
132  void printElement();
133  static void printDocument(QDomDocument document);
134  static void printElement(QDomElement element);
135 
136 private:
137  void load();
138 
139  QString mFilename;
140  QDomDocument mDocument;
141  QDomElement mCurrentElement;
142 
143 };
144 
145 } // namespace cx
146 
147 #endif /* CXXMLOPTIONITEM_H_ */
Helper class for storing one string value in an xml document.
Helper class for xml files used to store ssc/cx data.
Namespace for all CustusX production code.