umbrello: umbrello/debug/debug_utils.h Source File

umbrello 2.38.3 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
57 class Tracer : public QTreeWidget
58{
59 Q_OBJECT
60public:
61 static Tracer* instance();
62
63 ~Tracer();
64
65 bool isEnabled(const QString& name) const;
66 void enable(const QString& name);
67 void disable(const QString& name);
68
69 void enableAll();
70 void disableAll();
71
72 bool logToConsole();
73
74 static void registerClass(const char * name, bool state=true, const char * filePath=0);
75
76protected:
77 void update(const QString &name);
78 void updateParentItemCheckBox(QTreeWidgetItem *parent);
79 virtual void showEvent(QShowEvent*);
80
81private slots:
82 void slotParentItemClicked(QTreeWidgetItem *parent);
83 void slotItemClicked(QTreeWidgetItem* item, int column);
84
85private:
86 class MapEntry {
87 public:
88 QString filePath;
89 bool state;
90 MapEntry() : state(false) {}
91 MapEntry(const QString &_filePath, bool _state) : filePath(_filePath), state(_state) {}
92 };
93
94 typedef QMap<QString, MapEntry> MapType;
95 typedef QMap<QString,Qt::CheckState> StateMap;
96
97 static Tracer* s_instance;
98 static MapType* s_classes;
99 static StateMap* s_states;
100 static bool s_logToConsole;
101
102 explicit Tracer(QWidget *parent = 0);
103};
104
105// convenience macros for console output to the Umbrello area
106#define uDebug() qCDebug(UMBRELLO)
107#define uError() qCCritical(UMBRELLO)
108#define uWarning() qCWarning(UMBRELLO)
109
110#ifndef DBG_SRC
111#define DBG_SRC QString::fromLatin1(metaObject()->className())
112#endif
113#define DEBUG_SHOW_FILTER() Tracer::instance()->show()
114#define DEBUG_N(latin1str) if (Tracer::instance()->logToConsole() || Tracer::instance()->isEnabled(latin1str)) uDebug()
115#define DEBUG() DEBUG_N(DBG_SRC)
116#define IS_DEBUG_ENABLED() Tracer::instance()->isEnabled(DBG_SRC)
117#define DEBUG_REGISTER(src) \
118 class src##Tracer { \
119 public: \
120 src##Tracer() { Tracer::registerClass(#src, true, __FILE__); } \
121 }; \
122 static src##Tracer src##TracerGlobal;
123#define DEBUG_REGISTER_DISABLED(src) \
124 class src##Tracer { \
125 public: \
126 src##Tracer() { Tracer::registerClass(#src, false, __FILE__); } \
127 }; \
128 static src##Tracer src##TracerGlobal;
129
130#define uIgnoreZeroPointer(a) if (!a) { uDebug() << "zero pointer detected" << __FILE__ << __LINE__; continue; }
131
132
139#define ENUM_NAME(o, e, v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))
140
141#endif
Tracer::MapEntry
Definition: debug_utils.h:86
Tracer::MapEntry::MapEntry
MapEntry(const QString &_filePath, bool _state)
Definition: debug_utils.h:91
Tracer::MapEntry::filePath
QString filePath
Definition: debug_utils.h:88
Tracer::MapEntry::state
bool state
Definition: debug_utils.h:89
Tracer::MapEntry::MapEntry
MapEntry()
Definition: debug_utils.h:90
Tracer
The singleton class for switching on or off debug messages.
Definition: debug_utils.h:58
Tracer::s_states
static StateMap * s_states
Definition: debug_utils.h:99
Tracer::s_logToConsole
static bool s_logToConsole
Definition: debug_utils.h:100
Tracer::disable
void disable(const QString &name)
Definition: debug_utils.cpp:185
Tracer::s_instance
static Tracer * s_instance
Definition: debug_utils.h:97
Tracer::disableAll
void disableAll()
Definition: debug_utils.cpp:196
Tracer::enableAll
void enableAll()
Definition: debug_utils.cpp:191
Tracer::slotParentItemClicked
void slotParentItemClicked(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:296
Tracer::StateMap
QMap< QString, Qt::CheckState > StateMap
Definition: debug_utils.h:95
Tracer::updateParentItemCheckBox
void updateParentItemCheckBox(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:247
Tracer::enable
void enable(const QString &name)
Definition: debug_utils.cpp:175
Tracer::~Tracer
~Tracer()
Definition: debug_utils.cpp:148
Tracer::logToConsole
bool logToConsole()
Definition: debug_utils.cpp:201
Tracer::instance
static Tracer * instance()
Definition: debug_utils.cpp:108
Tracer::registerClass
static void registerClass(const char *name, bool state=true, const char *filePath=0)
Definition: debug_utils.cpp:212
Tracer::update
void update(const QString &name)
Definition: debug_utils.cpp:232
Tracer::isEnabled
bool isEnabled(const QString &name) const
Definition: debug_utils.cpp:157
Tracer::s_classes
static MapType * s_classes
Definition: debug_utils.h:98
Tracer::showEvent
virtual void showEvent(QShowEvent *)
Definition: debug_utils.cpp:267
Tracer::slotItemClicked
void slotItemClicked(QTreeWidgetItem *item, int column)
Definition: debug_utils.cpp:322
Tracer::MapType
QMap< QString, MapEntry > MapType
Definition: debug_utils.h:94