From decb99680198094d599fc6adbf3ada22ce69a10c Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 26 Jan 2014 16:30:08 +0100 Subject: [PATCH 1/4] OP-1198 allow GCS gadgets to store/restore individual state (needed for OP-1194) --- .../src/plugins/coreplugin/uavgadgetdecorator.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp index e4e33d07e..86536d988 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp @@ -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; } } + // store gadget individual state + qSettings->beginGroup("state"); + m_gadget->restoreState(qSettings); + qSettings->endGroup(); } From cdeebeebb44dcf8b8698d3489bb87f8f788e57a9 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 26 Jan 2014 16:54:24 +0100 Subject: [PATCH 2/4] OP-1194 scope gadget will now persistent plot and legend visibility state between runs +review OPReview --- .../src/plugins/scope/scopegadget.cpp | 18 ++-- .../src/plugins/scope/scopegadget.h | 11 ++- .../src/plugins/scope/scopegadgetwidget.cpp | 83 ++++++++++--------- .../src/plugins/scope/scopegadgetwidget.h | 7 ++ 4 files changed, 71 insertions(+), 48 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp index 798984ea5..2a6d13655 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp @@ -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 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); +} diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadget.h b/ground/openpilotgcs/src/plugins/scope/scopegadget.h index 8b06739b6..88b74acc5 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadget.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadget.h @@ -32,10 +32,10 @@ #include #include "scopegadgetwidget.h" -class IUAVGadget; -// class QList; 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 m_context; - - bool configLoaded; }; diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index 8418a1c42..1b4798dbf 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -25,8 +25,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#include #include "scopegadgetwidget.h" #include "utils/stylehelper.h" @@ -44,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -52,14 +51,10 @@ #include #include -// 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,38 @@ void ScopeGadgetWidget::clearCurvePlots() m_curvesData.clear(); } +void ScopeGadgetWidget::saveState(QSettings *qSettings) +{ + // plot state + int i = 1; + + foreach(PlotData * plotData, m_curvesData.values()) { + qSettings->setValue(QString("plot%1").arg(i), plotData->curve->isVisible()); + 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 +703,7 @@ void ScopeGadgetWidget::csvLoggingConnect() csvLoggingStart(); } } + void ScopeGadgetWidget::csvLoggingDisconnect() { m_csvLoggingHeaderSaved = 0; diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h index a7e57b65d..51bc653ed 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h @@ -41,6 +41,8 @@ #include #include +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; From 9e16e8f6a9025099a6f7741f8d67301448f0ad3e Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Thu, 30 Jan 2014 21:54:05 +0100 Subject: [PATCH 3/4] OP-1194 minor cleanups to scope gadget state persistence handling --- .../plugins/coreplugin/uavgadgetdecorator.cpp | 2 +- .../openpilotgcs/src/plugins/scope/scope.pro | 36 +++++++++++-------- .../src/plugins/scope/scopegadgetwidget.cpp | 5 ++- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp index 86536d988..e9111c1b4 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp @@ -138,7 +138,7 @@ void UAVGadgetDecorator::restoreState(QSettings *qSettings) break; } } - // store gadget individual state + // restore gadget individual state qSettings->beginGroup("state"); m_gadget->restoreState(qSettings); qSettings->endGroup(); diff --git a/ground/openpilotgcs/src/plugins/scope/scope.pro b/ground/openpilotgcs/src/plugins/scope/scope.pro index 7fef56df4..b95e23e6c 100644 --- a/ground/openpilotgcs/src/plugins/scope/scope.pro +++ b/ground/openpilotgcs/src/plugins/scope/scope.pro @@ -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 diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index 1b4798dbf..733068f0f 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -520,7 +520,10 @@ void ScopeGadgetWidget::saveState(QSettings *qSettings) int i = 1; foreach(PlotData * plotData, m_curvesData.values()) { - qSettings->setValue(QString("plot%1").arg(i), plotData->curve->isVisible()); + bool plotVisible = plotData->curve->isVisible(); + if (!plotVisible) { + qSettings->setValue(QString("plot%1").arg(i), plotVisible); + } i++; } // legend state From 7a6fcba12a8bd024359842863c37b769d70ef9c7 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Thu, 20 Mar 2014 01:46:38 +0100 Subject: [PATCH 4/4] OP-1194 uncrustified --- ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index 733068f0f..2762727bd 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -521,6 +521,7 @@ void ScopeGadgetWidget::saveState(QSettings *qSettings) foreach(PlotData * plotData, m_curvesData.values()) { bool plotVisible = plotData->curve->isVisible(); + if (!plotVisible) { qSettings->setValue(QString("plot%1").arg(i), plotVisible); }