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 
26  : m_document ( document )
27 {
28 }
29 
31 QtXmlDocument ( const std::string & name )
32 {
33  m_document = QDomDocument ( name.c_str () );
34 }
35 
38 {
39 }
40 
42 {
44 
45  return new QtXmlElement ( root );
46 }
47 
48 XmlElement *
50 createElement ( const std::string & tagName )
51 {
52  QDomElement element = m_document.createElement ( tagName.c_str() );
53 
54  return new QtXmlElement ( element );
55 }
56 
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 */
68 {
69  const QtXmlElement & qtelem
70  = dynamic_cast < const QtXmlElement & > ( child );
71 
72  m_document.appendChild ( qtelem.m_node );
73 }
74 
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 
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 
QDomNode m_node
The DOM node wrapped by this object.
Definition: QtXmlNode.h:41
virtual XmlElement * createElement(const std::string &tagName)
Creates a new DOM element wrapper object and returns a pointer to it.
documentElement() const
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
bool ok
Definition: CanvasView.cxx:163
setCurrent(const QString &path)
QDomDocument m_document
The DOM element wrapped by this object.
Definition: QtXmlDocument.h:36
Status
Status codes for opening an XML document.
Definition: XmlDocument.h:37
virtual void appendChild(XmlElement &)
Appends the root element to the document.
createTextNode(const QString &value)
virtual XmlTextNode * createTextNode(const std::string &tag)
Creates a new DOM Text node.
A pure virtual base class of XML DOM Text node wrapper.
Definition: XmlTextNode.h:28
dirPath(bool absPath=FALSE) const
hippodraw::QtXmlTextNode class interface
virtual Status setContent(const std::string &filename)
Sets the content of the XML document from the text in the file filename.
QtXmlDocument(const QtXmlDocument &)
A private copy constructor in order to avoid copying.
hippodraw::QtXmlElement class interface
QtXmlDocument class interface.
createElement(const QString &tagName)
virtual Status saveToFile(const std::string &filename)
Saves the document to the file.
~QtXmlDocument()
The dstructor.
virtual XmlElement * documentElement() const
Returns the root document element.
An XML Dom text node using the Qt XML module.
Definition: QtXmlTextNode.h:38
setContent(const QCString &buffer, bool namespaceProcessing, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
An XML element using the Qt XML module.
Definition: QtXmlElement.h:38

Generated for HippoDraw Class Library by doxygen