1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Merge branch 'filnet/OP-1194_persist_scope_gadget_plot_and_legend_visibility_state' into next

This commit is contained in:
Philippe Renon 2014-03-20 01:49:21 +01:00
commit d5e9f42fd1
6 changed files with 105 additions and 62 deletions

View File

@ -121,6 +121,10 @@ void UAVGadgetDecorator::saveState(QSettings *qSettings)
if (m_activeConfiguration) {
qSettings->setValue("activeConfiguration", m_activeConfiguration->name());
}
// save gadget individual state
qSettings->beginGroup("state");
m_gadget->saveState(qSettings);
qSettings->endGroup();
}
void UAVGadgetDecorator::restoreState(QSettings *qSettings)
@ -134,4 +138,8 @@ void UAVGadgetDecorator::restoreState(QSettings *qSettings)
break;
}
}
// restore gadget individual state
qSettings->beginGroup("state");
m_gadget->restoreState(qSettings);
qSettings->endGroup();
}

View File

@ -1,22 +1,30 @@
TEMPLATE = lib
TARGET = ScopeGadget
DEFINES += SCOPE_LIBRARY
include(../../openpilotgcsplugin.pri)
include (scope_dependencies.pri)
HEADERS += scopeplugin.h \
HEADERS += \
scopeplugin.h \
plotdata.h \
scope_global.h
HEADERS += scopegadgetoptionspage.h
HEADERS += scopegadgetconfiguration.h
HEADERS += scopegadget.h
HEADERS += scopegadgetwidget.h
HEADERS += scopegadgetfactory.h
SOURCES += scopeplugin.cpp \
plotdata.cpp
SOURCES += scopegadgetoptionspage.cpp
SOURCES += scopegadgetconfiguration.cpp
SOURCES += scopegadget.cpp
SOURCES += scopegadgetfactory.cpp
SOURCES += scopegadgetwidget.cpp
scope_global.h \
scopegadgetoptionspage.h \
scopegadgetconfiguration.h \
scopegadget.h \
scopegadgetwidget.h \
scopegadgetfactory.h
SOURCES += \
scopeplugin.cpp \
plotdata.cpp \
scopegadgetoptionspage.cpp \
scopegadgetconfiguration.cpp \
scopegadget.cpp \
scopegadgetfactory.cpp \
scopegadgetwidget.cpp
OTHER_FILES += ScopeGadget.pluginspec
FORMS += scopegadgetoptionspage.ui

View File

@ -25,7 +25,6 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "scopeplugin.h"
#include "scopegadget.h"
#include "scopegadgetconfiguration.h"
#include "scopegadgetwidget.h"
@ -33,9 +32,7 @@
#include <qcolor.h>
ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget),
configLoaded(false)
IUAVGadget(classId, parent), m_widget(widget)
{}
void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
@ -86,10 +83,19 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
}
/**
Scope gadget destructor: should delete the associated
scope gadget widget too!
Scope gadget destructor: should delete the associated scope gadget widget too!
*/
ScopeGadget::~ScopeGadget()
{
delete m_widget;
}
void ScopeGadget::saveState(QSettings *qSettings)
{
m_widget->saveState(qSettings);
}
void ScopeGadget::restoreState(QSettings *qSettings)
{
m_widget->restoreState(qSettings);
}

View File

@ -32,10 +32,10 @@
#include <coreplugin/iuavgadget.h>
#include "scopegadgetwidget.h"
class IUAVGadget;
// class QList<int>;
class QWidget;
class QString;
class QSettings;
class IUAVGadget;
class ScopeGadgetWidget;
using namespace Core;
@ -52,20 +52,23 @@ public:
{
return m_context;
}
QWidget *widget()
{
return m_widget;
}
QString contextHelpId() const
{
return QString();
}
void saveState(QSettings *qSettings);
void restoreState(QSettings *qSettings);
private:
ScopeGadgetWidget *m_widget;
QList<int> m_context;
bool configLoaded;
};

View File

@ -25,8 +25,6 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <QDir>
#include "scopegadgetwidget.h"
#include "utils/stylehelper.h"
@ -44,6 +42,7 @@
#include <iostream>
#include <math.h>
#include <QDebug>
#include <QDir>
#include <QColor>
#include <QStringList>
#include <QWidget>
@ -52,14 +51,10 @@
#include <QMutexLocker>
#include <QWheelEvent>
// using namespace Core;
// ******************************************************************
ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
{
setMouseTracking(true);
// canvas()->setMouseTracking(true);
// canvas()->setMouseTracking(true);
// Setup the timer that replots data
replotTimer = new QTimer(this);
@ -109,8 +104,6 @@ ScopeGadgetWidget::~ScopeGadgetWidget()
clearCurvePlots();
}
// ******************************************************************
void ScopeGadgetWidget::mousePressEvent(QMouseEvent *e)
{
QwtPlot::mousePressEvent(e);
@ -214,7 +207,6 @@ void ScopeGadgetWidget::deleteLegend()
disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0);
insertLegend(NULL, QwtPlot::TopLegend);
// insertLegend(NULL, QwtPlot::ExternalLegend);
}
void ScopeGadgetWidget::addLegend()
@ -227,27 +219,19 @@ void ScopeGadgetWidget::addLegend()
QwtLegend *legend = new QwtLegend();
legend->setItemMode(QwtLegend::CheckableItem);
legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
legend->setToolTip(tr("Click legend to show/hide scope trace"));
legend->setToolTip(tr("Click legend to show/hide scope trace.\nDouble click legend or plot to show/hide legend."));
// set colors
QPalette pal = legend->palette();
pal.setColor(legend->backgroundRole(), QColor(100, 100, 100)); // background colour
// pal.setColor(legend->backgroundRole(), Qt::transparent); // background colour
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
pal.setColor(QPalette::Text, QColor(0, 0, 0)); // text colour
pal.setColor(legend->backgroundRole(), QColor(100, 100, 100));
pal.setColor(QPalette::Text, QColor(0, 0, 0));
legend->setPalette(pal);
insertLegend(legend, QwtPlot::TopLegend);
// insertLegend(legend, QwtPlot::ExternalLegend);
//// Show a legend at the bottom
// QwtLegend *legend = new QwtLegend();
// legend->setItemMode(QwtLegend::CheckableItem);
// legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
// insertLegend(legend, QwtPlot::BottomLegend);
// Update the checked/unchecked state of the legend items
// -> this is necessary when hiding a legend where some plots are
// not visible, and the un-hiding it.
// not visible, and then un-hiding it.
foreach(QwtPlotItem * item, this->itemList()) {
bool on = item->isVisible();
QWidget *w = legend->find(item);
@ -269,15 +253,6 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
setMinimumSize(64, 64);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
// setMargin(1);
// QPalette pal = palette();
// QPalette::ColorRole cr = backgroundRole();
// pal.setColor(cr, QColor(128, 128, 128)); // background colour
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
// setPalette(pal);
// setCanvasBackground(Utils::StyleHelper::baseColor());
setCanvasBackground(QColor(64, 64, 64));
// Add grid lines
@ -287,9 +262,6 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
grid->setPen(QPen(Qt::darkGray, 1, Qt::DotLine));
grid->attach(this);
// Add the legend
addLegend();
// Only start the timer if we are already connected
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
if (cm->getCurrentConnection() && replotTimer) {
@ -304,9 +276,11 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
void ScopeGadgetWidget::showCurve(QwtPlotItem *item, bool on)
{
item->setVisible(!on);
QWidget *w = legend()->find(item);
if (w && w->inherits("QwtLegendItem")) {
((QwtLegendItem *)w)->setChecked(on);
if (legend()) {
QWidget *w = legend()->find(item);
if (w && w->inherits("QwtLegendItem")) {
((QwtLegendItem *)w)->setChecked(on);
}
}
mutex.lock();
@ -540,6 +514,42 @@ void ScopeGadgetWidget::clearCurvePlots()
m_curvesData.clear();
}
void ScopeGadgetWidget::saveState(QSettings *qSettings)
{
// plot state
int i = 1;
foreach(PlotData * plotData, m_curvesData.values()) {
bool plotVisible = plotData->curve->isVisible();
if (!plotVisible) {
qSettings->setValue(QString("plot%1").arg(i), plotVisible);
}
i++;
}
// legend state
qSettings->setValue("legendVisible", legend() != NULL);
}
void ScopeGadgetWidget::restoreState(QSettings *qSettings)
{
// plot state
int i = 1;
foreach(PlotData * plotData, m_curvesData.values()) {
bool visible = qSettings->value(QString("plot%1").arg(i), true).toBool();
showCurve(plotData->curve, !visible);
i++;
}
// legend state
bool legendVisible = qSettings->value("legendVisible", true).toBool();
if (legendVisible) {
addLegend();
} else {
deleteLegend();
}
}
/*
int csvLoggingEnable;
@ -697,6 +707,7 @@ void ScopeGadgetWidget::csvLoggingConnect()
csvLoggingStart();
}
}
void ScopeGadgetWidget::csvLoggingDisconnect()
{
m_csvLoggingHeaderSaved = 0;

View File

@ -41,6 +41,8 @@
#include <QVector>
#include <QMutex>
class QSettings;
/*!
\brief This class is used to render the time values on the horizontal axis for the
ChronoPlot.
@ -95,9 +97,14 @@ public:
void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int meanSamples = 1,
QString mathFunction = "None", QPen pen = QPen(Qt::black), bool antialiased = true);
void clearCurvePlots();
void saveState(QSettings *qSettings);
void restoreState(QSettings *qSettings);
int csvLoggingStart();
int csvLoggingStop();
void csvLoggingSetName(QString);
void setLoggingEnabled(bool value)
{
m_csvLoggingEnabled = value;