From 05fdf06660831d1ef6990a2b193ba4f659df0239 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 6 Jul 2016 00:41:45 +0200 Subject: [PATCH] refs #702, CStatusMessageList toHTML --- src/blackmisc/statusmessagelist.cpp | 35 +++++++++++++++++++++++++++++ src/blackmisc/statusmessagelist.h | 6 +++++ 2 files changed, 41 insertions(+) diff --git a/src/blackmisc/statusmessagelist.cpp b/src/blackmisc/statusmessagelist.cpp index 63d76f55f..cef97467e 100644 --- a/src/blackmisc/statusmessagelist.cpp +++ b/src/blackmisc/statusmessagelist.cpp @@ -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 += "" + statusMessage.propertyByIndex(index).toQString(true) + ""; + } + + rowHtml = "" + rowHtml + ""; + const QString severityClass = statusMessage.getSeverityAsString(); + html += rowHtml.arg(severityClass); + } + return "" + html + "
"; + } + + 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; // ""; + } + + const QString &CStatusMessageList::htmlStyleSheet() + { + static const QString style(htmlStyleSheetImpl()); + return style; + } + CStatusMessageList CStatusMessageList::fromDatabaseJson(const QJsonArray &array) { CStatusMessageList messages; diff --git a/src/blackmisc/statusmessagelist.h b/src/blackmisc/statusmessagelist.h index 67adcd607..059546483 100644 --- a/src/blackmisc/statusmessagelist.h +++ b/src/blackmisc/statusmessagelist.h @@ -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); };