From 42eb8d740bfde5f66cecfed0abce6f69fedc7f85 Mon Sep 17 00:00:00 2001 From: Andrei Popa Date: Wed, 10 Apr 2024 17:17:36 +0300 Subject: [PATCH] gui: PlotChannel: removed plotwidget parameter and dependency - developer is now required to use the addPlotChannel() function inside plotwidget Signed-off-by: Andrei Popa --- gr-util/src/grtimechanneladdon.cpp | 5 ++--- gr-util/src/grtimeplotaddon.cpp | 8 ++++---- gui/include/gui/plotchannel.h | 9 +++++---- gui/src/plotchannel.cpp | 17 ++++++----------- gui/src/plotwidget.cpp | 2 ++ .../src/datamonitor/monitorplotcurve.cpp | 3 ++- plugins/pqm/src/harmonicsinstrument.cpp | 4 ++-- plugins/pqm/src/waveforminstrument.cpp | 4 ++-- plugins/testplugin/src/testtool.cpp | 6 ++++-- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/gr-util/src/grtimechanneladdon.cpp b/gr-util/src/grtimechanneladdon.cpp index 15ece895e1..7d51c85d8e 100644 --- a/gr-util/src/grtimechanneladdon.cpp +++ b/gr-util/src/grtimechanneladdon.cpp @@ -4,7 +4,6 @@ #include #include "grdeviceaddon.h" #include "errorbox.h" -#include "plottracker.hpp" #include #include @@ -55,7 +54,7 @@ GRTimeChannelAddon::GRTimeChannelAddon(QString ch, GRDeviceAddon *dev, GRTimePlo auto plot = plotAddon->plot(); m_plotAxis = new PlotAxis(yPlotAxisPosition, plot, pen, this); - m_plotCh = new PlotChannel(m_channelName, pen, plot, plot->xAxis(), m_plotAxis, this); + m_plotCh = new PlotChannel(m_channelName, pen, plot->xAxis(), m_plotAxis, this); m_plotAxisHandle = new PlotAxisHandle(pen, m_plotAxis, plot, yPlotAxisHandle, this); m_plotCh->setHandle(m_plotAxisHandle); plot->addPlotAxisHandle(m_plotAxisHandle); @@ -343,7 +342,7 @@ ImportChannelAddon::ImportChannelAddon(QString name, PlotAddon *plotAddon, QPen ; m_plotAxis = new PlotAxis(yPlotAxisPosition, plot, pen, this); - m_plotCh = new PlotChannel(m_channelName, pen, plot, plot->xAxis(), m_plotAxis, this); + m_plotCh = new PlotChannel(m_channelName, pen, plot->xAxis(), m_plotAxis, this); m_plotAxisHandle = new PlotAxisHandle(pen, m_plotAxis, plot, yPlotAxisHandle, this); m_plotCh->setHandle(m_plotAxisHandle); plot->addPlotAxisHandle(m_plotAxisHandle); diff --git a/gr-util/src/grtimeplotaddon.cpp b/gr-util/src/grtimeplotaddon.cpp index 20e142d91c..539eab938f 100644 --- a/gr-util/src/grtimeplotaddon.cpp +++ b/gr-util/src/grtimeplotaddon.cpp @@ -1,7 +1,6 @@ #include "grtimeplotaddon.h" #include "grtimeplotaddonsettings.h" -#include "hoverwidget.h" #include #include @@ -60,8 +59,8 @@ GRTimePlotAddon::GRTimePlotAddon(QString name, GRTopBlock *top, QObject *parent) fft_yPlotAxis = new PlotAxis(QwtAxis::YLeft, m_fftPlotWidget, fftchannel_pen); fft_yPlotAxis->setInterval(-145, 5); - m_fft_channel = new PlotChannel("FFT", fftchannel_pen, m_fftPlotWidget, fft_xPlotAxis, fft_yPlotAxis); - + m_fft_channel = new PlotChannel("FFT", fftchannel_pen, fft_xPlotAxis, fft_yPlotAxis); + m_fftPlotWidget->addPlotChannel(m_fft_channel); // m_fft_channel->setThickness(5); // m_fft_channel->setStyle(1); @@ -81,7 +80,8 @@ GRTimePlotAddon::GRTimePlotAddon(QString name, GRTopBlock *top, QObject *parent) xy_xPlotAxis = new PlotAxis(QwtAxis::XBottom, m_xyPlotWidget, xychannel_pen); xy_yPlotAxis = new PlotAxis(QwtAxis::YLeft, m_xyPlotWidget, xychannel_pen); - m_xy_channel = new PlotChannel("X-Y", xychannel_pen, m_xyPlotWidget, xy_xPlotAxis, xy_yPlotAxis, this); + m_xy_channel = new PlotChannel("X-Y", xychannel_pen, xy_xPlotAxis, xy_yPlotAxis, this); + m_xyPlotWidget->addPlotChannel(m_xy_channel); // m_xy_channel->setHandle(new PlotAxisHandle(xychannel_pen, xy_yPlotAxis, m_xyPlotWidget, QwtAxis::YLeft, // this)); m_xyPlotWidget->addPlotAxisHandle(m_xy_channel->handle()); diff --git a/gui/include/gui/plotchannel.h b/gui/include/gui/plotchannel.h index 0503774b06..6f045d2c2b 100644 --- a/gui/include/gui/plotchannel.h +++ b/gui/include/gui/plotchannel.h @@ -26,8 +26,7 @@ class SCOPY_GUI_EXPORT PlotChannel : public QObject PCS_SMOOTH } PlotCurveStyle; - PlotChannel(QString name, QPen pen, PlotWidget *plot, PlotAxis *xAxis, PlotAxis *yAxis, - QObject *parent = nullptr); + PlotChannel(QString name, QPen pen, PlotAxis *xAxis, PlotAxis *yAxis, QObject *parent = nullptr); ~PlotChannel(); QwtPlotCurve *curve() const; @@ -56,14 +55,16 @@ public Q_SLOTS: void setThickness(int); void setStyle(int); +Q_SIGNALS: + void attachCurve(QwtPlotCurve *curve); + void doReplot(); + private: PlotAxis *m_xAxis, *m_yAxis; PlotAxisHandle *m_handle; QwtPlotCurve *m_curve; QList m_markers; QwtSymbol *symbol; - PlotWidget *m_plotWidget; - QwtPlot *m_plot; QPen m_pen; float *m_data; QString m_name; diff --git a/gui/src/plotchannel.cpp b/gui/src/plotchannel.cpp index ff930804e7..917d0b9bd2 100644 --- a/gui/src/plotchannel.cpp +++ b/gui/src/plotchannel.cpp @@ -1,16 +1,11 @@ #include "plotchannel.h" - #include "plotaxis.h" -#include "plotwidget.h" - #include using namespace scopy; -PlotChannel::PlotChannel(QString name, QPen pen, PlotWidget *plot, PlotAxis *xAxis, PlotAxis *yAxis, QObject *parent) +PlotChannel::PlotChannel(QString name, QPen pen, PlotAxis *xAxis, PlotAxis *yAxis, QObject *parent) : QObject(parent) - , m_plotWidget(plot) - , m_plot(m_plotWidget->plot()) , m_xAxis(xAxis) , m_yAxis(yAxis) , m_handle(nullptr) @@ -38,7 +33,7 @@ QwtPlotCurve *PlotChannel::curve() const { return m_curve; } void PlotChannel::setEnabled(bool b) { if(b) - m_curve->attach(m_plot); + Q_EMIT attachCurve(m_curve); else m_curve->detach(); } @@ -52,7 +47,7 @@ void PlotChannel::setThickness(int thickness) QPen pen = m_curve->pen(); pen.setWidthF(thickness); m_curve->setPen(pen); - m_plot->replot(); + Q_EMIT doReplot(); } void PlotChannel::setStyle(int style) @@ -83,7 +78,7 @@ void PlotChannel::setStyle(int style) m_curve->setStyle(QwtPlotCurve::Lines); break; } - m_plot->replot(); + Q_EMIT doReplot(); } QString PlotChannel::name() const { return m_name; } @@ -108,7 +103,7 @@ QwtPlotMarker *PlotChannel::buildMarker(QString str, QwtSymbol::Style shape, dou m->setXValue(x); m->setYValue(y); - m->attach(m_plot); + Q_EMIT attachCurve(m_curve); return m; } @@ -143,7 +138,7 @@ void PlotChannel::raise() } } -void PlotChannel::attach() { m_curve->attach(m_plot); } +void PlotChannel::attach() { Q_EMIT attachCurve(m_curve); } void PlotChannel::detach() { m_curve->detach(); } diff --git a/gui/src/plotwidget.cpp b/gui/src/plotwidget.cpp index add0a163f4..f2f171b83d 100644 --- a/gui/src/plotwidget.cpp +++ b/gui/src/plotwidget.cpp @@ -200,6 +200,8 @@ void PlotWidget::addPlotChannel(PlotChannel *ch) selectChannel(ch); } + connect(ch, &PlotChannel::doReplot, this, &PlotWidget::replot); + connect(ch, &PlotChannel::attachCurve, this, [=](QwtPlotCurve *curve) { curve->attach(m_plot); }); m_navigator->addChannel(ch); m_tracker->addChannel(ch); Q_EMIT addedChannel(ch); diff --git a/plugins/datamonitor/src/datamonitor/monitorplotcurve.cpp b/plugins/datamonitor/src/datamonitor/monitorplotcurve.cpp index dff2785315..7ce47647a5 100644 --- a/plugins/datamonitor/src/datamonitor/monitorplotcurve.cpp +++ b/plugins/datamonitor/src/datamonitor/monitorplotcurve.cpp @@ -12,7 +12,8 @@ MonitorPlotCurve::MonitorPlotCurve(DataMonitorModel *dataMonitorModel, PlotWidge m_curveStyleIndex = 0; QPen chpen = QPen(dataMonitorModel->getColor(), 1); - m_plotch = new PlotChannel(dataMonitorModel->getName(), chpen, plot, plot->xAxis(), plot->yAxis(), this); + m_plotch = new PlotChannel(dataMonitorModel->getName(), chpen, plot->xAxis(), plot->yAxis(), this); + plot->addPlotChannel(m_plotch); m_plotch->setEnabled(true); m_plotch->curve()->setRawSamples(m_dataMonitorModel->getXdata()->data(), m_dataMonitorModel->getYdata()->data(), diff --git a/plugins/pqm/src/harmonicsinstrument.cpp b/plugins/pqm/src/harmonicsinstrument.cpp index 1df513de03..78e5f8c659 100644 --- a/plugins/pqm/src/harmonicsinstrument.cpp +++ b/plugins/pqm/src/harmonicsinstrument.cpp @@ -122,8 +122,8 @@ void HarmonicsInstrument::setupPlotChannels() bool first = true; for(const QString &ch : m_chnls) { QPen chPen = QPen(QColor(StyleHelper::getColor("CH" + QString::number(chNumber))), 1); - PlotChannel *plotCh = - new PlotChannel(m_chnls.key(ch), chPen, m_plot, m_plot->xAxis(), m_plot->yAxis(), this); + PlotChannel *plotCh = new PlotChannel(m_chnls.key(ch), chPen, m_plot->xAxis(), m_plot->yAxis(), this); + m_plot->addPlotChannel(plotCh); plotCh->setStyle(PlotChannel::PCS_STICKS); plotCh->setThickness(10); plotCh->curve()->setRawSamples(m_xTime.data(), m_yValues[ch].data(), m_xTime.size()); diff --git a/plugins/pqm/src/waveforminstrument.cpp b/plugins/pqm/src/waveforminstrument.cpp index f224cb6baa..a4618d0690 100644 --- a/plugins/pqm/src/waveforminstrument.cpp +++ b/plugins/pqm/src/waveforminstrument.cpp @@ -81,8 +81,8 @@ void WaveformInstrument::setupChannels(PlotWidget *plot, QMap int chnlIdx = 0; for(const QString &chnlId : chnls) { QPen chPen = QPen(QColor(StyleHelper::getColor("CH" + QString::number(chnlIdx))), 1); - PlotChannel *plotCh = - new PlotChannel(chnls.key(chnlId), chPen, plot, plot->xAxis(), plot->yAxis(), this); + PlotChannel *plotCh = new PlotChannel(chnls.key(chnlId), chPen, plot->xAxis(), plot->yAxis(), this); + plot->addPlotChannel(plotCh); plotCh->setEnabled(true); plotCh->curve()->setRawSamples(m_xTime.data(), m_yValues[chnlId].data(), m_xTime.size()); chnlIdx++; diff --git a/plugins/testplugin/src/testtool.cpp b/plugins/testplugin/src/testtool.cpp index 67514f87c6..0a18a04dfa 100644 --- a/plugins/testplugin/src/testtool.cpp +++ b/plugins/testplugin/src/testtool.cpp @@ -95,7 +95,8 @@ TestTool::TestTool(QWidget *parent) QPen ch1pen = QPen(QColor(StyleHelper::getColor("CH1")), 1); auto *ch1PlotAxis = new PlotAxis(QwtAxis::YLeft, plot, ch1pen); - PlotChannel *ch1_plotch = new PlotChannel("Channel1", ch1pen, plot, plot->xAxis(), ch1PlotAxis, this); + PlotChannel *ch1_plotch = new PlotChannel("Channel1", ch1pen, plot->xAxis(), ch1PlotAxis, this); + plot->addPlotChannel(ch1_plotch); ch1_plotch->setHandle(new PlotAxisHandle(ch1pen, ch1PlotAxis, plot, QwtAxis::YLeft, this)); plot->addPlotAxisHandle(ch1_plotch->handle()); @@ -112,7 +113,8 @@ TestTool::TestTool(QWidget *parent) QPen ch2pen = QPen(QColor(StyleHelper::getColor("CH2")), 1); auto *ch2PlotAxis = new PlotAxis(QwtAxis::YLeft, plot, ch2pen); - PlotChannel *ch2_plotch = new PlotChannel("Channel2", ch2pen, plot, plot->xAxis(), ch2PlotAxis, this); + PlotChannel *ch2_plotch = new PlotChannel("Channel2", ch2pen, plot->xAxis(), ch2PlotAxis, this); + plot->addPlotChannel(ch2_plotch); ch2_plotch->setHandle(new PlotAxisHandle(ch2pen, ch2PlotAxis, plot, QwtAxis::YRight, this)); plot->addPlotAxisHandle(ch2_plotch->handle()); connect(ch2->checkBox(), &QCheckBox::toggled, ch2_plotch, &PlotChannel::setEnabled);