umbrello 26.03.70-1a62d36 Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

debug_utils.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2011 Andi Fischer <andi.fischer@hispeed.ch>
3 SPDX-FileCopyrightText: 2012 Ralf Habacker <ralf.habacker@freenet.de>
4 SPDX-FileCopyrightText: 2022 Oliver Kellogg <okellogg@users.sourceforge.net>
5
6 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
7*/
8
9#ifndef DEBUG_UTILS_H
10#define DEBUG_UTILS_H
11
12/*
13 This file shall only by #included by implementation files (.cpp),
14 not by header files (.h)
15*/
16
17#include <QtGlobal>
18
19#include <QLoggingCategory>
20Q_DECLARE_LOGGING_CATEGORY(UMBRELLO)
21#include <QMetaEnum>
22#include <QTreeWidget>
23
24 namespace Settings { class OptionState; }
25
59 class Tracer : public QTreeWidget
60{
61 Q_OBJECT
62 public:
63 static Tracer* instance();
64
65 ~Tracer();
66
67 bool isEnabled(const QString& name) const;
68 void enable(const QString& name);
69 void disable(const QString& name);
70
71 void enableAll();
72 void disableAll();
73
74 bool logToConsole();
75
76 static void registerClass(const char * name, bool state=true, const char *filePath = nullptr);
77 static void onSettingsChanged(const Settings::OptionState &state);
78
79 protected:
80 void update(const QString &name);
81 void updateAllItemCheckBox();
82 void updateParentItemCheckBox(QTreeWidgetItem *parent);
83 virtual void showEvent(QShowEvent*);
84 void restoreParentCheckState(QTreeWidgetItem *parent);
85
86 private Q_SLOTS:
87 void slotParentItemClicked(QTreeWidgetItem *parent);
88 void slotItemClicked(QTreeWidgetItem* item, int column);
89
90 private:
91 class MapEntry {
92 public:
93 QString filePath;
94 bool state;
95 MapEntry() : state(false) {}
96 MapEntry(const QString &_filePath, bool _state) : filePath(_filePath), state(_state) {}
97 };
98
99 typedef QMap<QString, MapEntry> MapType;
100 typedef QMap<QString,Qt::CheckState> StateMap;
101
102 static Tracer* s_instance;
103 static MapType* s_classes;
104 static StateMap* s_states;
105 static bool s_logToConsole;
106
107 explicit Tracer(QWidget *parent = nullptr);
108};
109
110// convenience macros for console output to the Umbrello area
111#define uDebug() qCDebug(UMBRELLO)
112#define uError() qCCritical(UMBRELLO)
113#define uWarning() qCWarning(UMBRELLO)
114
115#ifndef DBG_SRC
116#define DBG_SRC QString::fromLatin1(metaObject()->className())
117#endif
118#define DEBUG_SHOW_FILTER() Tracer::instance()->show()
119#define DEBUG_N(latin1str) if (Tracer::instance()->logToConsole() || Tracer::instance()->isEnabled(latin1str)) uDebug()
120#define DEBUG() DEBUG_N(DBG_SRC)
121#define IS_DEBUG_ENABLED() Tracer::instance()->isEnabled(DBG_SRC)
122#define DEBUG_REGISTER(src) \
123 class src##Tracer { \
124 public: \
125 src##Tracer() { Tracer::registerClass(#src, true, __FILE__); } \
126 }; \
127 static src##Tracer src##TracerGlobal;
128#define DEBUG_REGISTER_DISABLED(src) \
129 class src##Tracer { \
130 public: \
131 src##Tracer() { Tracer::registerClass(#src, false, __FILE__); } \
132 }; \
133 static src##Tracer src##TracerGlobal;
134
135#define uIgnoreZeroPointer(a) if (!a) { uDebug() << "zero pointer detected" << __FILE__ << __LINE__; continue; }
136
137
144#define ENUM_NAME(o, e, v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))
145
146 template <typename T>
147QString toString(const T& value);
148
149 template <typename T>
150QString toString(const T& value)
151{
152 QString s;
153 QDebug(&s) << value; // relies on Qt's QDebug operator<<
154 return s.trimmed();
155}
156
157#define logDebug0(s) if (UMLApp::app()->logToConsole() || Tracer::instance()->isEnabled(DBG_SRC)) \
158 UMLApp::app()->logDebug(QStringLiteral(s))
159#define logInfo0(s) UMLApp::app()->logInfo(QStringLiteral(s))
160#define logWarn0(s) UMLApp::app()->logWarn(QStringLiteral(s))
161#define logError0(s) UMLApp::app()->logError(QStringLiteral(s))
162
163#define logDebug1(s, a) if (UMLApp::app()->logToConsole() || Tracer::instance()->isEnabled(DBG_SRC)) \
164 do { QString fmt = QString(QStringLiteral(s)).arg(a); UMLApp::app()->logDebug(fmt); } while (0)
165#define logInfo1(s, a) do { QString fmt = QString(QStringLiteral(s)).arg(a); UMLApp::app()->logInfo(fmt); } while (0)
166#define logWarn1(s, a) do { QString fmt = QString(QStringLiteral(s)).arg(a); UMLApp::app()->logWarn(fmt); } while (0)
167#define logError1(s, a) do { QString fmt = QString(QStringLiteral(s)).arg(a); UMLApp::app()->logError(fmt); } while (0)
168
169#define logDebug2(s, a, b) if (UMLApp::app()->logToConsole() || Tracer::instance()->isEnabled(DBG_SRC)) \
170 do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b); UMLApp::app()->logDebug(fmt); } while (0)
171#define logInfo2(s, a, b) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b); UMLApp::app()->logInfo(fmt); } while (0)
172#define logWarn2(s, a, b) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b); UMLApp::app()->logWarn(fmt); } while (0)
173#define logError2(s, a, b) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b); UMLApp::app()->logError(fmt); } while (0)
174
175#define logDebug3(s, a, b, c) if (UMLApp::app()->logToConsole() || Tracer::instance()->isEnabled(DBG_SRC)) \
176 do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c); UMLApp::app()->logDebug(fmt); } while (0)
177#define logInfo3(s, a, b, c) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c); UMLApp::app()->logInfo(fmt); } while (0)
178#define logWarn3(s, a, b, c) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c); UMLApp::app()->logWarn(fmt); } while (0)
179#define logError3(s, a, b, c) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c); UMLApp::app()->logError(fmt); } while (0)
180
181#define logDebug4(s, a, b, c, d) if (UMLApp::app()->logToConsole() || Tracer::instance()->isEnabled(DBG_SRC)) \
182 do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d); UMLApp::app()->logDebug(fmt); } while (0)
183#define logInfo4(s, a, b, c, d) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d); UMLApp::app()->logInfo(fmt); } while (0)
184#define logWarn4(s, a, b, c, d) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d); UMLApp::app()->logWarn(fmt); } while (0)
185#define logError4(s, a, b, c, d) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d); UMLApp::app()->logError(fmt); } while (0)
186
187#define logDebug5(s, a, b, c, d, e) if (UMLApp::app()->logToConsole() || Tracer::instance()->isEnabled(DBG_SRC)) \
188 do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d).arg(e); \
189 UMLApp::app()->logDebug(fmt); } while (0)
190#define logInfo5(s, a, b, c, d, e) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d).arg(e); \
191 UMLApp::app()->logInfo(fmt); } while (0)
192#define logWarn5(s, a, b, c, d, e) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d).arg(e); \
193 UMLApp::app()->logWarn(fmt); } while (0)
194#define logError5(s, a, b, c, d, e) do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d).arg(e); \
195 UMLApp::app()->logError(fmt); } while (0)
196
197#define logDebug6(s, a, b, c, d, e, f) if (UMLApp::app()->logToConsole() || Tracer::instance()->isEnabled(DBG_SRC)) \
198 do { QString fmt = QString(QStringLiteral(s)).arg(a).arg(b).arg(c).arg(d).arg(e).arg(f); UMLApp::app()->logDebug(fmt); } while (0)
199
200#endif
Settings::OptionState
Definition: optionstate.h:314
Tracer::MapEntry
Definition: debug_utils.h:91
Tracer::MapEntry::MapEntry
MapEntry(const QString &_filePath, bool _state)
Definition: debug_utils.h:96
Tracer::MapEntry::filePath
QString filePath
Definition: debug_utils.h:93
Tracer::MapEntry::state
bool state
Definition: debug_utils.h:94
Tracer::MapEntry::MapEntry
MapEntry()
Definition: debug_utils.h:95
Tracer
The singleton class for switching on or off debug messages.
Definition: debug_utils.h:60
Tracer::restoreParentCheckState
void restoreParentCheckState(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:369
Tracer::s_logToConsole
static bool s_logToConsole
Definition: debug_utils.h:105
Tracer::disable
void disable(const QString &name)
Definition: debug_utils.cpp:202
Tracer::s_instance
static Tracer * s_instance
Definition: debug_utils.h:102
Tracer::disableAll
void disableAll()
Definition: debug_utils.cpp:226
Tracer::enableAll
void enableAll()
Definition: debug_utils.cpp:209
Tracer::slotParentItemClicked
void slotParentItemClicked(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:400
Tracer::StateMap
QMap< QString, Qt::CheckState > StateMap
Definition: debug_utils.h:100
Tracer::updateParentItemCheckBox
void updateParentItemCheckBox(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:311
Tracer::enable
void enable(const QString &name)
Definition: debug_utils.cpp:192
Tracer::~Tracer
~Tracer()
Definition: debug_utils.cpp:152
Tracer::logToConsole
bool logToConsole()
Definition: debug_utils.cpp:243
Tracer::instance
static Tracer * instance()
Definition: debug_utils.cpp:113
Tracer::updateAllItemCheckBox
void updateAllItemCheckBox()
Definition: debug_utils.cpp:284
Tracer::s_states
static StateMap * s_states
Definition: debug_utils.h:104
Tracer::update
void update(const QString &name)
Definition: debug_utils.cpp:274
Tracer::isEnabled
bool isEnabled(const QString &name) const
Definition: debug_utils.cpp:171
Tracer::s_classes
static MapType * s_classes
Definition: debug_utils.h:103
Tracer::onSettingsChanged
static void onSettingsChanged(const Settings::OptionState &state)
Definition: debug_utils.cpp:159
Tracer::registerClass
static void registerClass(const char *name, bool state=true, const char *filePath=nullptr)
Definition: debug_utils.cpp:254
Tracer::showEvent
virtual void showEvent(QShowEvent *)
Definition: debug_utils.cpp:329
Tracer::slotItemClicked
void slotItemClicked(QTreeWidgetItem *item, int column)
Definition: debug_utils.cpp:419
Tracer::MapType
QMap< QString, MapEntry > MapType
Definition: debug_utils.h:99
toString
QString toString(const T &value)
Definition: debug_utils.h:150
Settings
Definition: codeviewerstate.cpp:10