swift
Loading...
Searching...
No Matches
statusmessagefilter.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include "misc/logpattern.h"
7
8using namespace swift::misc;
9
10namespace swift::gui::models
11{
13 const QString &category)
14 : m_severity(severity), m_msgText(text.trimmed()), m_category(category.trimmed())
15 {
16 // info or debug are treated like no filter
17 this->m_valid = !((severity == CStatusMessage::SeverityInfo || severity == CStatusMessage::SeverityDebug) &&
18 m_msgText.isEmpty() && m_category.isEmpty());
19 }
20
22 {
23 if (!this->isValid())
24 {
25 return inContainer;
26 }
27 CStatusMessageList outContainer;
28 for (const CStatusMessage &msg : inContainer)
29 {
30 if (m_severity != CStatusMessage::SeverityInfo && m_severity != CStatusMessage::SeverityDebug)
31 {
32 if (!msg.isSeverityHigherOrEqual(this->m_severity))
33 {
34 continue;
35 }
36 }
37
38 if (!this->m_msgText.isEmpty())
39 {
40 if (!this->stringMatchesFilterExpression(msg.getMessage(), this->m_msgText))
41 {
42 continue;
43 }
44 }
45
46 if (!this->m_category.isEmpty())
47 {
49 this->m_category))
50 {
51 continue;
52 }
53 }
54
55 outContainer.push_back(msg);
56 }
57 return outContainer;
58 }
59
61 {
62 if (!m_category.contains('*'))
63 {
64 if (CLogPattern::allHumanReadableNames().contains(m_category))
65 {
67 CLogPattern::fromHumanReadableName(m_category).withSeverityAtOrAbove(m_severity));
68 }
69 return CVariant::fromValue(CLogPattern::exactMatch(m_category).withSeverityAtOrAbove(m_severity));
70 }
71
73 categories.removeIf([this](const CLogCategory &cat) {
74 return this->stringMatchesFilterExpression(cat.toQString(), this->m_category);
75 });
77 humanNames.removeIf(
78 [this](const QString &name) { return this->stringMatchesFilterExpression(name, this->m_category); });
79 auto humanCats = humanNames.transform([](const QString &name) {
80 const auto strings = CLogPattern::fromHumanReadableName(name).getCategoryStrings();
81 return strings.isEmpty() ? QString {} : *strings.begin();
82 });
83
84 return CVariant::fromValue(CLogPattern::anyOf(categories.join(humanCats)).withSeverityAtOrAbove(m_severity));
85 }
86} // namespace swift::gui::models
CStatusMessageFilter(swift::misc::CStatusMessage::StatusSeverity severity, const QString &text, const QString &category)
Constructor.
swift::misc::CVariant getAsValueObject() const
Return an implementation-specific value object representing the filter.
swift::misc::CStatusMessageList filter(const swift::misc::CStatusMessageList &inContainer) const
Used container data.
bool stringMatchesFilterExpression(const QString &value, const QString &filter, Qt::CaseSensitivity cs=Qt::CaseInsensitive) const
static const QStringList & allSpecialCategories()
All predefined special categories.
A log category is an arbitrary string tag which can be attached to log messages.
Definition logcategory.h:28
A sequence of log categories.
static CLogCategoryList fromQStringList(const QStringList &stringList)
Convert a string list, such as that returned by toQStringList(), into a CLogCategoryList.
QSet< QString > getCategoryStrings() const
Technical category names matched by this pattern.
Definition logpattern.h:104
static QStringList humanOrTechnicalCategoriesFrom(const CStatusMessage &message)
Human or machine readable categories of message.
static const CLogPattern & fromHumanReadableName(const QString &name)
Return a predefined CLogPattern corresponding to the given human-readable name.
static const QStringList & allHumanReadableNames()
Get a list of human-readable names of predefined log patterns.
static CLogPattern exactMatch(const CLogCategory &category)
Returns a CLogPattern which will match any message with the given category.
static CLogPattern anyOf(const CLogCategoryList &categories)
Returns a CLogPattern which will match any message with any of the given categories.
auto transform(F function) const
Return a new container generated by applying some transformation function to all elements of this one...
Definition range.h:415
Generic sequential container with value semantics.
Definition sequence.h:86
int removeIf(Predicate p)
Remove elements for which a given predicate returns true.
Definition sequence.h:458
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
CSequence join(const CSequence &other) const
Concatenates two sequences and returns the result.
Definition sequence.h:359
Streamable status message, e.g.
static constexpr auto SeverityInfo
Status severities.
swift::misc::StatusSeverity StatusSeverity
Status severities.
static constexpr auto SeverityDebug
Status severities.
Status messages, e.g. from Core -> GUI.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition variant.h:69
static CVariant fromValue(T &&value)
Construct a variant from a value.
Definition variant.h:139
QString toQString(bool i18n=false) const
Cast as QString.
Definition mixinstring.h:74
Models to be used with views, mainly QTableView.
Free functions in swift::misc.
bool isEmpty() const const
QString::iterator begin()