umbrello  2.39.2
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 #include <QLoggingCategory>
20 Q_DECLARE_LOGGING_CATEGORY(UMBRELLO)
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) 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 
76 protected:
77  void update(const QString &name);
78  void updateParentItemCheckBox(QTreeWidgetItem *parent);
79  virtual void showEvent(QShowEvent*);
80 
81 private slots:
82  void slotParentItemClicked(QTreeWidgetItem *parent);
83  void slotItemClicked(QTreeWidgetItem* item, int column);
84 
85 private:
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
Definition: debug_utils.h:86
MapEntry(const QString &_filePath, bool _state)
Definition: debug_utils.h:91
QString filePath
Definition: debug_utils.h:88
bool state
Definition: debug_utils.h:89
MapEntry()
Definition: debug_utils.h:90
The singleton class for switching on or off debug messages.
Definition: debug_utils.h:58
static StateMap * s_states
Definition: debug_utils.h:99
static bool s_logToConsole
Definition: debug_utils.h:100
void disable(const QString &name)
Definition: debug_utils.cpp:185
static Tracer * s_instance
Definition: debug_utils.h:97
void disableAll()
Definition: debug_utils.cpp:196
void enableAll()
Definition: debug_utils.cpp:191
void slotParentItemClicked(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:296
QMap< QString, Qt::CheckState > StateMap
Definition: debug_utils.h:95
void updateParentItemCheckBox(QTreeWidgetItem *parent)
Definition: debug_utils.cpp:247
void enable(const QString &name)
Definition: debug_utils.cpp:175
~Tracer()
Definition: debug_utils.cpp:148
bool logToConsole()
Definition: debug_utils.cpp:201
static Tracer * instance()
Definition: debug_utils.cpp:108
Tracer(QWidget *parent=0)
Definition: debug_utils.cpp:135
static void registerClass(const char *name, bool state=true, const char *filePath=0)
Definition: debug_utils.cpp:212
void update(const QString &name)
Definition: debug_utils.cpp:232
bool isEnabled(const QString &name) const
Definition: debug_utils.cpp:157
static MapType * s_classes
Definition: debug_utils.h:98
virtual void showEvent(QShowEvent *)
Definition: debug_utils.cpp:267
void slotItemClicked(QTreeWidgetItem *item, int column)
Definition: debug_utils.cpp:322
QMap< QString, MapEntry > MapType
Definition: debug_utils.h:94