swift
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 
4 #include "misc/logcategorylist.h"
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 
14 struct QMetaObject;
15 
16 SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc, CLogCategory, CLogCategoryList)
17 
18 namespace swift::misc
19 {
20  void CLogCategoryList::appendCategoriesFromMetaObject(const QMetaObject &metaObject, const QMetaObject &super)
21  {
22  for (auto *meta = &metaObject; meta != &super; meta = meta->superClass()) { push_back(meta->className()); }
23  }
24 
25  QStringList CLogCategoryList::toQStringList() const
26  {
27  return transform([](const CLogCategory &cat) { return cat.toQString(); });
28  }
29 
30  QString CLogCategoryList::toQString(bool i18n) const { return convertToQString(i18n); }
31 
32  QString CLogCategoryList::convertToQString(bool i18n) const
33  {
34  Q_UNUSED(i18n); // log categories are always Latin-1
35  return toQStringList().join("|");
36  }
37 
38  CLogCategoryList CLogCategoryList::fromQStringList(const QStringList &stringList)
39  {
40  return makeRange(Iterators::makeTransformIterator(stringList.begin(),
41  [](const QString &str) { return CLogCategory { str }; }),
42  stringList.end());
43  }
44 
45  CLogCategoryList CLogCategoryList::fromQString(const QString &string)
46  {
47  return fromQStringList(string.split("|", Qt::SkipEmptyParts));
48  }
49 
50  bool CLogCategoryList::anyStartWith(const QString &prefix) const
51  {
52  return containsBy([=](const CLogCategory &cat) { return cat.startsWith(prefix); });
53  }
54 
55  bool CLogCategoryList::anyEndWith(const QString &suffix) const
56  {
57  return containsBy([=](const CLogCategory &cat) { return cat.endsWith(suffix); });
58  }
59 
60  void CLogCategoryList::registerMetadata()
61  {
62  qRegisterMetaType<CLogCategoryList>();
63  qDBusRegisterMetaType<CLogCategoryList>();
64  registerMetaValueType<CLogCategoryList>();
65  }
66 } // 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
A sequence of log categories.
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.
QStringList toQStringList() const
Convert each of the categories to a QString and return the result as a QStringList.
auto transform(F function) const
Return a new container generated by applying some transformation function to all elements of this one...
Definition: range.h:403
void push_back(const CLogCategory &value)
Appends an element at the end of the sequence.
Definition: sequence.h:305
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:76
auto makeTransformIterator(I iterator, F function) -> TransformIterator< I, F >
Construct a TransformIterator of the appropriate type from deduced template function arguments.
Definition: iterator.h:343
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:316
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition: sequence.h:63