qtxml
QtXmlDocument.cxx
Go to the documentation of this file.
1
12
#include "
QtXmlDocument.h
"
13
#include "
QtXmlElement.h
"
14
#include "
QtXmlTextNode.h
"
15
16
#include <qdir.h>
17
#include <qfile.h>
18
#include <qfileinfo.h>
19
#include <qtextstream.h>
20
21
using
std::string;
22
23
namespace
hippodraw
{
24
25
QtXmlDocument::QtXmlDocument
(
QDomDocument
document )
26
: m_document ( document )
27
{
28
}
29
30
QtXmlDocument::
31
QtXmlDocument
(
const
std::string & name )
32
{
33
m_document
=
QDomDocument
( name.c_str () );
34
}
35
36
QtXmlDocument::
37
~QtXmlDocument
()
38
{
39
}
40
41
XmlElement
*
QtXmlDocument::documentElement
( )
const
42
{
43
QDomElement
root =
m_document
.
documentElement
();
44
45
return
new
QtXmlElement
( root );
46
}
47
48
XmlElement
*
49
QtXmlDocument::
50
createElement
(
const
std::string & tagName )
51
{
52
QDomElement
element =
m_document
.
createElement
( tagName.c_str() );
53
54
return
new
QtXmlElement
( element );
55
}
56
57
XmlTextNode
*
58
QtXmlDocument::
59
createTextNode
(
const
std::string & tag )
60
{
61
QDomText
node =
m_document
.
createTextNode
( tag.c_str () );
62
63
return
new
QtXmlTextNode
( node );
64
}
65
66
/* virtual */
67
void
QtXmlDocument::appendChild
(
XmlElement
& child )
68
{
69
const
QtXmlElement
& qtelem
70
= dynamic_cast <
const
QtXmlElement
& > ( child );
71
72
m_document
.appendChild ( qtelem.
m_node
);
73
}
74
75
XmlDocument::Status
76
QtXmlDocument::
77
saveToFile
(
const
std::string & filename )
78
{
79
QFile
filedev ( filename.c_str() );
80
81
#if QT_VERSION < 0x040000
82
bool
ok = filedev.
open
( IO_WriteOnly );
83
#else
84
bool
ok = filedev.open ( QIODevice::WriteOnly );
85
#endif
86
87
if
( ! ok ) {
88
return
WriteError
;
89
}
90
91
QTextStream
ts ( &filedev );
92
m_document
.save ( ts, 2 );
93
filedev.close ();
94
95
return
Success
;
96
}
97
98
XmlDocument::Status
99
QtXmlDocument::
100
setContent
(
const
std::string & filename )
101
{
102
QFile
file ( filename.c_str() );
103
#if QT_VERSION < 0x040000
104
bool
ok = file.
open
( IO_ReadOnly );
105
#else
106
bool
ok = file.open ( QIODevice::ReadOnly );
107
#endif
108
109
if
( ! ok ) {
110
file.close ();
111
return
OpenError
;
//
112
}
113
ok =
m_document
.
setContent
( &file );
114
if
( ! ok ) {
115
file.close ();
116
return
ParseError
;
117
}
118
119
QFileInfo
info ( file );
120
#if QT_VERSION < 0x040000
121
QString
dir = info.
dirPath
();
122
#else
123
QString
dir = info.path();
124
#endif
125
QDir::setCurrent
( dir );
126
127
file.close ();
128
129
return
Success
;
130
}
131
132
}
// namespace hippodraw
133
QtXmlDocument.h
QtXmlDocument class interface.
hippodraw::QtXmlDocument::QtXmlDocument
QtXmlDocument(const QtXmlDocument &)
A private copy constructor in order to avoid copying.
QDomDocument::documentElement
documentElement() const
hippodraw::XmlDocument::Success
Definition:
XmlDocument.h:37
QFile
hippodraw::QtXmlDocument::m_document
QDomDocument m_document
The DOM element wrapped by this object.
Definition:
QtXmlDocument.h:36
QTextStream
hippodraw::XmlTextNode
A pure virtual base class of XML DOM Text node wrapper.
Definition:
XmlTextNode.h:28
hippodraw::QtXmlDocument::appendChild
virtual void appendChild(XmlElement &)
Appends the root element to the document.
Definition:
QtXmlDocument.cxx:67
hippodraw::QtXmlDocument::documentElement
virtual XmlElement * documentElement() const
Returns the root document element.
Definition:
QtXmlDocument.cxx:41
hippodraw::XmlDocument::WriteError
Definition:
XmlDocument.h:37
hippodraw
Namespace for HippoDraw.
Definition:
AxesType.cxx:21
hippodraw::QtXmlDocument::~QtXmlDocument
~QtXmlDocument()
The dstructor.
Definition:
QtXmlDocument.cxx:37
hippodraw::QtXmlNode::m_node
QDomNode m_node
The DOM node wrapped by this object.
Definition:
QtXmlNode.h:41
QDir::setCurrent
setCurrent(const QString &path)
QString
QFile::open
open(int m)
QtXmlTextNode.h
hippodraw::QtXmlTextNode class interface
QDomDocument::createTextNode
createTextNode(const QString &value)
QFileInfo
hippodraw::QtXmlDocument::createTextNode
virtual XmlTextNode * createTextNode(const std::string &tag)
Creates a new DOM Text node.
Definition:
QtXmlDocument.cxx:59
QDomDocument
QFileInfo::dirPath
dirPath(bool absPath=FALSE) const
hippodraw::XmlElement
A pure virtual base class of XML element wrapper.
Definition:
XmlElement.h:30
hippodraw::QtXmlDocument::createElement
virtual XmlElement * createElement(const std::string &tagName)
Creates a new DOM element wrapper object and returns a pointer to it.
Definition:
QtXmlDocument.cxx:50
hippodraw::QtXmlElement
An XML element using the Qt XML module.
Definition:
QtXmlElement.h:38
hippodraw::XmlDocument::Status
Status
Status codes for opening an XML document.
Definition:
XmlDocument.h:37
hippodraw::QtXmlDocument::saveToFile
virtual Status saveToFile(const std::string &filename)
Saves the document to the file.
Definition:
QtXmlDocument.cxx:77
QDomDocument::createElement
createElement(const QString &tagName)
hippodraw::QtXmlTextNode
An XML Dom text node using the Qt XML module.
Definition:
QtXmlTextNode.h:38
QDomElement
QtXmlElement.h
hippodraw::QtXmlElement class interface
QDomText
hippodraw::XmlDocument::OpenError
Definition:
XmlDocument.h:37
hippodraw::XmlDocument::ParseError
Definition:
XmlDocument.h:37
hippodraw::QtXmlDocument::setContent
virtual Status setContent(const std::string &filename)
Sets the content of the XML document from the text in the file filename.
Definition:
QtXmlDocument.cxx:100
QDomDocument::setContent
setContent(const QCString &buffer, bool namespaceProcessing, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
Generated for HippoDraw Class Library by