GUI: Read ErrorItems instead of ErrorLines from XML report.

XML report format 1 only had error "lines" that we promoted to "items"
when adding to GUI. XML report format 2 contains error "items" so
change the code to read items and do the promotion directly when
reading and parsing the data.
This commit is contained in:
Kimmo Varis 2011-02-05 12:41:29 +02:00
parent 0f0f53f919
commit d31703e452
6 changed files with 41 additions and 35 deletions

View File

@ -260,7 +260,7 @@ void ResultsView::ReadErrorsXml(const QString &filename)
else if (version == 2)
report = new XmlReportV2(filename, this);
QList<ErrorLine> errors;
QList<ErrorItem> errors;
if (report)
{
if (report->Open())
@ -283,10 +283,9 @@ void ResultsView::ReadErrorsXml(const QString &filename)
msgBox.exec();
}
ErrorLine line;
foreach(line, errors)
ErrorItem item;
foreach(item, errors)
{
ErrorItem item(line);
mUI.mTree->AddErrorItem(item);
}
mUI.mTree->SetCheckDirectory("");

View File

@ -22,6 +22,7 @@
#include <QString>
#include <QList>
#include "report.h"
#include "erroritem.h"
class QObject;
@ -40,7 +41,7 @@ public:
/**
* @brief Read contents of the report file.
*/
virtual QList<ErrorLine> Read() = 0;
virtual QList<ErrorItem> Read() = 0;
/**
* @brief Quote the message.

View File

@ -106,9 +106,9 @@ void XmlReportV1::WriteError(const ErrorItem &error)
mXmlWriter->writeEndElement();
}
QList<ErrorLine> XmlReportV1::Read()
QList<ErrorItem> XmlReportV1::Read()
{
QList<ErrorLine> errors;
QList<ErrorItem> errors;
bool insideResults = false;
if (!mXmlReader)
{
@ -126,8 +126,8 @@ QList<ErrorLine> XmlReportV1::Read()
// Read error element from inside result element
if (insideResults && mXmlReader->name() == ErrorElementName)
{
ErrorLine line = ReadError(mXmlReader);
errors.append(line);
ErrorItem item = ReadError(mXmlReader);
errors.append(item);
}
break;
@ -152,16 +152,19 @@ QList<ErrorLine> XmlReportV1::Read()
return errors;
}
ErrorLine XmlReportV1::ReadError(QXmlStreamReader *reader)
ErrorItem XmlReportV1::ReadError(QXmlStreamReader *reader)
{
ErrorLine line;
ErrorItem item;
if (reader->name().toString() == ErrorElementName)
{
QXmlStreamAttributes attribs = reader->attributes();
line.file = attribs.value("", FilenameAttribute).toString();
line.line = attribs.value("", LineAttribute).toString().toUInt();
line.id = attribs.value("", IdAttribute).toString();
line.severity = attribs.value("", SeverityAttribute).toString();
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();
// NOTE: This dublicates the message to Summary-field. But since
// old XML format doesn't have separate summary and verbose messages
@ -171,8 +174,8 @@ ErrorLine XmlReportV1::ReadError(QXmlStreamReader *reader)
const int ind = summary.indexOf('.');
if (ind != -1)
summary = summary.left(ind + 1);
line.summary = summary;
line.message = attribs.value("", MsgAttribute).toString();
item.summary = summary;
item.message = attribs.value("", MsgAttribute).toString();
}
return line;
return item;
}

View File

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

View File

@ -132,9 +132,9 @@ void XmlReportV2::WriteError(const ErrorItem &error)
mXmlWriter->writeEndElement();
}
QList<ErrorLine> XmlReportV2::Read()
QList<ErrorItem> XmlReportV2::Read()
{
QList<ErrorLine> errors;
QList<ErrorItem> errors;
bool insideResults = false;
if (!mXmlReader)
{
@ -152,8 +152,8 @@ QList<ErrorLine> XmlReportV2::Read()
// Read error element from inside result element
if (insideResults && mXmlReader->name() == ErrorElementName)
{
ErrorLine line = ReadError(mXmlReader);
errors.append(line);
ErrorItem item = ReadError(mXmlReader);
errors.append(item);
}
break;
@ -178,16 +178,19 @@ QList<ErrorLine> XmlReportV2::Read()
return errors;
}
ErrorLine XmlReportV2::ReadError(QXmlStreamReader *reader)
ErrorItem XmlReportV2::ReadError(QXmlStreamReader *reader)
{
ErrorLine line;
ErrorItem item;
if (reader->name().toString() == ErrorElementName)
{
QXmlStreamAttributes attribs = reader->attributes();
line.file = attribs.value("", FilenameAttribute).toString();
line.line = attribs.value("", LineAttribute).toString().toUInt();
line.id = attribs.value("", IdAttribute).toString();
line.severity = attribs.value("", SeverityAttribute).toString();
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();
// NOTE: This dublicates the message to Summary-field. But since
// old XML format doesn't have separate summary and verbose messages
@ -197,8 +200,8 @@ ErrorLine XmlReportV2::ReadError(QXmlStreamReader *reader)
const int ind = summary.indexOf('.');
if (ind != -1)
summary = summary.left(ind + 1);
line.summary = summary;
line.message = attribs.value("", MsgAttribute).toString();
item.summary = summary;
item.message = attribs.value("", MsgAttribute).toString();
}
return line;
return item;
}

View File

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