Skip to content

Commit

Permalink
gui: PlotChannel: removed plotwidget parameter and dependency
Browse files Browse the repository at this point in the history
- developer is now required to use the addPlotChannel() function inside plotwidget

Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Apr 11, 2024
1 parent 3990583 commit 42eb8d7
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
5 changes: 2 additions & 3 deletions gr-util/src/grtimechanneladdon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <iio-widgets/iiowidgetfactory.h>
#include "grdeviceaddon.h"
#include "errorbox.h"
#include "plottracker.hpp"

#include <QComboBox>
#include <QDebug>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions gr-util/src/grtimeplotaddon.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "grtimeplotaddon.h"

#include "grtimeplotaddonsettings.h"
#include "hoverwidget.h"

#include <QLoggingCategory>
#include <QTimer>
Expand Down Expand Up @@ -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);

Expand All @@ -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());

Expand Down
9 changes: 5 additions & 4 deletions gui/include/gui/plotchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<QwtPlotMarker *> m_markers;
QwtSymbol *symbol;
PlotWidget *m_plotWidget;
QwtPlot *m_plot;
QPen m_pen;
float *m_data;
QString m_name;
Expand Down
17 changes: 6 additions & 11 deletions gui/src/plotchannel.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#include "plotchannel.h"

#include "plotaxis.h"
#include "plotwidget.h"

#include <QPen>

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)
Expand Down Expand Up @@ -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();
}
Expand All @@ -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)
Expand Down Expand Up @@ -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; }
Expand All @@ -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;
}

Expand Down Expand Up @@ -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(); }

Expand Down
2 changes: 2 additions & 0 deletions gui/src/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion plugins/datamonitor/src/datamonitor/monitorplotcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions plugins/pqm/src/harmonicsinstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions plugins/pqm/src/waveforminstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void WaveformInstrument::setupChannels(PlotWidget *plot, QMap<QString, QString>
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++;
Expand Down
6 changes: 4 additions & 2 deletions plugins/testplugin/src/testtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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);
Expand Down

0 comments on commit 42eb8d7

Please sign in to comment.