dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
debuggadgetfactory.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 #include "debuggadgetfactory.h"
28 #include "debuggadgetwidget.h"
29 #include "debuggadget.h"
30 #include <coreplugin/iuavgadget.h>
31 #include <QTextStream>
32 #include <QProcessEnvironment>
33 
34 void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
35 {
37  switch (type) {
38  case QtDebugMsg:
39  level = DebugEngine::DEBUG;
40  break;
41  case QtInfoMsg:
42  level = DebugEngine::INFO;
43  break;
44  case QtWarningMsg:
45  level = DebugEngine::WARNING;
46  QTextStream(stderr) << "[Warning] " << msg << endl;
47  break;
48  case QtCriticalMsg:
49  level = DebugEngine::CRITICAL;
50  QTextStream(stderr) << "[Critical] " << msg << endl;
51  break;
52  case QtFatalMsg:
53  level = DebugEngine::FATAL;
54  QTextStream(stderr) << "[FATAL] " << msg << endl;
55  break;
56  }
57  DebugEngine::getInstance()->message(level, msg, QString(context.file), context.line,
58  QString(context.function));
59 }
60 
62  : IUAVGadgetFactory(QString("DebugGadget"), tr("DebugGadget"), parent)
63 {
64  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
65  if (env.contains("NO_DEBUG_GADGET"))
67  "Debug gadget disabled by NO_DEBUG_GADGET env. var.");
68  else
69  qInstallMessageHandler(customMessageHandler);
70 }
71 
73 {
74 }
75 
76 IUAVGadget *DebugGadgetFactory::createGadget(QWidget *parent)
77 {
78  DebugGadgetWidget *gadgetWidget = new DebugGadgetWidget(parent);
79 
80  return new DebugGadget(QString("DebugGadget"), gadgetWidget, parent);
81 }
82 
void message(DebugEngine::Level level, const QString &msg, const QString &file="", const int line=0, const QString &function="")
IUAVGadget * createGadget(QWidget *parent)
void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
DebugGadgetFactory(QObject *parent=nullptr)
static DebugEngine * getInstance()
Definition: debugengine.cpp:35