From 7c589384d29c78b7240bfc58a1b6f347a89cb57b Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 7 Mar 2011 21:10:30 +0200 Subject: [PATCH] GUI: Use severity enum in ErrorItem. Convert from using string to enum values for severity in ErrorItem. Storing and handling severity as string was the easy way earlier but it is not convenient or efficient way to handle severities. This commit is the first step in converting severity handling to use the enum values instead of strings. --- gui/csvreport.cpp | 2 +- gui/erroritem.cpp | 4 +-- gui/erroritem.h | 60 +++++++++++++++++++++++++++++++++++++++++++- gui/resultstree.cpp | 8 +++--- gui/resultsview.cpp | 2 +- gui/threadresult.cpp | 2 +- gui/txtreport.cpp | 2 +- gui/xmlreportv1.cpp | 6 +++-- gui/xmlreportv2.cpp | 6 +++-- 9 files changed, 77 insertions(+), 15 deletions(-) diff --git a/gui/csvreport.cpp b/gui/csvreport.cpp index 0080f1434..1147d01f3 100644 --- a/gui/csvreport.cpp +++ b/gui/csvreport.cpp @@ -65,7 +65,7 @@ void CsvReport::WriteError(const ErrorItem &error) QString line; const QString file = QDir::toNativeSeparators(error.files[error.files.size() - 1]); line += QString("%1,%2,").arg(file).arg(error.lines[error.lines.size() - 1]); - line += QString("%1,%2").arg(error.severity).arg(error.summary); + line += QString("%1,%2").arg(GuiSeverity::toString(error.severity)).arg(error.summary); mTxtWriter << line << endl; } diff --git a/gui/erroritem.cpp b/gui/erroritem.cpp index a7b09c853..dd7fc1aa9 100644 --- a/gui/erroritem.cpp +++ b/gui/erroritem.cpp @@ -35,14 +35,14 @@ ErrorItem::ErrorItem(const ErrorLine &line) files.append(line.file); lines.append(line.line); id = line.id; - severity = line.severity; + severity = GuiSeverity::fromString(line.severity); summary = line.summary; message = line.message; } QString ErrorItem::ToString() const { - QString str = file + " - " + id + " - " + severity +"\n"; + QString str = file + " - " + id + " - " + GuiSeverity::toString(severity) +"\n"; str += summary + "\n"; str += message + "\n"; for (int i = 0; i < files.size(); i++) diff --git a/gui/erroritem.h b/gui/erroritem.h index c6b36b7c3..8092c5f46 100644 --- a/gui/erroritem.h +++ b/gui/erroritem.h @@ -22,12 +22,70 @@ #include #include #include +#include "errorlogger.h" class ErrorLine; /// @addtogroup GUI /// @{ + +/** + * @brief GUI versions of severity conversions. + * GUI needs its own versions of conversions since GUI uses Qt's QString + * instead of the std::string used by lib/cli. + */ +class GuiSeverity : Severity +{ +public: + static QString toString(SeverityType severity) + { + switch (severity) + { + case none: + return ""; + case error: + return "error"; + case warning: + return "warning"; + case style: + return "style"; + case performance: + return "performance"; + case portability: + return "portability"; + case information: + return "information"; + case debug: + return "debug"; + }; + return "???"; + } + + static SeverityType fromString(const QString &severity) + { + if (severity.isEmpty()) + return none; + if (severity == "none") + return none; + if (severity == "error") + return error; + if (severity == "warning") + return warning; + if (severity == "style") + return style; + if (severity == "performance") + return performance; + if (severity == "portability") + return portability; + if (severity == "information") + return information; + if (severity == "debug") + return debug; + return none; + } +}; + /** * @brief A class containing error data for one error. * @@ -54,7 +112,7 @@ public: QStringList files; QList lines; QString id; - QString severity; + Severity::SeverityType severity; QString summary; QString message; }; diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 5f2630c53..59b6bfc23 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -109,7 +109,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) realfile = tr("Undefined file"); } - bool hide = !mShowTypes[SeverityToShowType(item.severity)]; + bool hide = !mShowTypes[SeverityToShowType(GuiSeverity::toString(item.severity))]; //if there is at least one error that is not hidden, we have a visible error if (!hide) @@ -123,7 +123,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) line.line = item.lines[0]; line.summary = item.summary; line.message = item.message; - line.severity = item.severity; + line.severity = GuiSeverity::toString(item.severity); //Create the base item for the error and ensure it has a proper //file item as a parent QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(line.file, hide), @@ -137,7 +137,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) //Add user data to that item QMap data; data["hide"] = false; - data["severity"] = SeverityToShowType(item.severity); + data["severity"] = SeverityToShowType(GuiSeverity::toString(item.severity)); data["summary"] = item.summary; data["message"] = item.message; data["file"] = item.files[0]; @@ -794,7 +794,7 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item) QVariantMap data = userdata.toMap(); ErrorItem item; - item.severity = ShowTypeToString(VariantToShowType(data["severity"])); + item.severity = GuiSeverity::fromString(ShowTypeToString(VariantToShowType(data["severity"]))); item.summary = data["summary"].toString(); item.message = data["message"].toString(); item.id = data["id"].toString(); diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 1d4f90568..13bf85348 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -88,7 +88,7 @@ void ResultsView::Error(const ErrorItem &item) mErrorsFound = true; mUI.mTree->AddErrorItem(item); emit GotResults(); - mStatistics->AddItem(ResultsTree::SeverityToShowType(item.severity)); + mStatistics->AddItem(ResultsTree::SeverityToShowType(GuiSeverity::toString(item.severity))); } void ResultsView::ShowResults(ShowTypes type, bool show) diff --git a/gui/threadresult.cpp b/gui/threadresult.cpp index 7a92481c4..38e990ba1 100644 --- a/gui/threadresult.cpp +++ b/gui/threadresult.cpp @@ -71,7 +71,7 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg) item.lines = lines; item.summary = QString::fromStdString(msg.shortMessage()); item.message = QString::fromStdString(msg.verboseMessage()); - item.severity = QString::fromStdString(Severity::toString(msg._severity)); + item.severity = msg._severity; if (msg._severity != Severity::debug) emit Error(item); diff --git a/gui/txtreport.cpp b/gui/txtreport.cpp index 20c34d7b7..f7c5ceb86 100644 --- a/gui/txtreport.cpp +++ b/gui/txtreport.cpp @@ -76,7 +76,7 @@ void TxtReport::WriteError(const ErrorItem &error) } } - line += QString("(%1) %2").arg(error.severity).arg(error.summary); + line += QString("(%1) %2").arg(GuiSeverity::toString(error.severity)).arg(error.summary); mTxtWriter << line << endl; } diff --git a/gui/xmlreportv1.cpp b/gui/xmlreportv1.cpp index 1062de07f..bab621f81 100644 --- a/gui/xmlreportv1.cpp +++ b/gui/xmlreportv1.cpp @@ -100,7 +100,9 @@ void XmlReportV1::WriteError(const ErrorItem &error) const QString line = QString::number(error.lines[error.lines.size() - 1]); mXmlWriter->writeAttribute(LineAttribute, line); mXmlWriter->writeAttribute(IdAttribute, error.id); - mXmlWriter->writeAttribute(SeverityAttribute, error.severity); + + // Don't localize severity so we can read these files + mXmlWriter->writeAttribute(SeverityAttribute, GuiSeverity::toString(error.severity)); const QString message = XmlReport::quoteMessage(error.message); mXmlWriter->writeAttribute(MsgAttribute, message); mXmlWriter->writeEndElement(); @@ -165,7 +167,7 @@ ErrorItem XmlReportV1::ReadError(QXmlStreamReader *reader) 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(); + item.severity = GuiSeverity::fromString(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 diff --git a/gui/xmlreportv2.cpp b/gui/xmlreportv2.cpp index 381d7d9c0..2c5665704 100644 --- a/gui/xmlreportv2.cpp +++ b/gui/xmlreportv2.cpp @@ -110,7 +110,9 @@ void XmlReportV2::WriteError(const ErrorItem &error) mXmlWriter->writeStartElement(ErrorElementName); mXmlWriter->writeAttribute(IdAttribute, error.id); - mXmlWriter->writeAttribute(SeverityAttribute, error.severity); + + // Don't localize severity so we can read these files + mXmlWriter->writeAttribute(SeverityAttribute, GuiSeverity::toString(error.severity)); const QString summary = XmlReport::quoteMessage(error.summary); mXmlWriter->writeAttribute(MsgAttribute, summary); const QString message = XmlReport::quoteMessage(error.message); @@ -196,7 +198,7 @@ ErrorItem XmlReportV2::ReadError(QXmlStreamReader *reader) { QXmlStreamAttributes attribs = reader->attributes(); item.id = attribs.value("", IdAttribute).toString(); - item.severity = attribs.value("", SeverityAttribute).toString(); + item.severity = GuiSeverity::fromString(attribs.value("", SeverityAttribute).toString()); const QString summary = attribs.value("", MsgAttribute).toString(); item.summary = XmlReport::unquoteMessage(summary); const QString message = attribs.value("", VerboseAttribute).toString();