From 9eacceb00ac43281459b1789b5a150dd7d50ebab Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 5 Feb 2011 15:56:56 +0200 Subject: [PATCH] GUI: Read XML format version 2 files. Implement the parsing of XML format v2 error data. --- gui/xmlreportv2.cpp | 69 +++++++++++++++++++++++++++++++++++---------- gui/xmlreportv2.h | 6 ++++ 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/gui/xmlreportv2.cpp b/gui/xmlreportv2.cpp index 7e2011a92..e6068ed8c 100644 --- a/gui/xmlreportv2.cpp +++ b/gui/xmlreportv2.cpp @@ -180,28 +180,67 @@ QList XmlReportV2::Read() ErrorItem XmlReportV2::ReadError(QXmlStreamReader *reader) { + /* + Error example from the core program in xml + + + + + */ + ErrorItem item; if (reader->name().toString() == ErrorElementName) { QXmlStreamAttributes attribs = reader->attributes(); - const QString file = attribs.value("", FilenameAttribute).toString(); - item.file = file; - item.files.push_back(file); - const int line = attribs.value("", LineAttribute).toString().toUInt(); - item.lines.push_back(line); item.id = attribs.value("", IdAttribute).toString(); item.severity = attribs.value("", SeverityAttribute).toString(); + item.summary = attribs.value("", MsgAttribute).toString(); + item.message = attribs.value("", VerboseAttribute).toString(); - // NOTE: This dublicates the message to Summary-field. But since - // old XML format doesn't have separate summary and verbose messages - // we must add same message to both data so it shows up in GUI. - // Check if there is full stop and cut the summary to it. - QString summary = attribs.value("", MsgAttribute).toString(); - const int ind = summary.indexOf('.'); - if (ind != -1) - summary = summary.left(ind + 1); - item.summary = summary; - item.message = attribs.value("", MsgAttribute).toString(); + ReadLocations(item); } return item; } + +void XmlReportV2::ReadLocations(ErrorItem &item) +{ + QList errors; + bool allRead = false; + while (!allRead && !mXmlReader->atEnd()) + { + switch (mXmlReader->readNext()) + { + case QXmlStreamReader::StartElement: + if (mXmlReader->name() != LocationElementName) + continue; // Skip other than location elements + { + QXmlStreamAttributes attribs = mXmlReader->attributes(); + const QString file = attribs.value("", FilenameAttribute).toString(); + if (item.file.isEmpty()) + item.file = file; + item.files.push_back(file); + const int line = attribs.value("", LineAttribute).toString().toUInt(); + item.lines.push_back(line); + } + break; + + case QXmlStreamReader::EndElement: + if (mXmlReader->name() == LocationElementName) + allRead = true; + break; + + // Not handled + case QXmlStreamReader::NoToken: + case QXmlStreamReader::Invalid: + case QXmlStreamReader::StartDocument: + case QXmlStreamReader::EndDocument: + case QXmlStreamReader::Characters: + case QXmlStreamReader::Comment: + case QXmlStreamReader::DTD: + case QXmlStreamReader::EntityReference: + case QXmlStreamReader::ProcessingInstruction: + break; + } + } +} diff --git a/gui/xmlreportv2.h b/gui/xmlreportv2.h index 6b1a2841c..d60b71126 100644 --- a/gui/xmlreportv2.h +++ b/gui/xmlreportv2.h @@ -81,6 +81,12 @@ protected: */ ErrorItem ReadError(QXmlStreamReader *reader); + /** + * @brief Read and parse error items location elements from XML stream. + * @param item ErrorItem to write the location data. + */ + void ReadLocations(ErrorItem &item); + private: /** * @brief XML stream reader for reading the report in XML format.