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 Copyright 2011 Andi Fischer <andi.fischer@hispeed.ch>
3 Copyright 2012 Ralf Habacker <ralf.habacker@freenet.de>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3 or any later version
9 accepted by the membership of KDE e.V. (or its successor approved
10 by the membership of KDE e.V.), which shall act as a proxy
11 defined in Section 14 of version 3 of the license.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef DEBUG_UTILS_H
23 #define DEBUG_UTILS_H
24
25 #include <QtGlobal>
26
27 #if QT_VERSION < 0x050000
28 #include <kdebug.h>
29 #endif
30
31 #if QT_VERSION >= 0x050000
32 #include <QLoggingCategory>
33 Q_DECLARE_LOGGING_CATEGORY(UMBRELLO)
34 #endif
35 #include <QMetaEnum>
36 #include <QTreeWidget>
37
71 class Tracer : public QTreeWidget
72 {
73 Q_OBJECT
74 public:
75 static Tracer* instance();
76
77 ~Tracer();
78
79 bool isEnabled(const QString& name);
80 void enable(const QString& name);
81 void disable(const QString& name);
82
83 void enableAll();
84 void disableAll();
85
86 static void registerClass(const QString& name, bool state=true, const QString &filePath=QString());
87
88 protected:
89 void update(const QString &name);
90 void updateParentItemCheckBox(QTreeWidgetItem *parent);
91 virtual void showEvent(QShowEvent*);
92
93 private slots:
94 void slotParentItemClicked(QTreeWidgetItem *parent);
95 void slotItemClicked(QTreeWidgetItem* item, int column);
96
97 private:
98 class MapEntry {
99 public:
100 QString filePath;
101 bool state;
102 MapEntry() : state(false) {}
103 MapEntry(const QString &_filePath, bool _state) : filePath(_filePath), state(_state) {}
104 };
105
106 typedef QMap<QString, MapEntry> MapType;
107 typedef QMap<QString,Qt::CheckState> StateMap;
108
109 static Tracer* m_instance;
110 static MapType *m_classes;
111 static StateMap *m_states;
112
113 explicit Tracer(QWidget *parent = 0);
114 };
115
116 // convenience macros for console output to the Umbrello area
117 #if QT_VERSION >= 0x050000
118 #define uDebug() qCDebug(UMBRELLO)
119 #define uError() qCCritical(UMBRELLO)
120 #define uWarning() qCWarning(UMBRELLO)
121 #else
122 #define uDebug() kDebug(8060)
123 #define uError() kError(8060)
124 #define uWarning() kWarning(8060)
125 #endif
126
127 #define DBG_SRC QString::fromLatin1(metaObject()->className())
128 #define DEBUG_SHOW_FILTER() Tracer::instance()->show()
129 #define DEBUG(src) if (Tracer::instance()->isEnabled(src)) uDebug()
130 #define IS_DEBUG_ENABLED(src) Tracer::instance()->isEnabled(QString::fromLatin1(#src))
131 #define DEBUG_REGISTER(src) class src##Tracer { public: src##Tracer() { Tracer::registerClass(QString::fromLatin1(#src), true, QLatin1String(__FILE__)); } }; static src##Tracer src##TracerGlobal;
132 #define DEBUG_REGISTER_DISABLED(src) class src##Tracer { public: src##Tracer() { Tracer::registerClass(QString::fromLatin1(#src), false, QLatin1String(__FILE__)); } }; static src##Tracer src##TracerGlobal;
133
134 #define uIgnoreZeroPointer(a) if (!a) { uDebug() << "zero pointer detected" << __FILE__ << __LINE__; continue; }
135
136
143 #define ENUM_NAME(o, e, v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))
144
145 #endif
Tracer::disableAll
void disableAll()
Definition: debug_utils.cpp:109
Tracer::slotParentItemClicked
void slotParentItemClicked(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:198
Tracer::m_states
static StateMap * m_states
Definition: debug_utils.h:111
Tracer::enable
void enable(const QString &name)
Definition: debug_utils.cpp:88
Tracer::~Tracer
~Tracer()
Definition: debug_utils.cpp:66
Tracer::instance
static Tracer * instance()
Definition: debug_utils.cpp:36
Tracer::updateParentItemCheckBox
void updateParentItemCheckBox(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:149
Tracer::StateMap
QMap< QString, Qt::CheckState > StateMap
Definition: debug_utils.h:107
Tracer::enableAll
void enableAll()
Definition: debug_utils.cpp:104
Tracer::MapType
QMap< QString, MapEntry > MapType
Definition: debug_utils.h:106
Tracer::MapEntry
Definition: debug_utils.h:98
Tracer::m_classes
static MapType * m_classes
Definition: debug_utils.h:110
Tracer::MapEntry::state
bool state
Definition: debug_utils.h:101
Tracer::m_instance
static Tracer * m_instance
Definition: debug_utils.h:109
Tracer::registerClass
static void registerClass(const QString &name, bool state=true, const QString &filePath=QString())
Definition: debug_utils.cpp:119
Tracer::update
void update(const QString &name)
Definition: debug_utils.cpp:134
i18n
#define i18n
Definition: main.cpp:39
MyProject\connect
connect()
Definition: namespaces-multiple.php:5
Tracer::disable
void disable(const QString &name)
Definition: debug_utils.cpp:98
Tracer::showEvent
virtual void showEvent(QShowEvent *)
Definition: debug_utils.cpp:169
debug_utils.h
Tracer::MapEntry::MapEntry
MapEntry()
Definition: debug_utils.h:102
Tracer
The singleton class for switching on or off debug messages.
Definition: debug_utils.h:72
Tracer::isEnabled
bool isEnabled(const QString &name)
Definition: debug_utils.cpp:79
Tracer::slotItemClicked
void slotItemClicked(QTreeWidgetItem *item, int column)
Definition: debug_utils.cpp:224
Tracer::Tracer
Tracer(QWidget *parent=0)
Definition: debug_utils.cpp:48
Tracer::MapEntry::MapEntry
MapEntry(const QString &_filePath, bool _state)
Definition: debug_utils.h:103
Tracer::MapEntry::filePath
QString filePath
Definition: debug_utils.h:100