fixed edge display for volume cells
[engrid-github.git] / src / libengrid / xmlhandler.h
blobe5376b51da08735bf5fcb1b1718a70ddd343cfe8
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 {
31 Q_OBJECT
32 private:
33 QDomDocument m_XmlDoc; ///< XML document describing the templates to use
34 QObject *m_parent;///< Parent widget (for message boxes)
35 QDomNode m_DomNode;///< current node in the DOM tree
36 QString m_TagName;
38 public:
39 QDomNode getDomNode() { return m_DomNode; }///< Returns m_DomNode
41 public:
42 XmlHandler(QString tagName, QObject *parent = 0);///< Constructor
43 bool openXml(QString file_name);///< Open XML file
44 bool saveXml(QString file_name);///< Save XML file
45 QString getXmlSection(QString name);///< get contents of XML section
46 void setXmlSection(QString name, QString contents);///< set contents of XML section
47 void resetXmlDoc();///< Initialize or reset m_XmlDoc
48 QString getBuffer(int indent = 1) { return m_XmlDoc.toString(indent); }
49 QDomDocument* getXmlDoc() {return &m_XmlDoc;}
51 public:
52 /// Returns a list of all keys, including subkeys, that can be read using the XmlHandler object.
53 QStringList allKeys();
54 /// Returns a list of all key top-level groups that contain keys that can be read using the XmlHandler object.
55 QStringList childGroups();
56 /// Returns a list of all top-level keys that can be read using the XmlHandler object.
57 QStringList childKeys();
58 /// Returns the current group.
59 QString group(bool absolute = true);
60 ///Appends prefix to the current group.
61 void beginGroup(const QString & prefix);
62 /// Resets the group to what it was before the corresponding beginGroup() call.
63 void endGroup();
65 public:
66 void resetToTopNode();///< Reset to top node
67 void setGroup(const QString & prefix);///< Set current group
69 public:
70 /** Parses a QDomNode for text nodes.
71 * @param dom_node QDomNode to parse
72 * @param string_list QStringList in which to store the paths containing text
73 * @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)
74 * @return If dom_node is a text node, returns the path to it, otherwise returns an empty string.
76 QString parseNode(const QDomNode& dom_node, QStringList& string_list, QString stop_node);
79 #endif