Merge branch 'severities'

This commit is contained in:
Kimmo Varis 2011-03-07 23:45:29 +02:00
commit 03bdd22ccf
9 changed files with 197 additions and 70 deletions

View File

@ -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;
}

View File

@ -18,6 +18,11 @@
#include "erroritem.h"
ErrorItem::ErrorItem()
: severity(Severity::none)
{
}
ErrorItem::ErrorItem(const ErrorItem &item)
{
file = item.file;
@ -42,7 +47,7 @@ ErrorItem::ErrorItem(const ErrorLine &line)
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++)

View File

@ -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.
*
@ -39,7 +97,7 @@ class ErrorLine;
class ErrorItem
{
public:
ErrorItem() { }
ErrorItem();
ErrorItem(const ErrorItem &item);
ErrorItem(const ErrorLine &line);
~ErrorItem() { }
@ -54,7 +112,7 @@ public:
QStringList files;
QList<unsigned int> lines;
QString id;
QString severity;
Severity::SeverityType severity;
QString summary;
QString message;
};
@ -70,7 +128,7 @@ public:
QString file;
unsigned int line;
QString id;
QString severity;
Severity::SeverityType severity;
QString summary;
QString message;
};

View File

@ -190,7 +190,8 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
// Ensure shown path is with native separators
const QString file = QDir::toNativeSeparators(item.file);
list << CreateNormalItem(file);
list << CreateNormalItem(tr(item.severity.toLatin1()));
const QString severity = GuiSeverity::toString(item.severity);
list << CreateNormalItem(severity.toLatin1());
list << CreateLineNumberItem(QString("%1").arg(item.line));
//TODO message has parameter names so we'll need changes to the core
//cppcheck so we can get proper translations
@ -251,24 +252,107 @@ ShowTypes ResultsTree::VariantToShowType(const QVariant &data)
return (ShowTypes)value;
}
ShowTypes ResultsTree::SeverityToShowType(const QString & severity)
ShowTypes ResultsTree::SeverityToShowType(Severity::SeverityType severity)
{
if (severity == "error")
switch (severity)
{
case Severity::none:
return SHOW_NONE;
case Severity::error:
return SHOW_ERRORS;
if (severity == "style")
case Severity::style:
return SHOW_STYLE;
if (severity == "warning")
case Severity::warning:
return SHOW_WARNINGS;
if (severity == "performance")
case Severity::performance:
return SHOW_PERFORMANCE;
if (severity == "portability")
case Severity::portability:
return SHOW_PORTABILITY;
if (severity == "information")
case Severity::information:
return SHOW_INFORMATION;
default:
return SHOW_NONE;
}
return SHOW_NONE;
}
Severity::SeverityType ResultsTree::ShowTypeToSeverity(ShowTypes type)
{
switch (type)
{
case SHOW_STYLE:
return Severity::style;
break;
case SHOW_ERRORS:
return Severity::error;
break;
case SHOW_WARNINGS:
return Severity::warning;
break;
case SHOW_PERFORMANCE:
return Severity::performance;
break;
case SHOW_PORTABILITY:
return Severity::portability;
break;
case SHOW_INFORMATION:
return Severity::information;
break;
case SHOW_NONE:
return Severity::none;
break;
}
return Severity::none;
}
QString ResultsTree::SeverityToTranslatedString(Severity::SeverityType severity)
{
switch (severity)
{
case Severity::style:
return tr("style");
break;
case Severity::error:
return tr("error");
break;
case Severity::warning:
return tr("warning");
break;
case Severity::performance:
return tr("performance");
break;
case Severity::portability:
return tr("portability");
break;
case Severity::information:
return tr("information");
break;
case Severity::debug:
return tr("debug");
break;
case Severity::none:
return "";
break;
}
return "";
}
QStandardItem *ResultsTree::FindFileItem(const QString &name)
{
QList<QStandardItem *> list = mModel.findItems(name);
@ -735,21 +819,25 @@ void ResultsTree::CopyPath(QStandardItem *target, bool fullPath)
}
}
QString ResultsTree::SeverityToIcon(const QString &severity) const
QString ResultsTree::SeverityToIcon(Severity::SeverityType severity) const
{
if (severity == "error")
switch (severity)
{
case Severity::error:
return ":images/dialog-error.png";
if (severity == "style")
case Severity::style:
return ":images/applications-development.png";
if (severity == "warning")
case Severity::warning:
return ":images/dialog-warning.png";
if (severity == "portability")
case Severity::portability:
return ":images/applications-system.png";
if (severity == "performance")
case Severity::performance:
return ":images/utilities-system-monitor.png";
if (severity == "information")
case Severity::information:
return ":images/dialog-information.png";
default:
return "";
}
return "";
}
@ -794,7 +882,7 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
QVariantMap data = userdata.toMap();
ErrorItem item;
item.severity = ShowTypeToString(VariantToShowType(data["severity"]));
item.severity = ShowTypeToSeverity(VariantToShowType(data["severity"]));
item.summary = data["summary"].toString();
item.message = data["message"].toString();
item.id = data["id"].toString();
@ -823,42 +911,6 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
}
}
QString ResultsTree::ShowTypeToString(ShowTypes type)
{
switch (type)
{
case SHOW_STYLE:
return tr("style");
break;
case SHOW_ERRORS:
return tr("error");
break;
case SHOW_WARNINGS:
return tr("warning");
break;
case SHOW_PERFORMANCE:
return tr("performance");
break;
case SHOW_PORTABILITY:
return tr("portability");
break;
case SHOW_INFORMATION:
return tr("information");
break;
case SHOW_NONE:
return "";
break;
}
return "";
}
void ResultsTree::UpdateSettings(bool showFullPath,
bool saveFullPath,
bool saveAllErrors)

View File

@ -28,6 +28,7 @@
#include <QTextStream>
#include "common.h"
#include "applicationlist.h"
#include "errorlogger.h" // Severity
class Report;
class ErrorItem;
@ -128,10 +129,10 @@ public:
/**
* @brief Convert severity string to ShowTypes value
* @param severity Error severity string
* @param severity Error severity
* @return Severity converted to ShowTypes value
*/
static ShowTypes SeverityToShowType(const QString &severity);
static ShowTypes SeverityToShowType(Severity::SeverityType severity);
signals:
/**
@ -230,9 +231,9 @@ protected:
/**
* @brief Convert a severity string to a icon filename
*
* @param severity Severity string
* @param severity Severity
*/
QString SeverityToIcon(const QString &severity) const;
QString SeverityToIcon(Severity::SeverityType severity) const;
/**
* @brief Helper function to open an error within target with application*
@ -291,9 +292,16 @@ protected:
/**
* @brief Convert ShowType to severity string
* @param type ShowType to convert
* @return ShowType converted to string
* @return ShowType converted to severity
*/
QString ShowTypeToString(ShowTypes type);
Severity::SeverityType ShowTypeToSeverity(ShowTypes type);
/**
* @brief Convert Severity to translated string for GUI.
* @param type Severity to convert
* @return Severity as translated string
*/
QString SeverityToTranslatedString(Severity::SeverityType severity);
/**
* @brief Load all settings

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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();