GUI: Add errors read from XML report to GUI.

This commit is contained in:
Kimmo Varis 2010-07-11 02:02:08 +03:00
parent 9a5166075f
commit f894b19209
4 changed files with 29 additions and 13 deletions

View File

@ -17,6 +17,7 @@
*/ */
#include <QFile> #include <QFile>
#include "erroritem.h"
#include "report.h" #include "report.h"
Report::Report(const QString &filename, QObject * parent) : Report::Report(const QString &filename, QObject * parent) :

View File

@ -229,10 +229,11 @@ void ResultsView::DisableProgressbar()
void ResultsView::ReadErrorsXml(const QString &filename) void ResultsView::ReadErrorsXml(const QString &filename)
{ {
XmlReport *report = new XmlReport(filename, this); XmlReport *report = new XmlReport(filename, this);
QList<ErrorLine> errors;
if (report) if (report)
{ {
if (report->Open()) if (report->Open())
report->Read(); errors = report->Read();
else else
{ {
QMessageBox msgBox; QMessageBox msgBox;
@ -250,4 +251,11 @@ void ResultsView::ReadErrorsXml(const QString &filename)
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.exec(); msgBox.exec();
} }
ErrorLine line;
foreach(line, errors)
{
ErrorItem item(line);
mUI.mTree->AddErrorItem(item);
}
} }

View File

@ -19,6 +19,7 @@
#include <QFile> #include <QFile>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <qdebug> #include <qdebug>
#include "erroritem.h"
#include "xmlreport.h" #include "xmlreport.h"
static const char ResultElementName[] = "results"; static const char ResultElementName[] = "results";
@ -96,13 +97,14 @@ void XmlReport::WriteError(const ErrorItem &error)
mXmlWriter->writeEndElement(); mXmlWriter->writeEndElement();
} }
void XmlReport::Read() QList<ErrorLine> XmlReport::Read()
{ {
QList<ErrorLine> errors;
bool insideResults = false; bool insideResults = false;
if (!mXmlReader) if (!mXmlReader)
{ {
qDebug() << "You must Open() the file before reading it!"; qDebug() << "You must Open() the file before reading it!";
return; return errors;
} }
while (!mXmlReader->atEnd()) while (!mXmlReader->atEnd())
{ {
@ -114,7 +116,10 @@ void XmlReport::Read()
// Read error element from inside result element // Read error element from inside result element
if (insideResults && mXmlReader->name() == ErrorElementName) if (insideResults && mXmlReader->name() == ErrorElementName)
ReadError(mXmlReader); {
ErrorLine line = ReadError(mXmlReader);
errors.append(line);
}
break; break;
case QXmlStreamReader::EndElement: case QXmlStreamReader::EndElement:
@ -135,18 +140,20 @@ void XmlReport::Read()
break; break;
} }
} }
return errors;
} }
void XmlReport::ReadError(QXmlStreamReader *reader) ErrorLine XmlReport::ReadError(QXmlStreamReader *reader)
{ {
ErrorLine line;
if (reader->name().toString() == ErrorElementName) if (reader->name().toString() == ErrorElementName)
{ {
QXmlStreamAttributes attribs = reader->attributes(); QXmlStreamAttributes attribs = reader->attributes();
QString filename = attribs.value("", FilenameAttribute).toString(); line.file = attribs.value("", FilenameAttribute).toString();
QString line = attribs.value("", LineAttribute).toString(); line.line = attribs.value("", LineAttribute).toString();
QString id = attribs.value("", IdAttribute).toString(); line.id = attribs.value("", IdAttribute).toString();
QString severity = attribs.value("", SeverityAttribute).toString(); line.severity = attribs.value("", SeverityAttribute).toString();
QString msg = attribs.value("", MsgAttribute).toString(); line.msg = attribs.value("", MsgAttribute).toString();
qDebug() << "Error: " << filename << " " << line << " " << id << " " << severity << " " << msg;
} }
return line;
} }

View File

@ -72,14 +72,14 @@ public:
/** /**
* @brief Read contents of the report file. * @brief Read contents of the report file.
*/ */
void Read(); QList<ErrorLine> Read();
protected: protected:
/** /**
* @brief Read and parse error item from XML stream. * @brief Read and parse error item from XML stream.
* @param reader XML stream reader to use. * @param reader XML stream reader to use.
*/ */
void ReadError(QXmlStreamReader *reader); ErrorLine ReadError(QXmlStreamReader *reader);
private: private:
/** /**