1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

GCS/consolegadget: Addition of primitive console gadget that displays log messages.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@546 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-04-25 18:01:13 +00:00 committed by ephy
parent c51c7f72e7
commit 8f5ecf399d
12 changed files with 626 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<plugin name="ConsoleGadget" version="1.0.0" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright>
<license>The GNU Public License (GPL) Version 3</license>
<description>Console gadget</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,51 @@
/**
******************************************************************************
*
* @file consolegadget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "consolegadget.h"
#include "consolegadgetwidget.h"
#include "texteditloggerengine.h"
ConsoleGadget::ConsoleGadget(QString classId, ConsoleGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
m_logger = new TextEditLoggerEngine(widget);
bool suitableName = false;
int i = 0;
QString loggerName;
while (!suitableName) {
loggerName = "TextEditLogger" + QVariant(i).toString();
if (!qxtLog->isLoggerEngine(loggerName))
suitableName = true;
++i;
}
qxtLog->addLoggerEngine(loggerName, m_logger);
}
ConsoleGadget::~ConsoleGadget()
{
qxtLog->removeLoggerEngine(m_logger);
}

View File

@ -0,0 +1,59 @@
/**
******************************************************************************
*
* @file consolegadget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONSOLEGADGET_H_
#define CONSOLEGADGET_H_
#include <coreplugin/iuavgadget.h>
namespace Core {
class IUAVGadget;
}
class ConsoleGadgetWidget;
class TextEditLoggerEngine;
using namespace Core;
class ConsoleGadget : public Core::IUAVGadget
{
Q_OBJECT
public:
ConsoleGadget(QString classId, ConsoleGadgetWidget *widget, QWidget *parent = 0);
~ConsoleGadget();
QList<int> context() const { return m_context; }
QWidget *widget() { return m_widget; }
QString contextHelpId() const { return QString(); }
private:
QWidget *m_widget;
QList<int> m_context;
TextEditLoggerEngine *m_logger;
};
#endif // CONSOLEGADGET_H_

View File

@ -0,0 +1,15 @@
TEMPLATE = lib
TARGET = ConsoleGadget
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
HEADERS += consoleplugin.h \
texteditloggerengine.h
HEADERS += consolegadget.h
HEADERS += consolegadgetwidget.h
HEADERS += consolegadgetfactory.h
SOURCES += consoleplugin.cpp \
texteditloggerengine.cpp
SOURCES += consolegadget.cpp
SOURCES += consolegadgetfactory.cpp
SOURCES += consolegadgetwidget.cpp
OTHER_FILES += ConsoleGadget.pluginspec

View File

@ -0,0 +1,47 @@
/**
******************************************************************************
*
* @file consolegadgetfactory.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "consolegadgetfactory.h"
#include "consolegadgetwidget.h"
#include "consolegadget.h"
#include <coreplugin/iuavgadget.h>
ConsoleGadgetFactory::ConsoleGadgetFactory(QObject *parent) :
IUAVGadgetFactory(QString("ConsoleGadget"),
tr("Console"),
parent)
{
}
ConsoleGadgetFactory::~ConsoleGadgetFactory()
{
}
IUAVGadget* ConsoleGadgetFactory::createGadget(QWidget *parent) {
ConsoleGadgetWidget* gadgetWidget = new ConsoleGadgetWidget(parent);
return new ConsoleGadget(QString("ConsoleGadget"), gadgetWidget, parent);
}

View File

@ -0,0 +1,50 @@
/**
******************************************************************************
*
* @file consolegadgetfactory.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONSOLEGADGETFACTORY_H_
#define CONSOLEGADGETFACTORY_H_
#include <coreplugin/iuavgadgetfactory.h>
namespace Core {
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class ConsoleGadgetFactory : public IUAVGadgetFactory
{
Q_OBJECT
public:
ConsoleGadgetFactory(QObject *parent = 0);
~ConsoleGadgetFactory();
IUAVGadget *createGadget(QWidget *parent);
};
#endif // CONSOLEGADGETFACTORY_H_

View File

@ -0,0 +1,44 @@
/**
******************************************************************************
*
* @file consolegadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "consolegadgetwidget.h"
#include "qxtlogger.h"
#include <QDebug>
#include <QtGui/QTextEdit>
ConsoleGadgetWidget::ConsoleGadgetWidget(QWidget *parent) : QTextEdit(parent)
{
setMinimumSize(64,64);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setReadOnly(true);
}
ConsoleGadgetWidget::~ConsoleGadgetWidget()
{
// Do nothing
}

View File

@ -0,0 +1,44 @@
/**
******************************************************************************
*
* @file consolegadgetwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONSOLEGADGETWIDGET_H_
#define CONSOLEGADGETWIDGET_H_
#include <QtGui/QTextEdit>
class ConsoleGadgetWidget : public QTextEdit
{
Q_OBJECT
public:
ConsoleGadgetWidget(QWidget *parent = 0);
~ConsoleGadgetWidget();
private:
};
#endif /* CONSOLEGADGETWIDGET_H_ */

View File

@ -0,0 +1,65 @@
/**
******************************************************************************
*
* @file consoleplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "consoleplugin.h"
#include "consolegadgetfactory.h"
#include <QDebug>
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
ConsolePlugin::ConsolePlugin()
{
// Do nothing
}
ConsolePlugin::~ConsolePlugin()
{
// Do nothing
}
bool ConsolePlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
mf = new ConsoleGadgetFactory(this);
addAutoReleasedObject(mf);
return true;
}
void ConsolePlugin::extensionsInitialized()
{
// Do nothing
}
void ConsolePlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(ConsolePlugin)

View File

@ -0,0 +1,47 @@
/**
******************************************************************************
*
* @file consoleplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONSOLEPLUGIN_H_
#define CONSOLEPLUGIN_H_
#include <extensionsystem/iplugin.h>
class ConsoleGadgetFactory;
class ConsolePlugin : public ExtensionSystem::IPlugin
{
public:
ConsolePlugin();
~ConsolePlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private:
ConsoleGadgetFactory *mf;
};
#endif /* CONSOLEPLUGIN_H_ */

View File

@ -0,0 +1,137 @@
/**
******************************************************************************
*
* @file texteditloggerengine.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Qxt Foundation http://www.libqxt.org Copyright (C)
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "texteditloggerengine.h"
#include <QTime>
#include <QtGui/QTextEdit>
#include <QtGui/QScrollBar>
#include <QObject>
#define QXT_REQUIRED_LEVELS (QxtLogger::WarningLevel | QxtLogger::ErrorLevel | QxtLogger::CriticalLevel | QxtLogger::FatalLevel)
TextEditLoggerEngine::TextEditLoggerEngine(QTextEdit *textEdit) : m_textEdit(textEdit)
{
#ifndef QT_NO_DEBUG
setLogLevelsEnabled(QXT_REQUIRED_LEVELS);
#else
setLogLevelsEnabled(QXT_REQUIRED_LEVELS | QxtLogger::DebugLevel);
#endif
enableLogging();
}
TextEditLoggerEngine::~TextEditLoggerEngine()
{
}
void TextEditLoggerEngine::initLoggerEngine()
{
return; // Should work out of the box!
}
void TextEditLoggerEngine::killLoggerEngine()
{
return; // I do nothing.
}
bool TextEditLoggerEngine::isInitialized() const
{
return true;
}
void TextEditLoggerEngine::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable)
{
QxtLoggerEngine::setLogLevelsEnabled(level | QXT_REQUIRED_LEVELS, enable);
if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QXT_REQUIRED_LEVELS);
}
void TextEditLoggerEngine::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> &msgs)
{
switch (level)
{
case QxtLogger::ErrorLevel:
writeToTextEdit("Error", msgs, Qt::red);
break;
case QxtLogger::WarningLevel:
writeToTextEdit("Warning", msgs, Qt::red);
break;
case QxtLogger::CriticalLevel:
writeToTextEdit("Critical", msgs, Qt::red);
break;
case QxtLogger::FatalLevel:
writeToTextEdit("!!FATAL!!", msgs, Qt::red);
break;
case QxtLogger::TraceLevel:
writeToTextEdit("Trace", msgs, Qt::blue);
break;
case QxtLogger::DebugLevel:
writeToTextEdit("DEBUG", msgs, Qt::blue);
break;
case QxtLogger::InfoLevel:
writeToTextEdit("INFO", msgs);
break;
default:
writeToTextEdit("", msgs);
break;
}
}
void TextEditLoggerEngine::writeToTextEdit(const QString& level, const QList<QVariant> &msgs, QColor color)
{
/* Message format...
[time] [error level] First message.....
second message
third message
*/
if (msgs.isEmpty())
return;
QScrollBar *sb = m_textEdit->verticalScrollBar();
bool scroll = sb->value() == sb->maximum();
QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] [" + level + "] ";
QString padding;
QString appendText;
appendText.append(header);
for (int i = 0; i < header.size(); i++) padding.append(' ');
int count = 0;
Q_FOREACH(const QVariant& out, msgs)
{
if (!out.isNull())
{
if (count != 0)
appendText.append(padding);
appendText.append(out.toString());
}
count++;
}
Q_ASSERT(m_textEdit);
QTextCharFormat format = m_textEdit->currentCharFormat();
format.setForeground(QBrush(color));
m_textEdit->setCurrentCharFormat(format);
m_textEdit->append(appendText);
if (scroll)
sb->setValue(sb->maximum());
}

View File

@ -0,0 +1,57 @@
/**
******************************************************************************
*
* @file texteditloggerengine.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Qxt Foundation http://www.libqxt.org Copyright (C)
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup consolegadget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TEXTEDITLOGGERENGINE_H
#define TEXTEDITLOGGERENGINE_H
#include "qxtloggerengine.h"
#include "qxtglobal.h"
#include <QtGui/QColor>
class QTextEdit;
class TextEditLoggerEngine : public QxtLoggerEngine
{
public:
TextEditLoggerEngine(QTextEdit *textEdit);
~TextEditLoggerEngine();
void initLoggerEngine();
void killLoggerEngine();
void writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> &messages);
void setLogLevelEnabled(QxtLogger::LogLevels level, bool enable = true);
bool isInitialized() const;
private:
virtual void writeToTextEdit(const QString& str_level, const QList<QVariant> &msgs, QColor color = QColor(0,0,0));
QTextEdit *m_textEdit;
};
#endif // TEXTEDITLOGGERENGINE_H