From 6c476d2a58bd6b4582eb4e89c25c7ad5bc12c494 Mon Sep 17 00:00:00 2001 From: m_thread Date: Fri, 14 Nov 2014 14:18:46 +0100 Subject: [PATCH 1/3] OP-1611 Added context menu to Scope widget --- .../src/plugins/scope/plotdata.cpp | 17 +++++++ .../openpilotgcs/src/plugins/scope/plotdata.h | 1 + .../src/plugins/scope/scopegadget.cpp | 1 + .../src/plugins/scope/scopegadgetfactory.cpp | 1 - .../src/plugins/scope/scopegadgetwidget.cpp | 49 +++++++++++++++++++ .../src/plugins/scope/scopegadgetwidget.h | 6 +++ 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp index 10981d994..b930e3cbd 100644 --- a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp +++ b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp @@ -93,6 +93,23 @@ void PlotData::updatePlotData() m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries); } +void PlotData::clear() +{ + m_meanSum = 0.0f; + m_correctionSum = 0.0f; + m_correctionCount = 0; + m_xDataEntries.clear(); + m_yDataEntries.clear(); + while (!m_enumMarkerList.isEmpty()) { + QwtPlotMarker *marker = m_enumMarkerList.takeFirst(); + marker->detach(); + delete marker; + } + if (wantsInitialData()) { + append(m_object); + } +} + bool PlotData::hasData() const { if (!m_isEnumPlot) { diff --git a/ground/openpilotgcs/src/plugins/scope/plotdata.h b/ground/openpilotgcs/src/plugins/scope/plotdata.h index c180157d4..07ae1afce 100644 --- a/ground/openpilotgcs/src/plugins/scope/plotdata.h +++ b/ground/openpilotgcs/src/plugins/scope/plotdata.h @@ -93,6 +93,7 @@ public: virtual void removeStaleData() = 0; void updatePlotData(); + void clear(); bool hasData() const; QString lastDataAsString(); diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp index 6a91fa5e4..e5b36d170 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp @@ -47,6 +47,7 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config) ScopeGadgetConfiguration *sgConfig = qobject_cast(config); ScopeGadgetWidget *widget = qobject_cast(m_widget); + widget->setName(config->name()); widget->setPlotDataSize(sgConfig->dataSize()); widget->setRefreshInterval(sgConfig->refreshInterval()); diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetfactory.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetfactory.cpp index df75fe0a5..63551f043 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetfactory.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetfactory.cpp @@ -50,7 +50,6 @@ void ScopeGadgetFactory::startPlotting() emit onStartPlotting(); } - Core::IUAVGadget *ScopeGadgetFactory::createGadget(QWidget *parent) { ScopeGadgetWidget *gadgetWidget = new ScopeGadgetWidget(parent); diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index 6a2c22ee7..0f5f00d69 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -33,6 +33,7 @@ #include "uavobject.h" #include "coreplugin/icore.h" #include "coreplugin/connectionmanager.h" +#include #include "qwt/src/qwt_plot_curve.h" #include "qwt/src/qwt_plot_grid.h" @@ -48,6 +49,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -88,6 +93,9 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent), // Listen to autopilot connection events connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(csvLoggingDisconnect())); connect(cm, SIGNAL(deviceConnected(QIODevice *)), this, SLOT(csvLoggingConnect())); + + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, SIGNAL(customContextMenuRequested(const QPoint & )), this, SLOT(popUpMenu(const QPoint &))); } ScopeGadgetWidget::~ScopeGadgetWidget() @@ -624,3 +632,44 @@ void ScopeGadgetWidget::csvLoggingDisconnect() csvLoggingStop(); } } + +void ScopeGadgetWidget::popUpMenu(const QPoint &mousePosition) +{ + Q_UNUSED(mousePosition); + + QMenu menu; + QAction * action = menu.addAction(tr("Clear")); + connect(action, &QAction::triggered, this, &ScopeGadgetWidget::clearPlot); + action = menu.addAction(tr("Copy to Clipboard")); + connect(action, &QAction::triggered, this, &ScopeGadgetWidget::copyToClipboardAsImage); + menu.addSeparator(); + action = menu.addAction(tr("Options...")); + connect(action, &QAction::triggered, this, &ScopeGadgetWidget::showOptionDialog); + menu.exec(QCursor::pos()); +} + +void ScopeGadgetWidget::clearPlot() +{ + m_mutex.lock(); + foreach (PlotData * plot, m_curvesData.values()) { + plot->clear(); + } + m_mutex.unlock(); + replot(); +} + +void ScopeGadgetWidget::copyToClipboardAsImage() +{ + QPixmap pixmap = QWidget::grab(); + if(pixmap.isNull()){ + qDebug("Failed to capture the plot"); + return; + } + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setPixmap(pixmap); +} + +void ScopeGadgetWidget::showOptionDialog() +{ + Core::ICore::instance()->showOptionsDialog("ScopeGadget", m_name); +} diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h index cf725f46e..1b8302055 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h @@ -69,6 +69,7 @@ public: ScopeGadgetWidget(QWidget *parent = 0); ~ScopeGadgetWidget(); + void setName (QString name) { m_name = name; } void setupSequentialPlot(); void setupChronoPlot(); void setupUAVObjectPlot(); @@ -137,12 +138,17 @@ private slots: void stopPlotting(); void csvLoggingConnect(); void csvLoggingDisconnect(); + void popUpMenu(const QPoint &mousePosition); + void clearPlot(); + void copyToClipboardAsImage(); + void showOptionDialog(); private: void preparePlot(PlotType plotType); void setupExamplePlot(); + QString m_name; PlotType m_plotType; double m_plotDataSize; From 8a11c588a6bf81d669d9b3533b94e47b398db696 Mon Sep 17 00:00:00 2001 From: m_thread Date: Sat, 15 Nov 2014 11:04:19 +0100 Subject: [PATCH 2/3] OP-1611 Addressed some review comments and changed logic around plots wanting initial data. --- ground/openpilotgcs/src/plugins/scope/plotdata.cpp | 8 ++++++++ ground/openpilotgcs/src/plugins/scope/scopegadget.cpp | 2 +- .../src/plugins/scope/scopegadgetwidget.cpp | 11 ++++++----- .../src/plugins/scope/scopegadgetwidget.h | 2 -- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp index b930e3cbd..b20cf4f1f 100644 --- a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp +++ b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp @@ -201,6 +201,10 @@ QwtPlotMarker *PlotData::createMarker(QString value) bool SequentialPlotData::append(UAVObject *obj) { + if (obj == NULL) { + obj = m_object; + } + if (m_object == obj && m_field) { if (!m_isEnumPlot) { double currentValue = m_field->getValue(m_element).toDouble() * pow(10, m_scalePower); @@ -241,6 +245,10 @@ bool SequentialPlotData::append(UAVObject *obj) bool ChronoPlotData::append(UAVObject *obj) { + if (obj == NULL) { + obj = m_object; + } + if (m_object == obj && m_field) { // Get the field of interest // THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp index e5b36d170..5531897d1 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp @@ -47,7 +47,7 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config) ScopeGadgetConfiguration *sgConfig = qobject_cast(config); ScopeGadgetWidget *widget = qobject_cast(m_widget); - widget->setName(config->name()); + widget->setObjectName(config->name()); widget->setPlotDataSize(sgConfig->dataSize()); widget->setRefreshInterval(sgConfig->refreshInterval()); diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index 0f5f00d69..94344ab7e 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -195,6 +195,11 @@ void ScopeGadgetWidget::showEvent(QShowEvent *e) void ScopeGadgetWidget::startPlotting() { if (replotTimer && !replotTimer->isActive()) { + foreach (PlotData *plot, m_curvesData.values()) { + if (plot->wantsInitialData()) { + plot->append(NULL); + } + } replotTimer->start(m_refreshInterval); } } @@ -378,10 +383,6 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie connect(this, SIGNAL(visibilityChanged(QwtPlotItem *)), plotData, SLOT(visibilityChanged(QwtPlotItem *))); plotData->attach(this); - if (plotData->wantsInitialData()) { - plotData->append(object); - } - // Keep the curve details for later m_curvesData.insert(plotData->plotName(), plotData); @@ -671,5 +672,5 @@ void ScopeGadgetWidget::copyToClipboardAsImage() void ScopeGadgetWidget::showOptionDialog() { - Core::ICore::instance()->showOptionsDialog("ScopeGadget", m_name); + Core::ICore::instance()->showOptionsDialog("ScopeGadget", objectName()); } diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h index 1b8302055..07795db7c 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h @@ -69,7 +69,6 @@ public: ScopeGadgetWidget(QWidget *parent = 0); ~ScopeGadgetWidget(); - void setName (QString name) { m_name = name; } void setupSequentialPlot(); void setupChronoPlot(); void setupUAVObjectPlot(); @@ -148,7 +147,6 @@ private: void preparePlot(PlotType plotType); void setupExamplePlot(); - QString m_name; PlotType m_plotType; double m_plotDataSize; From 8cf65d5cbe6f7e010d40e2f966343ec4a0005374 Mon Sep 17 00:00:00 2001 From: m_thread Date: Sat, 15 Nov 2014 11:07:32 +0100 Subject: [PATCH 3/3] OP-1611 Uncrustify --- ground/openpilotgcs/src/plugins/scope/plotdata.cpp | 2 +- .../src/plugins/scope/scopegadgetwidget.cpp | 13 +++++++------ .../plugins/setupwizard/outputcalibrationutil.cpp | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp index b20cf4f1f..b5991ef54 100644 --- a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp +++ b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp @@ -96,7 +96,7 @@ void PlotData::updatePlotData() void PlotData::clear() { m_meanSum = 0.0f; - m_correctionSum = 0.0f; + m_correctionSum = 0.0f; m_correctionCount = 0; m_xDataEntries.clear(); m_yDataEntries.clear(); diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index 94344ab7e..8d019c8f5 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -95,7 +95,7 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent), connect(cm, SIGNAL(deviceConnected(QIODevice *)), this, SLOT(csvLoggingConnect())); setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, SIGNAL(customContextMenuRequested(const QPoint & )), this, SLOT(popUpMenu(const QPoint &))); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(popUpMenu(const QPoint &))); } ScopeGadgetWidget::~ScopeGadgetWidget() @@ -195,7 +195,7 @@ void ScopeGadgetWidget::showEvent(QShowEvent *e) void ScopeGadgetWidget::startPlotting() { if (replotTimer && !replotTimer->isActive()) { - foreach (PlotData *plot, m_curvesData.values()) { + foreach(PlotData * plot, m_curvesData.values()) { if (plot->wantsInitialData()) { plot->append(NULL); } @@ -639,7 +639,7 @@ void ScopeGadgetWidget::popUpMenu(const QPoint &mousePosition) Q_UNUSED(mousePosition); QMenu menu; - QAction * action = menu.addAction(tr("Clear")); + QAction *action = menu.addAction(tr("Clear")); connect(action, &QAction::triggered, this, &ScopeGadgetWidget::clearPlot); action = menu.addAction(tr("Copy to Clipboard")); connect(action, &QAction::triggered, this, &ScopeGadgetWidget::copyToClipboardAsImage); @@ -652,7 +652,7 @@ void ScopeGadgetWidget::popUpMenu(const QPoint &mousePosition) void ScopeGadgetWidget::clearPlot() { m_mutex.lock(); - foreach (PlotData * plot, m_curvesData.values()) { + foreach(PlotData * plot, m_curvesData.values()) { plot->clear(); } m_mutex.unlock(); @@ -661,8 +661,9 @@ void ScopeGadgetWidget::clearPlot() void ScopeGadgetWidget::copyToClipboardAsImage() { - QPixmap pixmap = QWidget::grab(); - if(pixmap.isNull()){ + QPixmap pixmap = QWidget::grab(); + + if (pixmap.isNull()) { qDebug("Failed to capture the plot"); return; } diff --git a/ground/openpilotgcs/src/plugins/setupwizard/outputcalibrationutil.cpp b/ground/openpilotgcs/src/plugins/setupwizard/outputcalibrationutil.cpp index 215faefc6..5369bf845 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/outputcalibrationutil.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/outputcalibrationutil.cpp @@ -93,7 +93,8 @@ void OutputCalibrationUtil::stopOutputCalibration() } } -void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue) { +void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue) +{ QList channels; channels.append(channel); startChannelOutput(channels, safeValue); @@ -125,9 +126,9 @@ void OutputCalibrationUtil::setChannelOutputValue(quint16 value) if (c_prepared) { ActuatorCommand *actuatorCommand = getActuatorCommandObject(); ActuatorCommand::DataFields data = actuatorCommand->getData(); - foreach (quint32 channel, m_outputChannels) { + foreach(quint32 channel, m_outputChannels) { // Set output value - if (channel <= ActuatorCommand::CHANNEL_NUMELEM){ + if (channel <= ActuatorCommand::CHANNEL_NUMELEM) { qDebug() << "OutputCalibrationUtil setting output value for channel " << channel << " to " << value << "."; data.Channel[channel] = value; } else {