scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

XmlStreamReader.cpp
Go to the documentation of this file.
1 
11 
30 #include "lib/XmlStreamReader.h"
31 #include <QtDebug>
32 
34 {
35  init();
36 }
37 
39 : QXmlStreamReader(device)
40 {
41  init();
42 }
43 
45 : QXmlStreamReader(data)
46 {
47  init();
48 }
49 
51 : QXmlStreamReader(data)
52 {
53  init();
54 }
55 
57 : QXmlStreamReader(data)
58 {
59  init();
60 }
61 
63 {
64  d_error_prefix = QObject::tr("XML reader error: ","prefix for XML error messages");
65  d_error_postfix = QObject::tr(" (loading failed)", "postfix for XML error messages");
66  d_warning_prefix = QObject::tr("XML reader warning: ","prefix for XML warning messages");
67  d_warning_postfix = QObject::tr("", "postfix for XML warning messages");
68 }
69 
71 {
72  return d_warnings;
73 }
74 
76 {
77  return !(d_warnings.isEmpty());
78 }
79 
80 void XmlStreamReader::raiseError(const QString & message)
81 {
82  QString prefix2 = QString(QObject::tr("line %1, column %2: ").arg(lineNumber()).arg(columnNumber()));
83  QXmlStreamReader::raiseError(d_error_prefix+prefix2+message+d_error_postfix);
84 }
85 
86 void XmlStreamReader::raiseWarning(const QString & message)
87 {
88  QString prefix2 = QString(QObject::tr("line %1, column %2: ").arg(lineNumber()).arg(columnNumber()));
89  d_warnings.append(d_warning_prefix+prefix2+message+d_warning_postfix);
90 }
91 
93 {
94  if (atEnd())
95  {
96  raiseError(QObject::tr("unexpected end of document"));
97  return false;
98  }
99  do {
100  readNext();
101  } while (!(isStartElement() || isEndElement() || atEnd()));
102  if (atEnd())
103  {
104  raiseError(QObject::tr("unexpected end of document"));
105  return false;
106  }
107  return true;
108 }
109 
110 int XmlStreamReader::readAttributeInt(const QString & name, bool * ok)
111 {
112  QString str = attributes().value(namespaceUri().toString(), name).toString();
113  if (str.isEmpty())
114  {
115  if (ok) *ok = false;
116  return 0;
117  }
118  return str.toInt(ok);
119 }
120 
122 {
123  int depth = 1;
124  if (atEnd())
125  {
126  raiseError(QObject::tr("unexpected end of document"));
127  return false;
128  }
129  do {
130  readNext();
131  if (isEndElement()) depth--;
132  if (isStartElement()) depth++;
133  } while (!((isEndElement() && depth == 0) || atEnd()));
134  if (atEnd())
135  {
136  raiseError(QObject::tr("unexpected end of document"));
137  return false;
138  }
139  return true;
140 }
XmlStreamReader::d_warnings
QStringList d_warnings
Definition: XmlStreamReader.h:83
XmlStreamReader::skipToNextTag
bool skipToNextTag()
Go to the next start or end element tag.
Definition: XmlStreamReader.cpp:92
XmlStreamReader::raiseError
void raiseError(const QString &message=QString())
Definition: XmlStreamReader.cpp:80
data
Definition: exp_saturation.c:37
XmlStreamReader::readAttributeInt
int readAttributeInt(const QString &name, bool *ok)
Read an XML attribute and convert it to int.
Definition: XmlStreamReader.cpp:110
str
#define str(x)
Definition: PythonScripting.cpp:41
XmlStreamReader::hasWarnings
bool hasWarnings() const
Definition: XmlStreamReader.cpp:75
toString
S toString(const QString &x)
Deal with conversion between QString and std::string/std::wstring in a generic way.
XmlStreamReader::d_warning_postfix
QString d_warning_postfix
Definition: XmlStreamReader.h:87
XmlStreamReader::skipToEndElement
bool skipToEndElement()
Go to the end element tag of the current element.
Definition: XmlStreamReader.cpp:121
XmlStreamReader::d_error_postfix
QString d_error_postfix
Definition: XmlStreamReader.h:85
XmlStreamReader::init
void init()
Definition: XmlStreamReader.cpp:62
XmlStreamReader::warningStrings
QStringList warningStrings() const
Definition: XmlStreamReader.cpp:70
XmlStreamReader.h
XmlStreamReader::XmlStreamReader
XmlStreamReader()
Definition: XmlStreamReader.cpp:33
name
char * name()
Definition: exp_saturation.c:45
XmlStreamReader::d_error_prefix
QString d_error_prefix
Definition: XmlStreamReader.h:84
XmlStreamReader::d_warning_prefix
QString d_warning_prefix
Definition: XmlStreamReader.h:86
XmlStreamReader::raiseWarning
void raiseWarning(const QString &message=QString())
Definition: XmlStreamReader.cpp:86