implemented mirror mesh, still not working for vol. cells
[engrid.git] / src / xmlhandler.h
blobabe8917d47b3534783f5b34c6df945e5e6c90903
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #ifndef XMLHANDLER_H
24 #define XMLHANDLER_H
26 #include <QDomDocument>
27 #include <QObject>
28 #include <QMessageBox>
29 #include <QtDebug>
31 /** A class to simplify the handling of XML files. */
32 class XmlHandler : public QObject {
33 Q_OBJECT
34 private:
35 QDomDocument m_XmlDoc; ///< XML document describing the templates to use
36 QObject *m_parent;///< Parent widget (for message boxes)
37 QDomNode m_DomNode;///< current node in the DOM tree
38 QString m_TagName;
40 public:
41 QDomNode getDomNode() { return m_DomNode; }///< Returns m_DomNode
43 public:
44 XmlHandler(QString tagName, QObject *parent = 0);///< Constructor
45 bool openXml(QString file_name);///< Open XML file
46 bool saveXml(QString file_name);///< Save XML file
47 QString getXmlSection(QString name);///< get contents of XML section
48 void setXmlSection(QString name, QString contents);///< set contents of XML section
49 void resetXmlDoc();///< Initialize or reset m_XmlDoc
50 QString getBuffer(int indent = 1) { return m_XmlDoc.toString(indent); }
51 QDomDocument* getXmlDoc() {return &m_XmlDoc;}
53 public:
54 /// Returns a list of all keys, including subkeys, that can be read using the XmlHandler object.
55 QStringList allKeys();
56 /// Returns a list of all key top-level groups that contain keys that can be read using the XmlHandler object.
57 QStringList childGroups();
58 /// Returns a list of all top-level keys that can be read using the XmlHandler object.
59 QStringList childKeys();
60 /// Returns the current group.
61 QString group(bool absolute = true);
62 ///Appends prefix to the current group.
63 void beginGroup(const QString & prefix);
64 /// Resets the group to what it was before the corresponding beginGroup() call.
65 void endGroup();
67 public:
68 void resetToTopNode();///< Reset to top node
69 void setGroup(const QString & prefix);///< Set current group
71 public:
72 /** Parses a QDomNode for text nodes.
73 * @param dom_node QDomNode to parse
74 * @param string_list QStringList in which to store the paths containing text
75 * @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)
76 * @return If dom_node is a text node, returns the path to it, otherwise returns an empty string.
78 QString parseNode(const QDomNode& dom_node, QStringList& string_list, QString stop_node);
81 #endif