umbrello 2.32.3 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
5 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
6*/
7
8#ifndef DEBUG_UTILS_H
9#define DEBUG_UTILS_H
10
11#include <QtGlobal>
12
13#if QT_VERSION < 0x050000
14#include <kdebug.h>
15#endif
16
17#if QT_VERSION >= 0x050000
18#include <QLoggingCategory>
19Q_DECLARE_LOGGING_CATEGORY(UMBRELLO)
20#endif
21#include <QMetaEnum>
22#include <QTreeWidget>
23
57 class Tracer : public QTreeWidget
58{
59 Q_OBJECT
60 public:
61 static Tracer* instance();
62
63 ~Tracer();
64
65 bool isEnabled(const QString& name);
66 void enable(const QString& name);
67 void disable(const QString& name);
68
69 void enableAll();
70 void disableAll();
71
72 static void registerClass(const QString& name, bool state=true, const QString &filePath=QString());
73
74 protected:
75 void update(const QString &name);
76 void updateParentItemCheckBox(QTreeWidgetItem *parent);
77 virtual void showEvent(QShowEvent*);
78
79 private slots:
80 void slotParentItemClicked(QTreeWidgetItem *parent);
81 void slotItemClicked(QTreeWidgetItem* item, int column);
82
83 private:
84 class MapEntry {
85 public:
86 QString filePath;
87 bool state;
88 MapEntry() : state(false) {}
89 MapEntry(const QString &_filePath, bool _state) : filePath(_filePath), state(_state) {}
90 };
91
92 typedef QMap<QString, MapEntry> MapType;
93 typedef QMap<QString,Qt::CheckState> StateMap;
94
95 static Tracer* m_instance;
96 static MapType *m_classes;
97 static StateMap *m_states;
98
99 explicit Tracer(QWidget *parent = 0);
100};
101
102// convenience macros for console output to the Umbrello area
103#if QT_VERSION >= 0x050000
104#define uDebug() qCDebug(UMBRELLO)
105#define uError() qCCritical(UMBRELLO)
106#define uWarning() qCWarning(UMBRELLO)
107#else
108#define uDebug() kDebug(8060)
109#define uError() kError(8060)
110#define uWarning() kWarning(8060)
111#endif
112
113#define DBG_SRC QString::fromLatin1(metaObject()->className())
114#define DEBUG_SHOW_FILTER() Tracer::instance()->show()
115#define DEBUG(src) if (Tracer::instance()->isEnabled(src)) uDebug()
116#define IS_DEBUG_ENABLED(src) Tracer::instance()->isEnabled(QString::fromLatin1(#src))
117#define DEBUG_REGISTER(src) class src##Tracer { public: src##Tracer() { Tracer::registerClass(QString::fromLatin1(#src), true, QLatin1String(__FILE__)); } }; static src##Tracer src##TracerGlobal;
118#define DEBUG_REGISTER_DISABLED(src) class src##Tracer { public: src##Tracer() { Tracer::registerClass(QString::fromLatin1(#src), false, QLatin1String(__FILE__)); } }; static src##Tracer src##TracerGlobal;
119
120#define uIgnoreZeroPointer(a) if (!a) { uDebug() << "zero pointer detected" << __FILE__ << __LINE__; continue; }
121
122
129#define ENUM_NAME(o, e, v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))
130
131#endif
Tracer::MapEntry
Definition: debug_utils.h:84
Tracer::MapEntry::MapEntry
MapEntry(const QString &_filePath, bool _state)
Definition: debug_utils.h:89
Tracer::MapEntry::filePath
QString filePath
Definition: debug_utils.h:86
Tracer::MapEntry::state
bool state
Definition: debug_utils.h:87
Tracer::MapEntry::MapEntry
MapEntry()
Definition: debug_utils.h:88
Tracer
The singleton class for switching on or off debug messages.
Definition: debug_utils.h:58
Tracer::disable
void disable(const QString &name)
Definition: debug_utils.cpp:84
Tracer::m_instance
static Tracer * m_instance
Definition: debug_utils.h:95
Tracer::disableAll
void disableAll()
Definition: debug_utils.cpp:95
Tracer::m_classes
static MapType * m_classes
Definition: debug_utils.h:96
Tracer::enableAll
void enableAll()
Definition: debug_utils.cpp:90
Tracer::slotParentItemClicked
void slotParentItemClicked(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:184
Tracer::StateMap
QMap< QString, Qt::CheckState > StateMap
Definition: debug_utils.h:93
Tracer::updateParentItemCheckBox
void updateParentItemCheckBox(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:135
Tracer::m_states
static StateMap * m_states
Definition: debug_utils.h:97
Tracer::enable
void enable(const QString &name)
Definition: debug_utils.cpp:74
Tracer::~Tracer
~Tracer()
Definition: debug_utils.cpp:52
Tracer::instance
static Tracer * instance()
Definition: debug_utils.cpp:22
Tracer::Tracer
Tracer(QWidget *parent=0)
Definition: debug_utils.cpp:34
Tracer::isEnabled
bool isEnabled(const QString &name)
Definition: debug_utils.cpp:65
Tracer::registerClass
static void registerClass(const QString &name, bool state=true, const QString &filePath=QString())
Definition: debug_utils.cpp:105
Tracer::update
void update(const QString &name)
Definition: debug_utils.cpp:120
Tracer::showEvent
virtual void showEvent(QShowEvent *)
Definition: debug_utils.cpp:155
Tracer::slotItemClicked
void slotItemClicked(QTreeWidgetItem *item, int column)
Definition: debug_utils.cpp:210
Tracer::MapType
QMap< QString, MapEntry > MapType
Definition: debug_utils.h:92