OP-1900 have path_progress updated correctly for leg_remaining and error_below end...
[librepilot.git] / ground / openpilotgcs / src / plugins / debuggadget / debuggadgetwidget.cpp
blob1958f3d0ec7f8c709b1b054e78590417779e76a9
1 /**
2 ******************************************************************************
4 * @file debuggadgetwidget.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup DebugGadgetPlugin Debug Gadget Plugin
9 * @{
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
21 * for more details.
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"
29 #include <QDebug>
30 #include <QStringList>
31 #include <QWidget>
32 #include <QTextEdit>
33 #include <QVBoxLayout>
34 #include <QPushButton>
35 #include "debugengine.h"
36 #include <QFile>
37 #include <QFileDialog>
38 #include <QMessageBox>
39 #include <QScrollBar>
40 #include <QTime>
42 QPointer<QTextBrowser> m_textedit;
44 void DebugGadgetWidget::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
46 Q_UNUSED(context);
47 QString txt;
48 QColor color = Qt::black;
50 switch (type) {
51 case QtDebugMsg:
52 txt = QString("Debug: %1").arg(msg);
53 color = Qt::black;
54 break;
55 case QtWarningMsg:
56 txt = QString("Warning: %1").arg(msg);
57 color = Qt::red;
58 break;
59 case QtCriticalMsg:
60 txt = QString("Critical: %1").arg(msg);
61 color = Qt::red;
62 break;
63 case QtFatalMsg:
64 txt = QString("Fatal: %1").arg(msg);
65 abort();
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()
89 // Do nothing
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()) {
117 return;
120 QFile file(fileName);
121 if (file.open(QIODevice::WriteOnly) &&
122 (file.write(m_config->plainTextEdit->toHtml().toLatin1()) != -1)) {
123 file.close();
124 } else {
125 QMessageBox::critical(0,
126 tr("Log Save"),
127 tr("Unable to save log: ") + fileName,
128 QMessageBox::Ok);
129 return;