refs #702, CStatusMessageList toHTML

This commit is contained in:
Klaus Basan
2016-07-06 00:41:45 +02:00
parent b848cf6e23
commit 05fdf06660
2 changed files with 41 additions and 0 deletions

View File

@@ -163,6 +163,41 @@ namespace BlackMisc
return newMsg;
}
QString CStatusMessageList::toHtml(const CPropertyIndexList &indexes) const
{
if (indexes.isEmpty() || this->isEmpty()) { return ""; }
QString html;
for (const CStatusMessage &statusMessage : *this)
{
QString rowHtml;
for (const CPropertyIndex index : indexes)
{
rowHtml += "<td>" + statusMessage.propertyByIndex(index).toQString(true) + "</td>";
}
rowHtml = "<tr class=\"%1\">" + rowHtml + "</tr>";
const QString severityClass = statusMessage.getSeverityAsString();
html += rowHtml.arg(severityClass);
}
return "<table>" + html + "</table>";
}
const QString htmlStyleSheetImpl()
{
QString style;
style += "." + CStatusMessage::severityToString(CStatusMessage::SeverityDebug) + " { color: lightgreen; } ";
style += "." + CStatusMessage::severityToString(CStatusMessage::SeverityInfo) + " { color: lightgreen; } ";
style += "." + CStatusMessage::severityToString(CStatusMessage::SeverityWarning) + " { color: yellow; } ";
style += "." + CStatusMessage::severityToString(CStatusMessage::SeverityError) + " { color: red; }";
return style; // "<style type=\"text/css\">" + style + "</style>";
}
const QString &CStatusMessageList::htmlStyleSheet()
{
static const QString style(htmlStyleSheetImpl());
return style;
}
CStatusMessageList CStatusMessageList::fromDatabaseJson(const QJsonArray &array)
{
CStatusMessageList messages;

View File

@@ -100,6 +100,12 @@ namespace BlackMisc
//! Merge into a single message
CStatusMessage toSingleMessage() const;
//! Specialized version to convert to HTML
QString toHtml(const CPropertyIndexList &indexes) const;
//! Default style sheet which can be used with CStatusMessageList::toHtml
static const QString &htmlStyleSheet();
//! From our database JSON format
static CStatusMessageList fromDatabaseJson(const QJsonArray &array);
};