1 /*
2  *  Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 #ifndef KIS_DEBUG_H_
19 #define KIS_DEBUG_H_
20 
21 #include <QDebug>
22 #include <QLoggingCategory>
23 
24 #include "kritaglobal_export.h"
25 
26 /**
27  * To show debug output, start krita like:
28  *
29  * QT_LOGGING_RULES="*.*=false;krita.metadata.*=true;krita.file.*=true"
30  *
31  */
32 
33 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_30009();
34 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41000();
35 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41001();
36 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41002();
37 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41003();
38 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41004();
39 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41005();
40 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41006();
41 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41007();
42 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41008();
43 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41009();
44 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41010();
45 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41011();
46 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41012();
47 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41013();
48 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41014();
49 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41015();
50 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41016();
51 extern const KRITAGLOBAL_EXPORT QLoggingCategory &_41017();
52 
53 #define dbgResources qCDebug(_30009)
54 #define dbgKrita qCDebug(_41000)
55 #define dbgImage qCDebug(_41001)
56 #define dbgRegistry qCDebug(_41002)
57 #define dbgTools qCDebug(_41003)
58 #define dbgTiles qCDebug(_41004)
59 #define dbgFilters qCDebug(_41005)
60 #define dbgPlugins qCDebug(_41006)
61 #define dbgUI qCDebug(_41007)
62 #define dbgFile qCDebug(_41008)
63 #define dbgMath qCDebug(_41009)
64 #define dbgRender qCDebug(_41010)
65 #define dbgScript qCDebug(_41011)
66 #define dbgInput qCDebug(_41012)
67 #define dbgAction qCDebug(_41013)
68 #define dbgTablet qCDebug(_41014)
69 #define dbgOpenGL qCDebug(_41015)
70 #define dbgMetaData qCDebug(_41016)
71 #define dbgAndroid qCDebug(_41017)
72 
73 #define infoResources qCInfo(_30009)
74 #define infoKrita qCInfo(_41000)
75 #define infoImage qCInfo(_41001)
76 #define infoRegistry qCInfo(_41002)
77 #define infoTools qCInfo(_41003)
78 #define infoTiles qCInfo(_41004)
79 #define infoFilters qCInfo(_41005)
80 #define infoPlugins qCInfo(_41006)
81 #define infoUI qCInfo(_41007)
82 #define infoFile qCInfo(_41008)
83 #define infoMath qCInfo(_41009)
84 #define infoRender qCInfo(_41010)
85 #define infoScript qCInfo(_41011)
86 #define infoInput qCInfo(_41012)
87 #define infoAction qCDebug(_41013)
88 #define infoTablet qCDebug(_41014)
89 #define infoOpenGL qCDebug(_41015)
90 #define infoMetaData qCDebug(_41016)
91 
92 
93 #define warnResources qCWarning(_30009)
94 #define warnKrita qCWarning(_41000)
95 #define warnImage qCWarning(_41001)
96 #define warnRegistry qCWarning(_41002)
97 #define warnTools qCWarning(_41003)
98 #define warnTiles qCWarning(_41004)
99 #define warnFilters qCWarning(_41005)
100 #define warnPlugins qCWarning(_41006)
101 #define warnUI qCWarning(_41007)
102 #define warnFile qCWarning(_41008)
103 #define warnMath qCWarning(_41009)
104 #define warnRender qCWarning(_41010)
105 #define warnScript qCWarning(_41011)
106 #define warnInput qCWarning(_41012)
107 #define warnAction qCDebug(_41013)
108 #define warnTablet qCDebug(_41014)
109 #define warnOpenGL qCDebug(_41015)
110 #define warnMetaData qCDebug(_41016)
111 
112 #define errResources qCCritical(_30009)
113 #define errKrita qCCritical(_41000)
114 #define errImage qCCritical(_41001)
115 #define errRegistry qCCritical(_41002)
116 #define errTools qCCritical(_41003)
117 #define errTiles qCCritical(_41004)
118 #define errFilters qCCritical(_41005)
119 #define errPlugins qCCritical(_41006)
120 #define errUI qCCritical(_41007)
121 #define errFile qCCritical(_41008)
122 #define errMath qCCritical(_41009)
123 #define errRender qCCritical(_41010)
124 #define errScript qCCritical(_41011)
125 #define errInput qCCritical(_41012)
126 #define errAction qCDebug(_41013)
127 #define errTablet qCDebug(_41014)
128 #define errOpenGL qCDebug(_41015)
129 #define errMetaData qCDebug(_41016)
130 
131 // Qt does not yet define qCFatal (TODO: this is an oversight, submit a patch upstream)
132 /*
133 #define fatalResources qCFatal(_30009)
134 #define fatalKrita qCFatal(_41000)
135 #define fatalImage qCFatal(_41001)
136 #define fatalRegistry qCFatal(_41002)
137 #define fatalTools qCFatal(_41003)
138 #define fatalTiles qCFatal(_41004)
139 #define fatalFilters qCFatal(_41005)
140 #define fatalPlugins qCFatal(_41006)
141 #define fatalUI qCFatal(_41007)
142 #define fatalFile qCFatal(_41008)
143 #define fatalMath qCFatal(_41009)
144 #define fatalRender qCFatal(_41010)
145 #define fatalScript qCFatal(_41011)
146 #define fatalInput qCFatal(_41012)
147 #define fatalAction qCDebug(_41013)
148 */
149 
150 
151 /**
152  * Show a nicely formatted backtrace.
153  */
154 KRITAGLOBAL_EXPORT QString kisBacktrace();
155 
156 /**
157  * Please pretty print my variable
158  *
159  * Use this macro to display in the output stream the name of a variable followed by its value.
160  */
161 #define ppVar( var ) #var << "=" << (var)
162 
163 #  ifndef QT_NO_DEBUG
164 #    undef Q_ASSERT
165 #    define Q_ASSERT(cond) if(!(cond)) { errKrita << kisBacktrace(); qt_assert(#cond,__FILE__,__LINE__); } qt_noop()
166 #  endif
167 
168 
169 #ifdef __GNUC__
170 KRITAGLOBAL_EXPORT QString __methodName(const char *prettyFunction);
171 #define __METHOD_NAME__ __methodName(__PRETTY_FUNCTION__)
172 #else
173 #define __METHOD_NAME__ "<unknown>:<unknown>"
174 #endif
175 
176 #define PREPEND_METHOD(msg) QString("%1: %2").arg(__METHOD_NAME__).arg(msg)
177 
178 #ifdef __GNUC__
179 #define ENTER_FUNCTION() qDebug() << "Entering" << __METHOD_NAME__
180 #define LEAVE_FUNCTION() qDebug() << "Leaving " << __METHOD_NAME__
181 #else
182 #define ENTER_FUNCTION() qDebug() << "Entering" << "<unknown>"
183 #define LEAVE_FUNCTION() qDebug() << "Leaving " << "<unknown>"
184 #endif
185 
186 #include "kis_assert.h"
187 
188 #endif
189