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 

Generated for HippoDraw Class Library by doxygen