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

View File

@@ -22,7 +22,9 @@ namespace BlackMisc
{ "swift contexts", exactMatch(CLogCategory::context()) }, { "swift contexts", exactMatch(CLogCategory::context()) },
{ "swift context slots", exactMatch(CLogCategory::contextSlot()) }, { "swift context slots", exactMatch(CLogCategory::contextSlot()) },
{ "swift GUI", exactMatch(CLogCategory::guiComponent()) }, { "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.") }, { "Qt library", startsWith("qt.") },
{ "uncategorized (other)", empty() } { "uncategorized (other)", empty() }
}; };

View File

@@ -187,15 +187,13 @@ namespace BlackMisc
CStatusMessage CStatusMessage::fromDatabaseJson(const QJsonObject &json) CStatusMessage CStatusMessage::fromDatabaseJson(const QJsonObject &json)
{ {
CLogCategory cat("swift.db");
QString msgText(json.value("text").toString()); QString msgText(json.value("text").toString());
QString severityText(json.value("severity").toString()); QString severityText(json.value("severity").toString());
QString typeText(json.value("type").toString()); QString typeText(json.value("type").toString());
StatusSeverity severity = stringToSeverity(severityText); StatusSeverity severity = stringToSeverity(severityText);
typeText = "swift.db.type." + typeText.toLower().remove(' '); typeText = "swift.db.type." + typeText.toLower().remove(' ');
CStatusMessage m({ CLogCategory::swiftDbWebservice(), CLogCategory(typeText)}, severity, msgText);
CStatusMessage m({ cat, CLogCategory(typeText)}, severity, msgText);
return m; return m;
} }

View File

@@ -73,6 +73,21 @@ namespace BlackMisc
{ {
msg.setCategories(categories); msg.setCategories(categories);
} }
}
void CStatusMessageList::removeWarningsAndBelow()
{
if (this->isEmpty()) { return; }
this->removeIf(&CStatusMessage::getSeverity, CStatusMessage::SeverityWarning);
this->removeInfoAndBelow();
}
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 CStatusMessageList::worstSeverity() const
{ {

View File

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