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.
This commit is contained in:
parent
a77993db75
commit
7c589384d2
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -22,12 +22,70 @@
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QMetaType>
|
||||
#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<unsigned int> lines;
|
||||
QString id;
|
||||
QString severity;
|
||||
Severity::SeverityType severity;
|
||||
QString summary;
|
||||
QString message;
|
||||
};
|
||||
|
|
|
@ -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<QString, QVariant> 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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue