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 "erroritem.h"
#include "report.h"
Report::Report(const QString &filename, QObject * parent) :

View File

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

View File

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

View File

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