diff --git a/ground/src/plugins/scope/scopegadgetoptionspage.cpp b/ground/src/plugins/scope/scopegadgetoptionspage.cpp index 25c19c6a7..69f05426c 100644 --- a/ground/src/plugins/scope/scopegadgetoptionspage.cpp +++ b/ground/src/plugins/scope/scopegadgetoptionspage.cpp @@ -26,14 +26,14 @@ */ #include "scopegadgetoptionspage.h" -#include "scopegadgetconfiguration.h" -#include "ui_scopegadgetoptionspage.h" #include "extensionsystem/pluginmanager.h" #include "uavobjects/uavobjectmanager.h" #include "uavobjects/uavdataobject.h" +#include + ScopeGadgetOptionsPage::ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent) : IOptionsPage(parent), @@ -154,9 +154,9 @@ void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve() void ScopeGadgetOptionsPage::setButtonColor(const QColor &color) { + options_page->btnColor->setAutoFillBackground(true); options_page->btnColor->setText(color.name()); options_page->btnColor->setPalette(QPalette(color)); - options_page->btnColor->setAutoFillBackground(true); } /*! @@ -228,14 +228,21 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked() if(!parseOK) scale = 0; - //TODO: Find an existing plot curve config based on the uavobject and uav field. If it - //exists, update it, else add a new one. QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb(); - addPlotCurveConfig(uavObject,uavField,scale,varColor); + //TODO: Find an existing plot curve config based on the uavobject and uav field. If it + //exists, update it, else add a new one. + if(options_page->lstCurves->currentItem()->text() == uavObject + "." + uavField) + { + QListWidgetItem *listWidgetItem = options_page->lstCurves->currentItem(); + setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,varColor); + }else + { + addPlotCurveConfig(uavObject,uavField,scale,varColor); - options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1); + options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1); + } } void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, QVariant varColor) @@ -247,10 +254,19 @@ void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavFi options_page->lstCurves->addItem(listItemDisplayText); QListWidgetItem *listWidgetItem = options_page->lstCurves->item(options_page->lstCurves->count() - 1); + setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,varColor); + +} + +void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetItem,QString uavObject, QString uavField, int scale, QVariant varColor) +{ + bool parseOK = false; + //Set the properties of the newly added list item + QString listItemDisplayText = uavObject + "." + uavField; QRgb rgbColor = (QRgb)varColor.toInt(&parseOK); QColor color = QColor( rgbColor ); - listWidgetItem->setText(listItemDisplayText); + //listWidgetItem->setText(listItemDisplayText); listWidgetItem->setTextColor( color ); //Store some additional data for the plot curve on the list item diff --git a/ground/src/plugins/scope/scopegadgetoptionspage.h b/ground/src/plugins/scope/scopegadgetoptionspage.h index c7e773c5e..9a553de4b 100644 --- a/ground/src/plugins/scope/scopegadgetoptionspage.h +++ b/ground/src/plugins/scope/scopegadgetoptionspage.h @@ -30,6 +30,9 @@ #include "coreplugin/dialogs/ioptionspage.h" +#include "scopegadgetconfiguration.h" +#include "ui_scopegadgetoptionspage.h" + #include #include #include @@ -64,6 +67,7 @@ private: ScopeGadgetConfiguration *m_config; void addPlotCurveConfig(QString uavObject, QString uavField, int scale, QVariant varColor); + void setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale, QVariant varColor); void setYAxisWidgetFromPlotCurve(); void setButtonColor(const QColor &color); diff --git a/ground/src/plugins/scope/scopegadgetoptionspage.ui b/ground/src/plugins/scope/scopegadgetoptionspage.ui index b5644e253..f0755b3c8 100644 --- a/ground/src/plugins/scope/scopegadgetoptionspage.ui +++ b/ground/src/plugins/scope/scopegadgetoptionspage.ui @@ -18,8 +18,8 @@ 0 0 - 601 - 341 + 611 + 241 @@ -27,7 +27,7 @@ 0 0 - 461 + 601 231 @@ -190,22 +190,30 @@ 20 - 80 + 100 + + Add a new curve to the scope, or update it if the UAVObject and UAVField is the same. + - >> + Add +Update + + Remove the curve from the scope. + - << + Remove + @@ -220,7 +228,7 @@ 20 - 30 + 15 diff --git a/ground/src/plugins/scope/scopegadgetwidget.cpp b/ground/src/plugins/scope/scopegadgetwidget.cpp index 3048a0f03..52d6a370d 100644 --- a/ground/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/src/plugins/scope/scopegadgetwidget.cpp @@ -50,8 +50,8 @@ TestDataGen* ScopeGadgetWidget::testDataGen; ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent) { -// if(testDataGen == 0) -// testDataGen = new TestDataGen(); + if(testDataGen == 0) + testDataGen = new TestDataGen(); //Setup the timer that replots data replotTimer = new QTimer(this); @@ -161,14 +161,18 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavField, int sc setAxisScale(QwtPlot::yLeft, plotData->yMinimum, plotData->yMaximum); //Create the curve - QString curveName = (plotData->uavObject) + "." + (plotData->uavField); + QString curveName; + if(scaleOrderFactor == 0) + curveName = (plotData->uavObject) + "." + (plotData->uavField); + else + curveName = (plotData->uavObject) + "." + (plotData->uavField) + "(E" + QString::number(scaleOrderFactor) + ")"; + QwtPlotCurve* plotCurve = new QwtPlotCurve(curveName); plotCurve->setPen(pen); plotCurve->setData(*plotData->xData, *plotData->yData); plotCurve->attach(this); plotData->curve = plotCurve; - //Keep the curve details for later m_curvesData.insert(curveName, plotData); @@ -331,7 +335,7 @@ void TestDataGen::genTestData() BaroAltitude::DataFields baroAltitudeData; baroAltitudeData.Altitude = 500 * sin(1 * testTime) + 200 * cos(4 * testTime) + 800; baroAltitudeData.Temperature = 30 * sin(0.5 * testTime); - baroAltitudeData.Pressure = 100; + baroAltitudeData.Pressure = baroAltitudeData.Altitude * 0.01 + baroAltitudeData.Temperature; baroAltitude->setData(baroAltitudeData);