mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
Merge branch 'filnet/OP-1194_persist_scope_gadget_plot_and_legend_visibility_state' into next
This commit is contained in:
commit
d5e9f42fd1
@ -121,6 +121,10 @@ void UAVGadgetDecorator::saveState(QSettings *qSettings)
|
|||||||
if (m_activeConfiguration) {
|
if (m_activeConfiguration) {
|
||||||
qSettings->setValue("activeConfiguration", m_activeConfiguration->name());
|
qSettings->setValue("activeConfiguration", m_activeConfiguration->name());
|
||||||
}
|
}
|
||||||
|
// save gadget individual state
|
||||||
|
qSettings->beginGroup("state");
|
||||||
|
m_gadget->saveState(qSettings);
|
||||||
|
qSettings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVGadgetDecorator::restoreState(QSettings *qSettings)
|
void UAVGadgetDecorator::restoreState(QSettings *qSettings)
|
||||||
@ -134,4 +138,8 @@ void UAVGadgetDecorator::restoreState(QSettings *qSettings)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// restore gadget individual state
|
||||||
|
qSettings->beginGroup("state");
|
||||||
|
m_gadget->restoreState(qSettings);
|
||||||
|
qSettings->endGroup();
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,30 @@
|
|||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
TARGET = ScopeGadget
|
TARGET = ScopeGadget
|
||||||
|
|
||||||
DEFINES += SCOPE_LIBRARY
|
DEFINES += SCOPE_LIBRARY
|
||||||
|
|
||||||
include(../../openpilotgcsplugin.pri)
|
include(../../openpilotgcsplugin.pri)
|
||||||
include (scope_dependencies.pri)
|
include (scope_dependencies.pri)
|
||||||
HEADERS += scopeplugin.h \
|
|
||||||
|
HEADERS += \
|
||||||
|
scopeplugin.h \
|
||||||
plotdata.h \
|
plotdata.h \
|
||||||
scope_global.h
|
scope_global.h \
|
||||||
HEADERS += scopegadgetoptionspage.h
|
scopegadgetoptionspage.h \
|
||||||
HEADERS += scopegadgetconfiguration.h
|
scopegadgetconfiguration.h \
|
||||||
HEADERS += scopegadget.h
|
scopegadget.h \
|
||||||
HEADERS += scopegadgetwidget.h
|
scopegadgetwidget.h \
|
||||||
HEADERS += scopegadgetfactory.h
|
scopegadgetfactory.h
|
||||||
SOURCES += scopeplugin.cpp \
|
|
||||||
plotdata.cpp
|
SOURCES += \
|
||||||
SOURCES += scopegadgetoptionspage.cpp
|
scopeplugin.cpp \
|
||||||
SOURCES += scopegadgetconfiguration.cpp
|
plotdata.cpp \
|
||||||
SOURCES += scopegadget.cpp
|
scopegadgetoptionspage.cpp \
|
||||||
SOURCES += scopegadgetfactory.cpp
|
scopegadgetconfiguration.cpp \
|
||||||
SOURCES += scopegadgetwidget.cpp
|
scopegadget.cpp \
|
||||||
|
scopegadgetfactory.cpp \
|
||||||
|
scopegadgetwidget.cpp
|
||||||
|
|
||||||
OTHER_FILES += ScopeGadget.pluginspec
|
OTHER_FILES += ScopeGadget.pluginspec
|
||||||
|
|
||||||
FORMS += scopegadgetoptionspage.ui
|
FORMS += scopegadgetoptionspage.ui
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "scopeplugin.h"
|
|
||||||
#include "scopegadget.h"
|
#include "scopegadget.h"
|
||||||
#include "scopegadgetconfiguration.h"
|
#include "scopegadgetconfiguration.h"
|
||||||
#include "scopegadgetwidget.h"
|
#include "scopegadgetwidget.h"
|
||||||
@ -33,9 +32,7 @@
|
|||||||
#include <qcolor.h>
|
#include <qcolor.h>
|
||||||
|
|
||||||
ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) :
|
ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) :
|
||||||
IUAVGadget(classId, parent),
|
IUAVGadget(classId, parent), m_widget(widget)
|
||||||
m_widget(widget),
|
|
||||||
configLoaded(false)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
|
void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
|
||||||
@ -86,10 +83,19 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Scope gadget destructor: should delete the associated
|
Scope gadget destructor: should delete the associated scope gadget widget too!
|
||||||
scope gadget widget too!
|
|
||||||
*/
|
*/
|
||||||
ScopeGadget::~ScopeGadget()
|
ScopeGadget::~ScopeGadget()
|
||||||
{
|
{
|
||||||
delete m_widget;
|
delete m_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScopeGadget::saveState(QSettings *qSettings)
|
||||||
|
{
|
||||||
|
m_widget->saveState(qSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScopeGadget::restoreState(QSettings *qSettings)
|
||||||
|
{
|
||||||
|
m_widget->restoreState(qSettings);
|
||||||
|
}
|
||||||
|
@ -32,10 +32,10 @@
|
|||||||
#include <coreplugin/iuavgadget.h>
|
#include <coreplugin/iuavgadget.h>
|
||||||
#include "scopegadgetwidget.h"
|
#include "scopegadgetwidget.h"
|
||||||
|
|
||||||
class IUAVGadget;
|
|
||||||
// class QList<int>;
|
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class QString;
|
class QString;
|
||||||
|
class QSettings;
|
||||||
|
class IUAVGadget;
|
||||||
class ScopeGadgetWidget;
|
class ScopeGadgetWidget;
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
@ -52,20 +52,23 @@ public:
|
|||||||
{
|
{
|
||||||
return m_context;
|
return m_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *widget()
|
QWidget *widget()
|
||||||
{
|
{
|
||||||
return m_widget;
|
return m_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString contextHelpId() const
|
QString contextHelpId() const
|
||||||
{
|
{
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void saveState(QSettings *qSettings);
|
||||||
|
void restoreState(QSettings *qSettings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScopeGadgetWidget *m_widget;
|
ScopeGadgetWidget *m_widget;
|
||||||
QList<int> m_context;
|
QList<int> m_context;
|
||||||
|
|
||||||
bool configLoaded;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include "scopegadgetwidget.h"
|
#include "scopegadgetwidget.h"
|
||||||
#include "utils/stylehelper.h"
|
#include "utils/stylehelper.h"
|
||||||
|
|
||||||
@ -44,6 +42,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -52,14 +51,10 @@
|
|||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
|
||||||
// using namespace Core;
|
|
||||||
|
|
||||||
// ******************************************************************
|
|
||||||
|
|
||||||
ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
|
ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
|
||||||
{
|
{
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
// canvas()->setMouseTracking(true);
|
// canvas()->setMouseTracking(true);
|
||||||
|
|
||||||
// Setup the timer that replots data
|
// Setup the timer that replots data
|
||||||
replotTimer = new QTimer(this);
|
replotTimer = new QTimer(this);
|
||||||
@ -109,8 +104,6 @@ ScopeGadgetWidget::~ScopeGadgetWidget()
|
|||||||
clearCurvePlots();
|
clearCurvePlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ******************************************************************
|
|
||||||
|
|
||||||
void ScopeGadgetWidget::mousePressEvent(QMouseEvent *e)
|
void ScopeGadgetWidget::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
QwtPlot::mousePressEvent(e);
|
QwtPlot::mousePressEvent(e);
|
||||||
@ -214,7 +207,6 @@ void ScopeGadgetWidget::deleteLegend()
|
|||||||
disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0);
|
disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0);
|
||||||
|
|
||||||
insertLegend(NULL, QwtPlot::TopLegend);
|
insertLegend(NULL, QwtPlot::TopLegend);
|
||||||
// insertLegend(NULL, QwtPlot::ExternalLegend);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScopeGadgetWidget::addLegend()
|
void ScopeGadgetWidget::addLegend()
|
||||||
@ -227,27 +219,19 @@ void ScopeGadgetWidget::addLegend()
|
|||||||
QwtLegend *legend = new QwtLegend();
|
QwtLegend *legend = new QwtLegend();
|
||||||
legend->setItemMode(QwtLegend::CheckableItem);
|
legend->setItemMode(QwtLegend::CheckableItem);
|
||||||
legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
|
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();
|
QPalette pal = legend->palette();
|
||||||
pal.setColor(legend->backgroundRole(), QColor(100, 100, 100)); // background colour
|
pal.setColor(legend->backgroundRole(), QColor(100, 100, 100));
|
||||||
// pal.setColor(legend->backgroundRole(), Qt::transparent); // background colour
|
pal.setColor(QPalette::Text, QColor(0, 0, 0));
|
||||||
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
|
|
||||||
pal.setColor(QPalette::Text, QColor(0, 0, 0)); // text colour
|
|
||||||
legend->setPalette(pal);
|
legend->setPalette(pal);
|
||||||
|
|
||||||
insertLegend(legend, QwtPlot::TopLegend);
|
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
|
// Update the checked/unchecked state of the legend items
|
||||||
// -> this is necessary when hiding a legend where some plots are
|
// -> 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()) {
|
foreach(QwtPlotItem * item, this->itemList()) {
|
||||||
bool on = item->isVisible();
|
bool on = item->isVisible();
|
||||||
QWidget *w = legend->find(item);
|
QWidget *w = legend->find(item);
|
||||||
@ -269,15 +253,6 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
|
|||||||
setMinimumSize(64, 64);
|
setMinimumSize(64, 64);
|
||||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
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));
|
setCanvasBackground(QColor(64, 64, 64));
|
||||||
|
|
||||||
// Add grid lines
|
// Add grid lines
|
||||||
@ -287,9 +262,6 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
|
|||||||
grid->setPen(QPen(Qt::darkGray, 1, Qt::DotLine));
|
grid->setPen(QPen(Qt::darkGray, 1, Qt::DotLine));
|
||||||
grid->attach(this);
|
grid->attach(this);
|
||||||
|
|
||||||
// Add the legend
|
|
||||||
addLegend();
|
|
||||||
|
|
||||||
// Only start the timer if we are already connected
|
// Only start the timer if we are already connected
|
||||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||||
if (cm->getCurrentConnection() && replotTimer) {
|
if (cm->getCurrentConnection() && replotTimer) {
|
||||||
@ -304,10 +276,12 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
|
|||||||
void ScopeGadgetWidget::showCurve(QwtPlotItem *item, bool on)
|
void ScopeGadgetWidget::showCurve(QwtPlotItem *item, bool on)
|
||||||
{
|
{
|
||||||
item->setVisible(!on);
|
item->setVisible(!on);
|
||||||
|
if (legend()) {
|
||||||
QWidget *w = legend()->find(item);
|
QWidget *w = legend()->find(item);
|
||||||
if (w && w->inherits("QwtLegendItem")) {
|
if (w && w->inherits("QwtLegendItem")) {
|
||||||
((QwtLegendItem *)w)->setChecked(on);
|
((QwtLegendItem *)w)->setChecked(on);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
replot();
|
replot();
|
||||||
@ -540,6 +514,42 @@ void ScopeGadgetWidget::clearCurvePlots()
|
|||||||
m_curvesData.clear();
|
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;
|
int csvLoggingEnable;
|
||||||
@ -697,6 +707,7 @@ void ScopeGadgetWidget::csvLoggingConnect()
|
|||||||
csvLoggingStart();
|
csvLoggingStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScopeGadgetWidget::csvLoggingDisconnect()
|
void ScopeGadgetWidget::csvLoggingDisconnect()
|
||||||
{
|
{
|
||||||
m_csvLoggingHeaderSaved = 0;
|
m_csvLoggingHeaderSaved = 0;
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
|
class QSettings;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief This class is used to render the time values on the horizontal axis for the
|
\brief This class is used to render the time values on the horizontal axis for the
|
||||||
ChronoPlot.
|
ChronoPlot.
|
||||||
@ -95,9 +97,14 @@ public:
|
|||||||
void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int meanSamples = 1,
|
void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int meanSamples = 1,
|
||||||
QString mathFunction = "None", QPen pen = QPen(Qt::black), bool antialiased = true);
|
QString mathFunction = "None", QPen pen = QPen(Qt::black), bool antialiased = true);
|
||||||
void clearCurvePlots();
|
void clearCurvePlots();
|
||||||
|
|
||||||
|
void saveState(QSettings *qSettings);
|
||||||
|
void restoreState(QSettings *qSettings);
|
||||||
|
|
||||||
int csvLoggingStart();
|
int csvLoggingStart();
|
||||||
int csvLoggingStop();
|
int csvLoggingStop();
|
||||||
void csvLoggingSetName(QString);
|
void csvLoggingSetName(QString);
|
||||||
|
|
||||||
void setLoggingEnabled(bool value)
|
void setLoggingEnabled(bool value)
|
||||||
{
|
{
|
||||||
m_csvLoggingEnabled = value;
|
m_csvLoggingEnabled = value;
|
||||||
|
Loading…
Reference in New Issue
Block a user