umbrello: umbrello/debug/debug_utils.h Source File

umbrello 2.35.1 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
63 class 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
103 static Tracer* s_instance;
104 static MapType* s_classes;
105 static StateMap* s_states;
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
Tracer::MapEntry
Definition: debug_utils.h:92
Tracer::MapEntry::MapEntry
MapEntry(const QString &_filePath, bool _state)
Definition: debug_utils.h:97
Tracer::MapEntry::filePath
QString filePath
Definition: debug_utils.h:94
Tracer::MapEntry::state
bool state
Definition: debug_utils.h:95
Tracer::MapEntry::MapEntry
MapEntry()
Definition: debug_utils.h:96
Tracer
The singleton class for switching on or off debug messages.
Definition: debug_utils.h:64
Tracer::s_states
static StateMap * s_states
Definition: debug_utils.h:105
Tracer::s_logToConsole
static bool s_logToConsole
Definition: debug_utils.h:106
Tracer::disable
void disable(const QString &name)
Definition: debug_utils.cpp:187
Tracer::s_instance
static Tracer * s_instance
Definition: debug_utils.h:103
Tracer::disableAll
void disableAll()
Definition: debug_utils.cpp:198
Tracer::enableAll
void enableAll()
Definition: debug_utils.cpp:193
Tracer::slotParentItemClicked
void slotParentItemClicked(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:298
Tracer::StateMap
QMap< QString, Qt::CheckState > StateMap
Definition: debug_utils.h:101
Tracer::updateParentItemCheckBox
void updateParentItemCheckBox(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:249
Tracer::enable
void enable(const QString &name)
Definition: debug_utils.cpp:177
Tracer::~Tracer
~Tracer()
Definition: debug_utils.cpp:150
Tracer::logToConsole
bool logToConsole()
Definition: debug_utils.cpp:203
Tracer::instance
static Tracer * instance()
Definition: debug_utils.cpp:110
Tracer::Tracer
Tracer(QWidget *parent=0)
Definition: debug_utils.cpp:137
Tracer::registerClass
static void registerClass(const char *name, bool state=true, const char *filePath=0)
Definition: debug_utils.cpp:214
Tracer::update
void update(const QString &name)
Definition: debug_utils.cpp:234
Tracer::isEnabled
bool isEnabled(const QString &name) const
Definition: debug_utils.cpp:159
Tracer::s_classes
static MapType * s_classes
Definition: debug_utils.h:104
Tracer::showEvent
virtual void showEvent(QShowEvent *)
Definition: debug_utils.cpp:269
Tracer::slotItemClicked
void slotItemClicked(QTreeWidgetItem *item, int column)
Definition: debug_utils.cpp:324
Tracer::MapType
QMap< QString, MapEntry > MapType
Definition: debug_utils.h:100