GUI: Refactor error data passing to use own class.

This commit is contained in:
Kimmo Varis 2010-07-10 18:20:45 +03:00
parent 5e14abf735
commit 0e9d0e9bde
8 changed files with 45 additions and 46 deletions

View File

@ -51,19 +51,16 @@ void CsvReport::WriteFooter()
// No footer for CSV report
}
void CsvReport::WriteError(const QStringList &files, const QStringList &lines,
const QString &id, const QString &severity, const QString &msg)
void CsvReport::WriteError(const ErrorItem &error)
{
Q_UNUSED(id);
/*
Error as CSV line
gui/test.cpp,23,error,Mismatching allocation and deallocation: k
*/
QString line;
line += QString("%1,%2,").arg(files[files.size() - 1]).arg(lines[lines.size() - 1]);
line += QString("%1,%2").arg(severity).arg(msg);
line += QString("%1,%2,").arg(error.files[error.files.size() - 1]).arg(error.lines[error.lines.size() - 1]);
line += QString("%1,%2").arg(error.severity).arg(error.msg);
mTxtWriter << line << endl;
}

View File

@ -60,10 +60,9 @@ public:
/**
* @brief Write error to report.
* @param error Error data.
*/
virtual void WriteError(const QStringList &files, const QStringList &lines,
const QString &id, const QString &severity,
const QString &msg);
virtual void WriteError(const ErrorItem &error);
private:

View File

@ -27,6 +27,19 @@
/// @addtogroup GUI
/// @{
/**
* @brief A class containing error data.
*/
class ErrorItem
{
public:
QStringList files;
QStringList lines;
QString id;
QString severity;
QString msg;
};
/**
* @brief A base class for reports.
*/
@ -73,10 +86,9 @@ public:
/**
* @brief Write error to report.
* @param error Error data.
*/
virtual void WriteError(const QStringList &files, const QStringList &lines,
const QString &id, const QString &severity,
const QString &msg) = 0;
virtual void WriteError(const ErrorItem &error) = 0;
protected:

View File

@ -601,8 +601,6 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
return;
}
//qDebug() << item->text() << "has" << item->rowCount() << "errors";
for (int i = 0; i < item->rowCount(); i++)
{
QStandardItem *error = item->child(i, 0);
@ -622,17 +620,15 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
//Convert it to QVariantMap
QVariantMap data = userdata.toMap();
QString severity = ShowTypeToString(VariantToShowType(data["severity"]));
QString message = data["message"].toString();
QString id = data["id"].toString();
ErrorItem item;
item.severity = ShowTypeToString(VariantToShowType(data["severity"]));
item.msg = data["message"].toString();
item.id = data["id"].toString();
QString file = StripPath(data["file"].toString(), true);
QString line = data["line"].toString();
QStringList files;
QStringList lines;
files << file;
lines << line;
item.files << file;
item.lines << line;
for (int j = 0; j < error->rowCount(); j++)
{
@ -645,11 +641,11 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
file = StripPath(child_data["file"].toString(), true);
line = child_data["line"].toString();
files << file;
lines << line;
item.files << file;
item.lines << line;
}
report->WriteError(files, lines, id, severity, message);
report->WriteError(item);
}
}

View File

@ -51,11 +51,8 @@ void TxtReport::WriteFooter()
// No footer for txt report
}
void TxtReport::WriteError(const QStringList &files, const QStringList &lines,
const QString &id, const QString &severity, const QString &msg)
void TxtReport::WriteError(const ErrorItem &error)
{
Q_UNUSED(id);
/*
Error example from the core program in text
[gui/test.cpp:23] -> [gui/test.cpp:14]: (error) Mismatching allocation and deallocation: k
@ -63,21 +60,21 @@ void TxtReport::WriteError(const QStringList &files, const QStringList &lines,
QString line;
for (int i = 0; i < lines.size(); i++)
for (int i = 0; i < error.lines.size(); i++)
{
line += QString("[%1:%2]").arg(files[i]).arg(lines[i]);
if (i < lines.size() - 1 && lines.size() > 0)
line += QString("[%1:%2]").arg(error.files[i]).arg(error.lines[i]);
if (i < error.lines.size() - 1 && error.lines.size() > 0)
{
line += " -> ";
}
if (i == lines.size() - 1)
if (i == error.lines.size() - 1)
{
line += ": ";
}
}
line += QString("(%1) %2").arg(severity).arg(msg);
line += QString("(%1) %2").arg(error.severity).arg(error.msg);
mTxtWriter << line << endl;
}

View File

@ -58,10 +58,9 @@ public:
/**
* @brief Write error to report.
* @param error Error data.
*/
virtual void WriteError(const QStringList &files, const QStringList &lines,
const QString &id, const QString &severity,
const QString &msg);
virtual void WriteError(const ErrorItem &error);
private:

View File

@ -78,8 +78,7 @@ void XmlReport::WriteFooter()
mXmlWriter->writeEndDocument();
}
void XmlReport::WriteError(const QStringList &files, const QStringList &lines,
const QString &id, const QString &severity, const QString &msg)
void XmlReport::WriteError(const ErrorItem &error)
{
/*
Error example from the core program in xml
@ -88,11 +87,11 @@ void XmlReport::WriteError(const QStringList &files, const QStringList &lines,
*/
mXmlWriter->writeStartElement(ErrorElementName);
mXmlWriter->writeAttribute(FilenameAttribute, files[files.size() - 1]);
mXmlWriter->writeAttribute(LineAttribute, lines[lines.size() - 1]);
mXmlWriter->writeAttribute(IdAttribute, id);
mXmlWriter->writeAttribute(SeverityAttribute, severity);
mXmlWriter->writeAttribute(MsgAttribute, msg);
mXmlWriter->writeAttribute(FilenameAttribute, error.files[error.files.size() - 1]);
mXmlWriter->writeAttribute(LineAttribute, error.lines[error.lines.size() - 1]);
mXmlWriter->writeAttribute(IdAttribute, error.id);
mXmlWriter->writeAttribute(SeverityAttribute, error.severity);
mXmlWriter->writeAttribute(MsgAttribute, error.msg);
mXmlWriter->writeEndElement();
}

View File

@ -65,9 +65,9 @@ public:
/**
* @brief Write error to report.
* @param error Error data.
*/
virtual void WriteError(const QStringList &files, const QStringList &lines,
const QString &id, const QString &severity, const QString &msg);
virtual void WriteError(const ErrorItem &error);
/**
* @brief Read contents of the report file.