diff --git a/src/blackmisc/logpattern.cpp b/src/blackmisc/logpattern.cpp index 0caa53736..48c1fc345 100644 --- a/src/blackmisc/logpattern.cpp +++ b/src/blackmisc/logpattern.cpp @@ -12,6 +12,35 @@ namespace BlackMisc { + const QHash &CLogPattern::allHumanReadablePatterns() + { + static const QHash patterns + { + { "uncategorized (swift)", exactMatch(CLogCategory::uncategorized()) }, + { "validation", exactMatch(CLogCategory::validation()) }, + { "swift contexts", exactMatch(CLogCategory::context()) }, + { "swift context slots", exactMatch(CLogCategory::contextSlot()) }, + { "swift GUI", exactMatch(CLogCategory::guiComponent()) }, + { "swift downloads", exactMatch(CLogCategory::download()) }, + { "Qt library", startsWith("qt.") }, + { "uncategorized (other)", empty() } + }; + return patterns; + } + + const QStringList &CLogPattern::allHumanReadableNames() + { + static const QStringList names = allHumanReadablePatterns().keys(); + return names; + } + + const CLogPattern &CLogPattern::fromHumanReadableName(const QString &name) + { + static const CLogPattern empty {}; + auto it = allHumanReadablePatterns().find(name); + return it == allHumanReadablePatterns().end() ? empty : *it; + } + CLogPattern::CLogPattern(Strategy strategy, const QSet &strings) : m_strategy(strategy), m_strings(strings) { diff --git a/src/blackmisc/logpattern.h b/src/blackmisc/logpattern.h index 8b2dd75a9..9c4f85979 100644 --- a/src/blackmisc/logpattern.h +++ b/src/blackmisc/logpattern.h @@ -34,6 +34,12 @@ namespace BlackMisc public Mixin::Icon { public: + //! Get a list of human-readable names of predefined log patterns. + static const QStringList &allHumanReadableNames(); + + //! Return a predefined CLogPattern corresponding to the given human-readable name. + static const CLogPattern &fromHumanReadableName(const QString &name); + //! Default constructed CLogPattern will match any message. CLogPattern(); @@ -121,6 +127,8 @@ namespace BlackMisc const QString &getPrefix() const { Q_ASSERT(m_strategy == StartsWith && m_strings.size() == 1); return *m_strings.begin(); } const QString &getSuffix() const { Q_ASSERT(m_strategy == EndsWith && m_strings.size() == 1); return *m_strings.begin(); } const QString &getSubstring() const { Q_ASSERT(m_strategy == Contains && m_strings.size() == 1); return *m_strings.begin(); } + + static const QHash &allHumanReadablePatterns(); }; }