updated to modern VTK
[engrid-github.git] / src / libengrid / xmlhandler.h
blob30d00210840fedcc26679a7da5f328f9a3cb3b5e
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef XMLHANDLER_H
22 #define XMLHANDLER_H
24 #include <QDomDocument>
25 #include <QObject>
26 #include <QMessageBox>
27 #include <QtDebug>
29 /** A class to simplify the handling of XML files. */
30 class XmlHandler : public QObject {
32 Q_OBJECT
34 private:
36 QDomDocument m_XmlDoc; ///< XML document describing the templates to use
37 QObject *m_parent;///< Parent widget (for message boxes)
38 QDomNode m_DomNode;///< current node in the DOM tree
39 QString m_TagName;
42 public:
44 QDomNode getDomNode() { return m_DomNode; }///< Returns m_DomNode
46 QString nodeToString(QDomNode node, int level);
49 public:
51 XmlHandler(QString tagName, QObject *parent = 0);///< Constructor
52 bool openXml(QString file_name);///< Open XML file
53 bool saveXml(QString file_name);///< Save XML file
54 QString getXmlSection(QString name);///< get contents of XML section
55 void setXmlSection(QString name, QString contents);///< set contents of XML section
56 void resetXmlDoc();///< Initialize or reset m_XmlDoc
57 QString getBuffer(int indent = 1) { return m_XmlDoc.toString(indent); }
58 QDomDocument* getXmlDoc() {return &m_XmlDoc;}
60 /// Returns a list of all keys, including subkeys, that can be read using the XmlHandler object.
61 QStringList allKeys();
63 /// Returns a list of all key top-level groups that contain keys that can be read using the XmlHandler object.
64 QStringList childGroups();
66 /// Returns a list of all top-level keys that can be read using the XmlHandler object.
67 QStringList childKeys();
69 /// Returns the current group.
70 QString group(bool absolute = true);
72 ///Appends prefix to the current group.
73 void beginGroup(const QString & prefix);
75 /// Resets the group to what it was before the corresponding beginGroup() call.
76 void endGroup();
78 void resetToTopNode();///< Reset to top node
79 void setGroup(const QString & prefix);///< Set current group
81 /** Parses a QDomNode for text nodes.
82 * @param dom_node QDomNode to parse
83 * @param string_list QStringList in which to store the paths containing text
84 * @param stop_node node at which to stop working up the path. ex: if the full path of a located text node is "#document/A/B/C/D/" and stop_node="B" then "C/D/" will be put into string_list (and eventually returned if dom_node is a text node)
85 * @return If dom_node is a text node, returns the path to it, otherwise returns an empty string.
87 QString parseNode(const QDomNode& dom_node, QStringList& string_list, QString stop_node);
91 #endif