| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #ifndef QQMLJSLOGGINGUTILS_P_H |
| 5 | #define QQMLJSLOGGINGUTILS_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qstring.h> |
| 19 | #include <qtqmlcompilerexports.h> |
| 20 | |
| 21 | #include "qqmljsloggingutils.h" |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | class QQmlToolingSettings; |
| 26 | class QCommandLineParser; |
| 27 | |
| 28 | namespace QQmlJS { |
| 29 | |
| 30 | using LoggerWarningId = QQmlSA::LoggerWarningId; |
| 31 | |
| 32 | class LoggerCategoryPrivate; |
| 33 | |
| 34 | class Q_QMLCOMPILER_EXPORT LoggerCategory |
| 35 | { |
| 36 | Q_DECLARE_PRIVATE(LoggerCategory) |
| 37 | |
| 38 | public: |
| 39 | LoggerCategory(); |
| 40 | LoggerCategory(QString name, QString settingsName, QString description, QtMsgType level, |
| 41 | bool ignored = false, bool isDefault = false); |
| 42 | LoggerCategory(const LoggerCategory &); |
| 43 | LoggerCategory(LoggerCategory &&) noexcept; |
| 44 | LoggerCategory &operator=(const LoggerCategory &); |
| 45 | LoggerCategory &operator=(LoggerCategory &&) noexcept; |
| 46 | ~LoggerCategory(); |
| 47 | |
| 48 | QString name() const; |
| 49 | QString settingsName() const; |
| 50 | QString description() const; |
| 51 | QtMsgType level() const; |
| 52 | bool isIgnored() const; |
| 53 | bool isDefault() const; |
| 54 | |
| 55 | LoggerWarningId id() const; |
| 56 | |
| 57 | void setLevel(QtMsgType); |
| 58 | void setIgnored(bool); |
| 59 | |
| 60 | private: |
| 61 | std::unique_ptr<QQmlJS::LoggerCategoryPrivate> d_ptr; |
| 62 | }; |
| 63 | |
| 64 | class LoggerCategoryPrivate |
| 65 | { |
| 66 | friend class QT_PREPEND_NAMESPACE(QQmlJS::LoggerCategory); |
| 67 | |
| 68 | public: |
| 69 | LoggerWarningId id() const { return LoggerWarningId(m_name); } |
| 70 | |
| 71 | void setLevel(QtMsgType); |
| 72 | void setIgnored(bool); |
| 73 | |
| 74 | QString name() const; |
| 75 | QString settingsName() const; |
| 76 | QString description() const; |
| 77 | QtMsgType level() const; |
| 78 | bool isIgnored() const; |
| 79 | bool isDefault() const; |
| 80 | bool hasChanged() const; |
| 81 | |
| 82 | static LoggerCategoryPrivate *get(LoggerCategory *); |
| 83 | |
| 84 | friend bool operator==(const LoggerCategoryPrivate &lhs, const LoggerCategoryPrivate &rhs) |
| 85 | { |
| 86 | return operatorEqualsImpl(lhs, rhs); |
| 87 | } |
| 88 | friend bool operator!=(const LoggerCategoryPrivate &lhs, const LoggerCategoryPrivate &rhs) |
| 89 | { |
| 90 | return !operatorEqualsImpl(lhs, rhs); |
| 91 | } |
| 92 | |
| 93 | bool operator==(const LoggerWarningId warningId) const { return warningId.name() == m_name; } |
| 94 | |
| 95 | private: |
| 96 | static bool operatorEqualsImpl(const LoggerCategoryPrivate &, const LoggerCategoryPrivate &); |
| 97 | |
| 98 | QString m_name; |
| 99 | QString m_settingsName; |
| 100 | QString m_description; |
| 101 | QtMsgType m_level = QtDebugMsg; |
| 102 | bool m_ignored = false; |
| 103 | bool m_isDefault = false; // Whether or not the category can be disabled |
| 104 | bool m_changed = false; |
| 105 | }; |
| 106 | |
| 107 | namespace LoggingUtils { |
| 108 | Q_QMLCOMPILER_EXPORT void updateLogLevels(QList<LoggerCategory> &categories, |
| 109 | const QQmlToolingSettings &settings, |
| 110 | QCommandLineParser *parser); |
| 111 | |
| 112 | Q_QMLCOMPILER_EXPORT QString levelToString(const QQmlJS::LoggerCategory &category); |
| 113 | Q_QMLCOMPILER_EXPORT bool applyLevelToCategory(const QStringView level, LoggerCategory &category); |
| 114 | } // namespace LoggingUtils |
| 115 | |
| 116 | } // namespace QQmlJS |
| 117 | |
| 118 | QT_END_NAMESPACE |
| 119 | |
| 120 | #endif // QQMLJSLOGGINGUTILS_P_H |
| 121 | |