mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #702, CStatusMessageList toHTML
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user