umbrello 2.31.70-88582909d
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
57class 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 static void registerClass(const QString& name, bool state=true, const QString &filePath=QString());
73
74protected:
75 void update(const QString &name);
76 void updateParentItemCheckBox(QTreeWidgetItem *parent);
77 virtual void showEvent(QShowEvent*);
78
79private slots:
80 void slotParentItemClicked(QTreeWidgetItem *parent);
81 void slotItemClicked(QTreeWidgetItem* item, int column);
82
83private:
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
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
Definition: debug_utils.h:84
MapEntry(const QString &_filePath, bool _state)
Definition: debug_utils.h:89
QString filePath
Definition: debug_utils.h:86
bool state
Definition: debug_utils.h:87
MapEntry()
Definition: debug_utils.h:88
The singleton class for switching on or off debug messages.
Definition: debug_utils.h:58
void disable(const QString &name)
Definition: debug_utils.cpp:84
static Tracer * m_instance
Definition: debug_utils.h:95
void disableAll()
Definition: debug_utils.cpp:95
static MapType * m_classes
Definition: debug_utils.h:96
void enableAll()
Definition: debug_utils.cpp:90
void slotParentItemClicked(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:184
QMap< QString, Qt::CheckState > StateMap
Definition: debug_utils.h:93
void updateParentItemCheckBox(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:135
static StateMap * m_states
Definition: debug_utils.h:97
void enable(const QString &name)
Definition: debug_utils.cpp:74
~Tracer()
Definition: debug_utils.cpp:52
static Tracer * instance()
Definition: debug_utils.cpp:22
Tracer(QWidget *parent=0)
Definition: debug_utils.cpp:34
static void registerClass(const QString &name, bool state=true, const QString &filePath=QString())
Definition: debug_utils.cpp:105
void update(const QString &name)
Definition: debug_utils.cpp:120
bool isEnabled(const QString &name) const
Definition: debug_utils.cpp:65
virtual void showEvent(QShowEvent *)
Definition: debug_utils.cpp:155
void slotItemClicked(QTreeWidgetItem *item, int column)
Definition: debug_utils.cpp:210
QMap< QString, MapEntry > MapType
Definition: debug_utils.h:92