umbrello 2.34.70-5524f40e1
Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology
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#if QT_VERSION < 0x050000
20#include <kdebug.h>
21#endif
22
23#if QT_VERSION >= 0x050000
24#include <QLoggingCategory>
25Q_DECLARE_LOGGING_CATEGORY(UMBRELLO)
26#endif
27#include <QMetaEnum>
28#include <QTreeWidget>
29
63class Tracer : public QTreeWidget
64{
65 Q_OBJECT
66public:
67 static Tracer* instance();
68
69 ~Tracer();
70
71 bool isEnabled(const QString& name) const;
72 void enable(const QString& name);
73 void disable(const QString& name);
74
75 void enableAll();
76 void disableAll();
77
78 bool logToConsole();
79
80 static void registerClass(const char * name, bool state=true, const char * filePath=0);
81
82protected:
83 void update(const QString &name);
84 void updateParentItemCheckBox(QTreeWidgetItem *parent);
85 virtual void showEvent(QShowEvent*);
86
87private slots:
88 void slotParentItemClicked(QTreeWidgetItem *parent);
89 void slotItemClicked(QTreeWidgetItem* item, int column);
90
91private:
92 class MapEntry {
93 public:
94 QString filePath;
95 bool state;
96 MapEntry() : state(false) {}
97 MapEntry(const QString &_filePath, bool _state) : filePath(_filePath), state(_state) {}
98 };
99
100 typedef QMap<QString, MapEntry> MapType;
101 typedef QMap<QString,Qt::CheckState> StateMap;
102
106 static bool s_logToConsole;
107
108 explicit Tracer(QWidget *parent = 0);
109};
110
111// convenience macros for console output to the Umbrello area
112#if QT_VERSION >= 0x050000
113#define uDebug() qCDebug(UMBRELLO)
114#define uError() qCCritical(UMBRELLO)
115#define uWarning() qCWarning(UMBRELLO)
116#else
117#define uDebug() kDebug(8060)
118#define uError() kError(8060)
119#define uWarning() kWarning(8060)
120#endif
121
122#ifndef DBG_SRC
123#define DBG_SRC QString::fromLatin1(metaObject()->className())
124#endif
125#define DEBUG_SHOW_FILTER() Tracer::instance()->show()
126#define DEBUG_N(latin1str) if (Tracer::instance()->logToConsole() || Tracer::instance()->isEnabled(latin1str)) uDebug()
127#define DEBUG() DEBUG_N(DBG_SRC)
128#define IS_DEBUG_ENABLED() Tracer::instance()->isEnabled(DBG_SRC)
129#define DEBUG_REGISTER(src) \
130 class src##Tracer { \
131 public: \
132 src##Tracer() { Tracer::registerClass(#src, true, __FILE__); } \
133 }; \
134 static src##Tracer src##TracerGlobal;
135#define DEBUG_REGISTER_DISABLED(src) \
136 class src##Tracer { \
137 public: \
138 src##Tracer() { Tracer::registerClass(#src, false, __FILE__); } \
139 }; \
140 static src##Tracer src##TracerGlobal;
141
142#define uIgnoreZeroPointer(a) if (!a) { uDebug() << "zero pointer detected" << __FILE__ << __LINE__; continue; }
143
144
151#define ENUM_NAME(o, e, v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))
152
153#endif
Definition: debug_utils.h:92
MapEntry(const QString &_filePath, bool _state)
Definition: debug_utils.h:97
QString filePath
Definition: debug_utils.h:94
bool state
Definition: debug_utils.h:95
MapEntry()
Definition: debug_utils.h:96
The singleton class for switching on or off debug messages.
Definition: debug_utils.h:64
static StateMap s_states
Definition: debug_utils.h:105
static bool s_logToConsole
Definition: debug_utils.h:106
void disable(const QString &name)
Definition: debug_utils.cpp:184
static Tracer * s_instance
Definition: debug_utils.h:103
void disableAll()
Definition: debug_utils.cpp:195
void enableAll()
Definition: debug_utils.cpp:190
void slotParentItemClicked(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:295
QMap< QString, Qt::CheckState > StateMap
Definition: debug_utils.h:101
void updateParentItemCheckBox(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:246
void enable(const QString &name)
Definition: debug_utils.cpp:174
~Tracer()
Definition: debug_utils.cpp:147
bool logToConsole()
Definition: debug_utils.cpp:200
static Tracer * instance()
Definition: debug_utils.cpp:109
Tracer(QWidget *parent=0)
Definition: debug_utils.cpp:134
static MapType s_classes
Definition: debug_utils.h:104
static void registerClass(const char *name, bool state=true, const char *filePath=0)
Definition: debug_utils.cpp:211
void update(const QString &name)
Definition: debug_utils.cpp:231
bool isEnabled(const QString &name) const
Definition: debug_utils.cpp:156
virtual void showEvent(QShowEvent *)
Definition: debug_utils.cpp:266
void slotItemClicked(QTreeWidgetItem *item, int column)
Definition: debug_utils.cpp:321
QMap< QString, MapEntry > MapType
Definition: debug_utils.h:100