From 0e9d0e9bde155e2bfa5a87deb648571c3389a3b2 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 10 Jul 2010 18:20:45 +0300 Subject: [PATCH] GUI: Refactor error data passing to use own class. --- gui/csvreport.cpp | 9 +++------ gui/csvreport.h | 5 ++--- gui/report.h | 18 +++++++++++++++--- gui/resultstree.cpp | 22 +++++++++------------- gui/txtreport.cpp | 15 ++++++--------- gui/txtreport.h | 5 ++--- gui/xmlreport.cpp | 13 ++++++------- gui/xmlreport.h | 4 ++-- 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/gui/csvreport.cpp b/gui/csvreport.cpp index 7a4c5efab..db47fcdb2 100644 --- a/gui/csvreport.cpp +++ b/gui/csvreport.cpp @@ -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; } diff --git a/gui/csvreport.h b/gui/csvreport.h index 23e3eadef..5661a03d5 100644 --- a/gui/csvreport.h +++ b/gui/csvreport.h @@ -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: diff --git a/gui/report.h b/gui/report.h index 9e8972951..386911dd0 100644 --- a/gui/report.h +++ b/gui/report.h @@ -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: diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index e69138a81..a01785b59 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -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); } } diff --git a/gui/txtreport.cpp b/gui/txtreport.cpp index 0cf4728ba..0a064f354 100644 --- a/gui/txtreport.cpp +++ b/gui/txtreport.cpp @@ -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; } diff --git a/gui/txtreport.h b/gui/txtreport.h index f3035536a..8dab58622 100644 --- a/gui/txtreport.h +++ b/gui/txtreport.h @@ -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: diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index 30d0e2d6b..d8b5d2212 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -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(); } diff --git a/gui/xmlreport.h b/gui/xmlreport.h index 06c0fbf35..5cc99d769 100644 --- a/gui/xmlreport.h +++ b/gui/xmlreport.h @@ -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.