2 ******************************************************************************
4 * @file debuggadgetwidget.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup DebugGadgetPlugin Debug Gadget Plugin
10 * @brief A place holder gadget plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "debuggadgetwidget.h"
30 #include <QStringList>
33 #include <QVBoxLayout>
34 #include <QPushButton>
35 #include "debugengine.h"
37 #include <QFileDialog>
38 #include <QMessageBox>
42 QPointer
<QTextBrowser
> m_textedit
;
44 void DebugGadgetWidget::customMessageHandler(QtMsgType type
, const QMessageLogContext
&context
, const QString
&msg
)
48 QColor color
= Qt::black
;
52 txt
= QString("Debug: %1").arg(msg
);
56 txt
= QString("Warning: %1").arg(msg
);
60 txt
= QString("Critical: %1").arg(msg
);
64 txt
= QString("Fatal: %1").arg(msg
);
68 debugengine::getInstance()->setTextEdit(m_textedit
);
69 debugengine::getInstance()->setColor(color
);
70 debugengine::getInstance()->writeMessage(txt
);
73 DebugGadgetWidget::DebugGadgetWidget(QWidget
*parent
) : QLabel(parent
)
75 m_config
= new Ui_Form();
76 m_config
->setupUi(this);
78 // m_textedit = m_config->plainTextEdit;
79 // MyplainTextEdit=m_config->plainTextEdit;
80 // debugengine *de = new debugengine();
81 // qInstallMessageHandler(customMessageHandler);
82 // connect(de, SIGNAL(dbgMsg(QString, QList<QVariant>)), this, SLOT(dbgMsg(QString, QList<QVariant>)));
83 // connect(de, SIGNAL(dbgMsgError(QString, QList<QVariant>)), this, SLOT(dbgMsgError(QString, QList<QVariant>)));
84 connect(m_config
->pushButton
, SIGNAL(clicked()), this, SLOT(saveLog()));
87 DebugGadgetWidget::~DebugGadgetWidget()
92 void DebugGadgetWidget::dbgMsg(const QString
&level
, const QList
<QVariant
> &msgs
)
94 m_config
->plainTextEdit
->setTextColor(Qt::red
);
96 m_config
->plainTextEdit
->append(QString("%2[%0]%1").arg(level
).arg(msgs
[0].toString()).arg(QTime::currentTime().toString()));
98 QScrollBar
*sb
= m_config
->plainTextEdit
->verticalScrollBar();
99 sb
->setValue(sb
->maximum());
102 void DebugGadgetWidget::dbgMsgError(const QString
&level
, const QList
<QVariant
> &msgs
)
104 m_config
->plainTextEdit
->setTextColor(Qt::black
);
107 m_config
->plainTextEdit
->append(QString("%2[%0]%1").arg(level
).arg(msgs
[0].toString()).arg(QTime::currentTime().toString()));
109 QScrollBar
*sb
= m_config
->plainTextEdit
->verticalScrollBar();
110 sb
->setValue(sb
->maximum());
112 void DebugGadgetWidget::saveLog()
114 QString fileName
= QFileDialog::getSaveFileName(0, tr("Save log File As"), "");
116 if (fileName
.isEmpty()) {
120 QFile
file(fileName
);
121 if (file
.open(QIODevice::WriteOnly
) &&
122 (file
.write(m_config
->plainTextEdit
->toHtml().toLatin1()) != -1)) {
125 QMessageBox::critical(0,
127 tr("Unable to save log: ") + fileName
,