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

View File

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

View File

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

View File

@ -601,8 +601,6 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
return; return;
} }
//qDebug() << item->text() << "has" << item->rowCount() << "errors";
for (int i = 0; i < item->rowCount(); i++) for (int i = 0; i < item->rowCount(); i++)
{ {
QStandardItem *error = item->child(i, 0); QStandardItem *error = item->child(i, 0);
@ -622,17 +620,15 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
//Convert it to QVariantMap //Convert it to QVariantMap
QVariantMap data = userdata.toMap(); QVariantMap data = userdata.toMap();
QString severity = ShowTypeToString(VariantToShowType(data["severity"])); ErrorItem item;
QString message = data["message"].toString(); item.severity = ShowTypeToString(VariantToShowType(data["severity"]));
QString id = data["id"].toString(); item.msg = data["message"].toString();
item.id = data["id"].toString();
QString file = StripPath(data["file"].toString(), true); QString file = StripPath(data["file"].toString(), true);
QString line = data["line"].toString(); QString line = data["line"].toString();
QStringList files; item.files << file;
QStringList lines; item.lines << line;
files << file;
lines << line;
for (int j = 0; j < error->rowCount(); j++) 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); file = StripPath(child_data["file"].toString(), true);
line = child_data["line"].toString(); line = child_data["line"].toString();
files << file; item.files << file;
lines << line; 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 // No footer for txt report
} }
void TxtReport::WriteError(const QStringList &files, const QStringList &lines, void TxtReport::WriteError(const ErrorItem &error)
const QString &id, const QString &severity, const QString &msg)
{ {
Q_UNUSED(id);
/* /*
Error example from the core program in text Error example from the core program in text
[gui/test.cpp:23] -> [gui/test.cpp:14]: (error) Mismatching allocation and deallocation: k [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; 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]); line += QString("[%1:%2]").arg(error.files[i]).arg(error.lines[i]);
if (i < lines.size() - 1 && lines.size() > 0) if (i < error.lines.size() - 1 && error.lines.size() > 0)
{ {
line += " -> "; line += " -> ";
} }
if (i == lines.size() - 1) if (i == error.lines.size() - 1)
{ {
line += ": "; line += ": ";
} }
} }
line += QString("(%1) %2").arg(severity).arg(msg); line += QString("(%1) %2").arg(error.severity).arg(error.msg);
mTxtWriter << line << endl; mTxtWriter << line << endl;
} }

View File

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

View File

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

View File

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