refs #526, category/statusmessage

* new categories
* utility functions in status message
This commit is contained in:
Klaus Basan
2016-01-02 20:42:06 +01:00
parent 4e0e2cddf8
commit 6fc39fb2d5
5 changed files with 44 additions and 7 deletions

View File

@@ -71,13 +71,27 @@ namespace BlackMisc
return cat;
}
//! Downloading
//! Generic downloads
static const CLogCategory &download()
{
static const CLogCategory cat { "swift.download" };
return cat;
}
//! Webservice
static const CLogCategory &webservice()
{
static const CLogCategory cat { "swift.webservice" };
return cat;
}
//! Webservice with swift DB
static const CLogCategory &swiftDbWebservice()
{
static const CLogCategory cat { "swift.db.webservice" };
return cat;
}
//! All predefined special categories
//! \note Human readable patterns are defined in CLogPattern::allHumanReadablePatterns
static const QList<CLogCategory> &allSpecialCategories()
@@ -89,7 +103,9 @@ namespace BlackMisc
context(),
contextSlot(),
guiComponent(),
download()
download(),
webservice(),
swiftDbWebservice(),
};
return cats;
}

View File

@@ -22,7 +22,9 @@ namespace BlackMisc
{ "swift contexts", exactMatch(CLogCategory::context()) },
{ "swift context slots", exactMatch(CLogCategory::contextSlot()) },
{ "swift GUI", exactMatch(CLogCategory::guiComponent()) },
{ "swift downloads", exactMatch(CLogCategory::download()) },
{ "downloading data", exactMatch(CLogCategory::download()) },
{ "webservice related", exactMatch(CLogCategory::webservice()) },
{ "swift DB webservice related", exactMatch(CLogCategory::swiftDbWebservice()) },
{ "Qt library", startsWith("qt.") },
{ "uncategorized (other)", empty() }
};

View File

@@ -187,15 +187,13 @@ namespace BlackMisc
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);
CStatusMessage m({ CLogCategory::swiftDbWebservice(), CLogCategory(typeText)}, severity, msgText);
return m;
}

View File

@@ -73,8 +73,23 @@ namespace BlackMisc
{
msg.setCategories(categories);
}
}
void CStatusMessageList::removeWarningsAndBelow()
{
if (this->isEmpty()) { return; }
this->removeIf(&CStatusMessage::getSeverity, CStatusMessage::SeverityWarning);
this->removeInfoAndBelow();
}
CStatusMessage::StatusSeverity CStatusMessageList::worstSeverity() const
void CStatusMessageList::removeInfoAndBelow()
{
if (this->isEmpty()) { return; }
this->removeIf(&CStatusMessage::getSeverity, CStatusMessage::SeverityDebug);
this->removeIf(&CStatusMessage::getSeverity, CStatusMessage::SeverityInfo);
}
CStatusMessage::StatusSeverity CStatusMessageList::worstSeverity() const
{
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityDebug;
for (const CStatusMessage &msg : *this)

View File

@@ -64,6 +64,12 @@ namespace BlackMisc
//! Reset the categories of all messages in the list
void setCategories(const CLogCategoryList &categories);
//! Remove warnings and below
void removeWarningsAndBelow();
//! Remove info and below
void removeInfoAndBelow();
//! Find worst severity
CStatusMessage::StatusSeverity worstSeverity() const;