mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +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
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
|
||||||
* Constructors
|
|
||||||
*/
|
|
||||||
CStatusMessage::CStatusMessage(const QString &message)
|
CStatusMessage::CStatusMessage(const QString &message)
|
||||||
: m_message(message)
|
: m_message(message)
|
||||||
{}
|
{}
|
||||||
@@ -58,9 +54,6 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Conversion
|
|
||||||
*/
|
|
||||||
void CStatusMessage::toQtLogTriple(QtMsgType *o_type, QString *o_category, QString *o_message) const
|
void CStatusMessage::toQtLogTriple(QtMsgType *o_type, QString *o_category, QString *o_message) const
|
||||||
{
|
{
|
||||||
auto category = m_categories.toQString();
|
auto category = m_categories.toQString();
|
||||||
@@ -107,6 +100,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QString CStatusMessage::getHumanReadableCategory() const
|
QString CStatusMessage::getHumanReadableCategory() const
|
||||||
{
|
{
|
||||||
|
//! \todo This should me not hardcoded
|
||||||
if (this->m_humanReadableCategory.isEmpty())
|
if (this->m_humanReadableCategory.isEmpty())
|
||||||
{
|
{
|
||||||
const QString cat(this->m_categories.toQString().toLower());
|
const QString cat(this->m_categories.toQString().toLower());
|
||||||
@@ -133,9 +127,6 @@ namespace BlackMisc
|
|||||||
return this->m_humanReadableCategory;
|
return this->m_humanReadableCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Handled by
|
|
||||||
*/
|
|
||||||
void CStatusMessage::markAsHandledBy(const QObject *object) const
|
void CStatusMessage::markAsHandledBy(const QObject *object) const
|
||||||
{
|
{
|
||||||
this->m_handledByObjects.push_back(quintptr(object));
|
this->m_handledByObjects.push_back(quintptr(object));
|
||||||
@@ -145,9 +136,6 @@ namespace BlackMisc
|
|||||||
return this->m_handledByObjects.contains(quintptr(object));
|
return this->m_handledByObjects.contains(quintptr(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* To string
|
|
||||||
*/
|
|
||||||
QString CStatusMessage::convertToQString(bool /** i18n */) const
|
QString CStatusMessage::convertToQString(bool /** i18n */) const
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -164,12 +152,14 @@ namespace BlackMisc
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Pixmap
|
|
||||||
*/
|
|
||||||
const CIcon &CStatusMessage::convertToIcon(const CStatusMessage &statusMessage)
|
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 SeverityDebug: return CIconList::iconByIndex(CIcons::StandardIconUnknown16); // TODO
|
||||||
case SeverityInfo: return CIconList::iconByIndex(CIcons::StandardIconInfo16);
|
case SeverityInfo: return CIconList::iconByIndex(CIcons::StandardIconInfo16);
|
||||||
@@ -179,9 +169,20 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
CStatusMessage CStatusMessage::fromDatabaseJson(const QJsonObject &json)
|
||||||
* Severity
|
{
|
||||||
*/
|
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)
|
CStatusMessage::StatusSeverity CStatusMessage::stringToSeverity(const QString &severity)
|
||||||
{
|
{
|
||||||
// pre-check
|
// pre-check
|
||||||
@@ -204,9 +205,6 @@ namespace BlackMisc
|
|||||||
return SeverityInfo;
|
return SeverityInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Severity
|
|
||||||
*/
|
|
||||||
const QString &CStatusMessage::severityToString(CStatusMessage::StatusSeverity severity)
|
const QString &CStatusMessage::severityToString(CStatusMessage::StatusSeverity severity)
|
||||||
{
|
{
|
||||||
switch (severity)
|
switch (severity)
|
||||||
@@ -238,26 +236,17 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Severity
|
|
||||||
*/
|
|
||||||
const QString &CStatusMessage::getSeverityAsString() const
|
const QString &CStatusMessage::getSeverityAsString() const
|
||||||
{
|
{
|
||||||
return severityToString(this->m_severity);
|
return severityToString(this->m_severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Severity
|
|
||||||
*/
|
|
||||||
const QStringList &CStatusMessage::allSeverityStrings()
|
const QStringList &CStatusMessage::allSeverityStrings()
|
||||||
{
|
{
|
||||||
static const QStringList all { severityToString(SeverityDebug), severityToString(SeverityInfo), severityToString(SeverityWarning), severityToString(SeverityError) };
|
static const QStringList all { severityToString(SeverityDebug), severityToString(SeverityInfo), severityToString(SeverityWarning), severityToString(SeverityError) };
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Property by index
|
|
||||||
*/
|
|
||||||
CVariant CStatusMessage::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
CVariant CStatusMessage::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||||
{
|
{
|
||||||
if (index.isMyself()) { return CVariant::from(*this); }
|
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)
|
void CStatusMessage::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||||
{
|
{
|
||||||
if (index.isMyself()) { (*this) = variant.to<CStatusMessage>(); return; }
|
if (index.isMyself()) { (*this) = variant.to<CStatusMessage>(); return; }
|
||||||
@@ -305,9 +291,6 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Message as HTML
|
|
||||||
*/
|
|
||||||
QString CStatusMessage::toHtml() const
|
QString CStatusMessage::toHtml() const
|
||||||
{
|
{
|
||||||
QString html;
|
QString html;
|
||||||
|
|||||||
@@ -147,11 +147,17 @@ namespace BlackMisc
|
|||||||
//! To HTML
|
//! To HTML
|
||||||
QString toHtml() const;
|
QString toHtml() const;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::convertToQString
|
||||||
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
//! Representing icon
|
//! Representing icon
|
||||||
static const CIcon &convertToIcon(const CStatusMessage &statusMessage);
|
static const CIcon &convertToIcon(const CStatusMessage &statusMessage);
|
||||||
|
|
||||||
//! \copydoc CValueObject::convertToQString
|
//! Representing icon
|
||||||
QString convertToQString(bool i18n = false) const;
|
static const CIcon &convertToIcon(CStatusMessage::StatusSeverity severity);
|
||||||
|
|
||||||
|
//! Object from JSON
|
||||||
|
static CStatusMessage fromDatabaseJson(const QJsonObject &json);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BLACK_ENABLE_TUPLE_CONVERSION(CStatusMessage)
|
BLACK_ENABLE_TUPLE_CONVERSION(CStatusMessage)
|
||||||
|
|||||||
@@ -12,32 +12,35 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* Construct from base class object
|
|
||||||
*/
|
|
||||||
CStatusMessageList::CStatusMessageList(const CSequence<CStatusMessage> &other) :
|
CStatusMessageList::CStatusMessageList(const CSequence<CStatusMessage> &other) :
|
||||||
CSequence<CStatusMessage>(other)
|
CSequence<CStatusMessage>(other)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/*
|
|
||||||
* Messages by type
|
|
||||||
*/
|
|
||||||
CStatusMessageList CStatusMessageList::findByCategory(const CLogCategory &category) const
|
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
|
CStatusMessageList CStatusMessageList::findBySeverity(CStatusMessage::StatusSeverity severity) const
|
||||||
{
|
{
|
||||||
return this->findBy(&CStatusMessage::getSeverity, severity);
|
return this->findBy(&CStatusMessage::getSeverity, severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
bool CStatusMessageList::hasErrorMessages() const
|
||||||
* Add category
|
{
|
||||||
*/
|
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)
|
void CStatusMessageList::addCategory(const CLogCategory &category)
|
||||||
{
|
{
|
||||||
for (auto &msg : *this)
|
for (auto &msg : *this)
|
||||||
@@ -46,9 +49,6 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Add categories
|
|
||||||
*/
|
|
||||||
void CStatusMessageList::addCategories(const CLogCategoryList &categories)
|
void CStatusMessageList::addCategories(const CLogCategoryList &categories)
|
||||||
{
|
{
|
||||||
for (auto &msg : *this)
|
for (auto &msg : *this)
|
||||||
@@ -56,4 +56,14 @@ namespace BlackMisc
|
|||||||
msg.addCategories(categories);
|
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
|
} // ns
|
||||||
|
|||||||
@@ -43,12 +43,23 @@ namespace BlackMisc
|
|||||||
//! Find by severity
|
//! Find by severity
|
||||||
CStatusMessageList findBySeverity(CStatusMessage::StatusSeverity severity) const;
|
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
|
//! Add a category to all messages in the list
|
||||||
void addCategory(const CLogCategory &category);
|
void addCategory(const CLogCategory &category);
|
||||||
|
|
||||||
//! Add some categories to all messages in the list
|
//! Add some categories to all messages in the list
|
||||||
void addCategories(const CLogCategoryList &categories);
|
void addCategories(const CLogCategoryList &categories);
|
||||||
|
|
||||||
|
//! From our database JSON format
|
||||||
|
static CStatusMessageList fromDatabaseJson(const QJsonArray &array);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user