mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 13:36:48 +08:00
refs #452, status messages
* DB support * finders and convenience methods
This commit is contained in:
committed by
Mathew Sutcliffe
parent
5587c06d37
commit
b5477c7c94
@@ -18,10 +18,6 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
CStatusMessage::CStatusMessage(const QString &message)
|
||||
: m_message(message)
|
||||
{}
|
||||
@@ -58,9 +54,6 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Conversion
|
||||
*/
|
||||
void CStatusMessage::toQtLogTriple(QtMsgType *o_type, QString *o_category, QString *o_message) const
|
||||
{
|
||||
auto category = m_categories.toQString();
|
||||
@@ -107,6 +100,7 @@ namespace BlackMisc
|
||||
|
||||
QString CStatusMessage::getHumanReadableCategory() const
|
||||
{
|
||||
//! \todo This should me not hardcoded
|
||||
if (this->m_humanReadableCategory.isEmpty())
|
||||
{
|
||||
const QString cat(this->m_categories.toQString().toLower());
|
||||
@@ -133,9 +127,6 @@ namespace BlackMisc
|
||||
return this->m_humanReadableCategory;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handled by
|
||||
*/
|
||||
void CStatusMessage::markAsHandledBy(const QObject *object) const
|
||||
{
|
||||
this->m_handledByObjects.push_back(quintptr(object));
|
||||
@@ -145,9 +136,6 @@ namespace BlackMisc
|
||||
return this->m_handledByObjects.contains(quintptr(object));
|
||||
}
|
||||
|
||||
/*
|
||||
* To string
|
||||
*/
|
||||
QString CStatusMessage::convertToQString(bool /** i18n */) const
|
||||
{
|
||||
|
||||
@@ -164,12 +152,14 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Pixmap
|
||||
*/
|
||||
const CIcon &CStatusMessage::convertToIcon(const CStatusMessage &statusMessage)
|
||||
{
|
||||
switch (statusMessage.getSeverity())
|
||||
return convertToIcon(statusMessage.getSeverity());
|
||||
}
|
||||
|
||||
const CIcon &CStatusMessage::convertToIcon(CStatusMessage::StatusSeverity severity)
|
||||
{
|
||||
switch (severity)
|
||||
{
|
||||
case SeverityDebug: return CIconList::iconByIndex(CIcons::StandardIconUnknown16); // TODO
|
||||
case SeverityInfo: return CIconList::iconByIndex(CIcons::StandardIconInfo16);
|
||||
@@ -179,9 +169,20 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Severity
|
||||
*/
|
||||
CStatusMessage CStatusMessage::fromDatabaseJson(const QJsonObject &json)
|
||||
{
|
||||
CLogCategory cat("swift.db");
|
||||
QString msgText(json.value("text").toString());
|
||||
QString severityText(json.value("severity").toString());
|
||||
QString typeText(json.value("type").toString());
|
||||
StatusSeverity severity = stringToSeverity(severityText);
|
||||
|
||||
typeText = "swift.db.type." + typeText.toLower().remove(' ');
|
||||
|
||||
CStatusMessage m({ cat, CLogCategory(typeText)}, severity, msgText);
|
||||
return m;
|
||||
}
|
||||
|
||||
CStatusMessage::StatusSeverity CStatusMessage::stringToSeverity(const QString &severity)
|
||||
{
|
||||
// pre-check
|
||||
@@ -204,9 +205,6 @@ namespace BlackMisc
|
||||
return SeverityInfo;
|
||||
}
|
||||
|
||||
/*
|
||||
* Severity
|
||||
*/
|
||||
const QString &CStatusMessage::severityToString(CStatusMessage::StatusSeverity severity)
|
||||
{
|
||||
switch (severity)
|
||||
@@ -238,26 +236,17 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Severity
|
||||
*/
|
||||
const QString &CStatusMessage::getSeverityAsString() const
|
||||
{
|
||||
return severityToString(this->m_severity);
|
||||
}
|
||||
|
||||
/*
|
||||
* Severity
|
||||
*/
|
||||
const QStringList &CStatusMessage::allSeverityStrings()
|
||||
{
|
||||
static const QStringList all { severityToString(SeverityDebug), severityToString(SeverityInfo), severityToString(SeverityWarning), severityToString(SeverityError) };
|
||||
return all;
|
||||
}
|
||||
|
||||
/*
|
||||
* Property by index
|
||||
*/
|
||||
CVariant CStatusMessage::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
@@ -280,9 +269,6 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set property as index
|
||||
*/
|
||||
void CStatusMessage::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CStatusMessage>(); return; }
|
||||
@@ -305,9 +291,6 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Message as HTML
|
||||
*/
|
||||
QString CStatusMessage::toHtml() const
|
||||
{
|
||||
QString html;
|
||||
|
||||
@@ -147,11 +147,17 @@ namespace BlackMisc
|
||||
//! To HTML
|
||||
QString toHtml() const;
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Representing icon
|
||||
static const CIcon &convertToIcon(const CStatusMessage &statusMessage);
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
//! Representing icon
|
||||
static const CIcon &convertToIcon(CStatusMessage::StatusSeverity severity);
|
||||
|
||||
//! Object from JSON
|
||||
static CStatusMessage fromDatabaseJson(const QJsonObject &json);
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CStatusMessage)
|
||||
|
||||
@@ -12,32 +12,35 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*
|
||||
* Construct from base class object
|
||||
*/
|
||||
CStatusMessageList::CStatusMessageList(const CSequence<CStatusMessage> &other) :
|
||||
CSequence<CStatusMessage>(other)
|
||||
{ }
|
||||
|
||||
/*
|
||||
* Messages by type
|
||||
*/
|
||||
CStatusMessageList CStatusMessageList::findByCategory(const CLogCategory &category) const
|
||||
{
|
||||
return this->findBy([ & ](const CStatusMessage &msg) { return msg.getCategories().contains(category); });
|
||||
return this->findBy([ & ](const CStatusMessage & msg) { return msg.getCategories().contains(category); });
|
||||
}
|
||||
|
||||
/*
|
||||
* Messages by severity
|
||||
*/
|
||||
CStatusMessageList CStatusMessageList::findBySeverity(CStatusMessage::StatusSeverity severity) const
|
||||
{
|
||||
return this->findBy(&CStatusMessage::getSeverity, severity);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add category
|
||||
*/
|
||||
bool CStatusMessageList::hasErrorMessages() const
|
||||
{
|
||||
return findBySeverity(CStatusMessage::SeverityError).size() > 0;
|
||||
}
|
||||
|
||||
bool CStatusMessageList::hasWarningMessages() const
|
||||
{
|
||||
return findBySeverity(CStatusMessage::SeverityWarning).size() > 0;
|
||||
}
|
||||
|
||||
bool CStatusMessageList::hasWarningOrErrorMessages() const
|
||||
{
|
||||
return hasErrorMessages() || hasWarningMessages();
|
||||
}
|
||||
|
||||
void CStatusMessageList::addCategory(const CLogCategory &category)
|
||||
{
|
||||
for (auto &msg : *this)
|
||||
@@ -46,9 +49,6 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add categories
|
||||
*/
|
||||
void CStatusMessageList::addCategories(const CLogCategoryList &categories)
|
||||
{
|
||||
for (auto &msg : *this)
|
||||
@@ -56,4 +56,14 @@ namespace BlackMisc
|
||||
msg.addCategories(categories);
|
||||
}
|
||||
}
|
||||
|
||||
CStatusMessageList CStatusMessageList::fromDatabaseJson(const QJsonArray &array)
|
||||
{
|
||||
CStatusMessageList messages;
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
messages.push_back(CStatusMessage::fromDatabaseJson(value.toObject()));
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -43,12 +43,23 @@ namespace BlackMisc
|
||||
//! Find by severity
|
||||
CStatusMessageList findBySeverity(CStatusMessage::StatusSeverity severity) const;
|
||||
|
||||
//! Error messages
|
||||
bool hasErrorMessages() const;
|
||||
|
||||
//! Warning messages
|
||||
bool hasWarningMessages() const;
|
||||
|
||||
//! Warning or error messages
|
||||
bool hasWarningOrErrorMessages() const;
|
||||
|
||||
//! Add a category to all messages in the list
|
||||
void addCategory(const CLogCategory &category);
|
||||
|
||||
//! Add some categories to all messages in the list
|
||||
void addCategories(const CLogCategoryList &categories);
|
||||
|
||||
//! From our database JSON format
|
||||
static CStatusMessageList fromDatabaseJson(const QJsonArray &array);
|
||||
};
|
||||
} // ns
|
||||
|
||||
|
||||
Reference in New Issue
Block a user