swift
Loading...
Searching...
No Matches
logcategorylist.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QDBusMetaType>
7#include <QList>
8#include <QMetaObject>
9
10#include "misc/containerbase.h"
11#include "misc/iterator.h"
12#include "misc/range.h"
13
14struct QMetaObject;
15
16SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc, CLogCategory, CLogCategoryList)
17
18namespace swift::misc
19{
20 void CLogCategoryList::appendCategoriesFromMetaObject(const QMetaObject &metaObject, const QMetaObject &super)
21 {
22 for (auto *meta = &metaObject; meta != &super; meta = meta->superClass())
23 {
24 push_back(meta->className());
25 }
26 }
27
29 {
30 return transform([](const CLogCategory &cat) { return cat.toQString(); });
31 }
32
33 QString CLogCategoryList::toQString(bool i18n) const { return convertToQString(i18n); }
34
36 {
37 Q_UNUSED(i18n); // log categories are always Latin-1
38 return toQStringList().join("|");
39 }
40
42 {
44 [](const QString &str) { return CLogCategory { str }; }),
45 stringList.end());
46 }
47
49 {
50 return fromQStringList(string.split("|", Qt::SkipEmptyParts));
51 }
52
53 bool CLogCategoryList::anyStartWith(const QString &prefix) const
54 {
55 return containsBy([=](const CLogCategory &cat) { return cat.startsWith(prefix); });
56 }
57
58 bool CLogCategoryList::anyEndWith(const QString &suffix) const
59 {
60 return containsBy([=](const CLogCategory &cat) { return cat.endsWith(suffix); });
61 }
62
64 {
65 qRegisterMetaType<CLogCategoryList>();
66 qDBusRegisterMetaType<CLogCategoryList>();
68 }
69} // namespace swift::misc
A log category is an arbitrary string tag which can be attached to log messages.
Definition logcategory.h:28
bool startsWith(const QString &prefix) const
Returns true if the category string starts with the given prefix.
Definition logcategory.h:40
bool endsWith(const QString &suffix) const
Returns true if the category string ends with the given suffix.
Definition logcategory.h:43
bool anyEndWith(const QString &suffix) const
Returns true if any of the categories in the list end with the given suffix.
static CLogCategoryList fromQString(const QString &string)
Convert a string, such as that returned by toQString(), into a CLogCategoryList.
static void registerMetadata()
Register metadata.
CLogCategoryList()=default
Empty constructor.
QString toQString(bool i18n=false) const
Cast as QString.
QString convertToQString(bool i18n=false) const
Cast as QString.
static CLogCategoryList fromQStringList(const QStringList &stringList)
Convert a string list, such as that returned by toQStringList(), into a CLogCategoryList.
bool anyStartWith(const QString &prefix) const
Returns true if any of the categories in the list start with the given prefix.
QStringList toQStringList() const
Convert each of the categories to a QString and return the result as a QStringList.
void push_back(const CLogCategory &value)
Definition sequence.h:308
iterator end()
Returns iterator one past the end of the sequence.
Definition sequence.h:172
QString toQString(bool i18n=false) const
Cast as QString.
Definition mixinstring.h:74
auto makeTransformIterator(I iterator, F function) -> TransformIterator< I, F >
Construct a TransformIterator of the appropriate type from deduced template function arguments.
Definition iterator.h:353
Free functions in swift::misc.
auto makeRange(I begin, I2 end) -> CRange< I >
Returns a CRange constructed from begin and end iterators of deduced types.
Definition range.h:328
void registerMetaValueType()
This registers the value type T with the swift::misc:: meta type system, making it available for use ...
Definition variant.h:46
QList< T >::iterator begin()
const QMetaObject * superClass() const const
QString join(QChar separator) const const
SkipEmptyParts
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition sequence.h:63