diff --git a/gr-util/include/gr-util/grtimeplotaddon.h b/gr-util/include/gr-util/grtimeplotaddon.h index 680aa2906d..0d50254069 100644 --- a/gr-util/include/gr-util/grtimeplotaddon.h +++ b/gr-util/include/gr-util/grtimeplotaddon.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -139,6 +140,7 @@ private Q_SLOTS: GRTimeChannelAddon *m_fft_source[2]; + PlotBufferPreviewer *m_bufferPreviewer; TimePlotInfo *m_info; time_sink_f::sptr time_sink; // fft_sink_f::sptr fft_sink; @@ -177,6 +179,7 @@ private Q_SLOTS: void updateXAxis(); void updateFrameRate(); void drawTags(); + QWidget *createPlotInfoSlot(QWidget *parent); }; } // namespace grutil } // namespace scopy diff --git a/gr-util/src/grtimeplotaddon.cpp b/gr-util/src/grtimeplotaddon.cpp index 539eab938f..cfd0d11237 100644 --- a/gr-util/src/grtimeplotaddon.cpp +++ b/gr-util/src/grtimeplotaddon.cpp @@ -105,10 +105,13 @@ GRTimePlotAddon::GRTimePlotAddon(QString name, GRTopBlock *top, QObject *parent) m_plotWidget->xAxis()->setVisible(true); // m_plotWidget->topHandlesArea()->setVisible(true); - m_info = new TimePlotInfo(m_plotWidget, widget); - m_plotWidget->addPlotInfoSlot(m_info); - connect(m_plotWidget->navigator(), &PlotNavigator::rectChanged, this, - [=]() { m_info->update(m_currentSamplingInfo); }); + QWidget *plotInfoSlot = createPlotInfoSlot(m_plotWidget); + m_plotWidget->addPlotInfoSlot(plotInfoSlot); + + connect(m_plotWidget->navigator(), &PlotNavigator::rectChanged, this, [=]() { + m_info->update(m_currentSamplingInfo); + m_bufferPreviewer->updateDataLimits(); + }); // m_lay->addWidget(m_plotWidget); m_plotTimer = new QTimer(this); @@ -199,6 +202,22 @@ void GRTimePlotAddon::drawTags() } } +QWidget *GRTimePlotAddon::createPlotInfoSlot(QWidget *parent) +{ + QWidget *plotInfoSlot = new QWidget(parent); + QVBoxLayout *plotInfoLayout = new QVBoxLayout(plotInfoSlot); + plotInfoLayout->setSpacing(2); + plotInfoLayout->setMargin(4); + plotInfoSlot->setLayout(plotInfoLayout); + + AnalogBufferPreviewer *bufferPreviewer = new AnalogBufferPreviewer(plotInfoSlot); + m_bufferPreviewer = new PlotBufferPreviewer(m_plotWidget, bufferPreviewer, plotInfoSlot); + m_info = new TimePlotInfo(m_plotWidget, plotInfoSlot); + plotInfoLayout->addWidget(m_bufferPreviewer); + plotInfoLayout->addWidget(m_info); + return plotInfoSlot; +} + void GRTimePlotAddon::drawPlot() { // qInfo(CAT_GRTIMEPLOT)<<"Draw plot"; @@ -313,7 +332,7 @@ void GRTimePlotAddon::replot() #endif } -void GRTimePlotAddon::updateBufferPreviewer() { m_info->updateBufferPreviewer(); } +void GRTimePlotAddon::updateBufferPreviewer() { m_bufferPreviewer->updateBufferPreviewer(); } void GRTimePlotAddon::onInit() { @@ -469,6 +488,7 @@ void GRTimePlotAddon::updateXAxis() qInfo() << fft_xPlotAxis->min() << fft_xPlotAxis->max(); m_info->update(m_currentSamplingInfo); + m_bufferPreviewer->updateDataLimits(); Q_EMIT xAxisUpdated(); } diff --git a/gui/include/gui/widgets/plotbufferpreviewer.h b/gui/include/gui/widgets/plotbufferpreviewer.h new file mode 100644 index 0000000000..c6fd1ff19e --- /dev/null +++ b/gui/include/gui/widgets/plotbufferpreviewer.h @@ -0,0 +1,36 @@ +#ifndef PLOTBUFFERPREVIEWER_H +#define PLOTBUFFERPREVIEWER_H + +#include "scopy-gui_export.h" +#include +#include "plotwidget.h" +#include "buffer_previewer.hpp" + +namespace scopy { + +class SCOPY_GUI_EXPORT PlotBufferPreviewer : public QWidget +{ + Q_OBJECT +public: + explicit PlotBufferPreviewer(PlotWidget *p, BufferPreviewer *b, QWidget *parent = nullptr); + ~PlotBufferPreviewer(); + + void updateDataLimits(); + void updateDataLimits(double min, double max); +public Q_SLOTS: + void updateBufferPreviewer(); + +private: + double m_bufferPrevInitMin; + double m_bufferPrevInitMax; + + double m_bufferPrevData; + + void setupBufferPreviewer(); + PlotWidget *m_plot; + BufferPreviewer *m_bufferPreviewer; +}; + +} // namespace scopy + +#endif // PLOTBUFFERPREVIEWER_H diff --git a/gui/include/gui/widgets/plotinfo.h b/gui/include/gui/widgets/plotinfo.h index 8e2117e5ae..b99c4541de 100644 --- a/gui/include/gui/widgets/plotinfo.h +++ b/gui/include/gui/widgets/plotinfo.h @@ -1,7 +1,6 @@ #ifndef PLOTINFO_H #define PLOTINFO_H -#include "buffer_previewer.hpp" #include "plotwidget.h" #include @@ -52,28 +51,6 @@ class SCOPY_GUI_EXPORT TimePlotStatusInfo : public QLabel class SCOPY_GUI_EXPORT TimePlotVDivInfo : public QWidget {}; -class SCOPY_GUI_EXPORT PlotBufferPreviewerController : public QWidget -{ - Q_OBJECT -public: - explicit PlotBufferPreviewerController(PlotWidget *p, BufferPreviewer *b, QWidget *parent = nullptr); - ~PlotBufferPreviewerController(); - - void updateDataLimits(double min, double max); -public Q_SLOTS: - void updateBufferPreviewer(); - -private: - double m_bufferPrevInitMin; - double m_bufferPrevInitMax; - - double m_bufferPrevData; - - void setupBufferPreviewer(); - PlotWidget *m_plot; - BufferPreviewer *m_bufferPreviewer; -}; - class SCOPY_GUI_EXPORT TimePlotInfo : public QWidget { Q_OBJECT @@ -83,15 +60,12 @@ class SCOPY_GUI_EXPORT TimePlotInfo : public QWidget public Q_SLOTS: void update(PlotSamplingInfo info); - void updateBufferPreviewer(); private: PlotWidget *m_plot; TimePlotHDivInfo *m_hdiv; TimePlotSamplingInfo *m_sampling; TimePlotStatusInfo *m_status; - PlotBufferPreviewerController *m_bufferController; - AnalogBufferPreviewer *m_bufferPreviewer; }; } // namespace scopy diff --git a/gui/src/widgets/plotbufferpreviewer.cpp b/gui/src/widgets/plotbufferpreviewer.cpp new file mode 100644 index 0000000000..63af68788e --- /dev/null +++ b/gui/src/widgets/plotbufferpreviewer.cpp @@ -0,0 +1,106 @@ +#include "plotbufferpreviewer.h" +#include "plotaxis.h" + +using namespace scopy; + +PlotBufferPreviewer::PlotBufferPreviewer(PlotWidget *p, BufferPreviewer *b, QWidget *parent) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + QVBoxLayout *layout = new QVBoxLayout(this); + setLayout(layout); + layout->setMargin(0); + layout->setSpacing(0); + layout->addWidget(b); + + m_plot = p; + m_bufferPreviewer = b; + setupBufferPreviewer(); +} + +PlotBufferPreviewer::~PlotBufferPreviewer() {} + +void PlotBufferPreviewer::setupBufferPreviewer() +{ + m_bufferPreviewer->setMinimumHeight(20); + m_bufferPreviewer->setCursorPos(0.5); + m_bufferPreviewer->setHighlightPos(0.05); + m_bufferPreviewer->setHighlightWidth(0.2); + m_bufferPreviewer->setCursorVisible(false); + m_bufferPreviewer->setWaveformPos(0.1); + m_bufferPreviewer->setWaveformWidth(0.5); + + updateDataLimits(m_plot->xAxis()->min(), m_plot->xAxis()->max()); + + connect(m_bufferPreviewer, &BufferPreviewer::bufferStopDrag, this, [=]() {}); + + connect(m_bufferPreviewer, &BufferPreviewer::bufferStartDrag, this, [=]() { + m_bufferPrevInitMin = m_plot->xAxis()->min(); + m_bufferPrevInitMax = m_plot->xAxis()->max(); + }); + + connect(m_bufferPreviewer, &BufferPreviewer::bufferMovedBy, this, [=](int value) { + double moveTo = 0.0; + + int width = m_bufferPreviewer->width(); + double xAxisWidth = m_bufferPrevData; + if(m_plot->xAxis()->min() > m_plot->xAxis()->max()) { + value *= -1; + } + + moveTo = value * xAxisWidth / width; + m_plot->xAxis()->setInterval(m_bufferPrevInitMin + moveTo, m_bufferPrevInitMax + moveTo); + m_plot->replot(); + + updateBufferPreviewer(); + }); + + connect(m_bufferPreviewer, &BufferPreviewer::bufferResetPosition, this, [=]() { + if(m_plot->xAxis()->min() > m_plot->xAxis()->max()) { + m_plot->xAxis()->setInterval(m_bufferPrevData, 0.); + } else { + m_plot->xAxis()->setInterval(0., m_bufferPrevData); + } + m_plot->xAxis()->updateAxisScale(); + }); +} + +void PlotBufferPreviewer::updateDataLimits() +{ + PlotAxis *xAxis = (m_plot->selectedChannel()) ? m_plot->selectedChannel()->xAxis() : m_plot->xAxis(); + m_bufferPrevData = abs(xAxis->max() - xAxis->min()); + updateBufferPreviewer(); +} + +void PlotBufferPreviewer::updateDataLimits(double min, double max) +{ + m_bufferPrevData = abs(max - min); + updateBufferPreviewer(); +} + +void PlotBufferPreviewer::updateBufferPreviewer() +{ + // Time interval within the plot canvas + double left = m_plot->plot()->axisScaleDiv(m_plot->xAxis()->axisId()).lowerBound(); + double right = m_plot->plot()->axisScaleDiv(m_plot->xAxis()->axisId()).upperBound(); + QwtInterval plotInterval(std::min(left, right), std::max(left, right)); + + // Time interval that represents the captured data + QwtInterval dataInterval(0.0, m_bufferPrevData); + + // Use the two intervals to determine the width and position of the + // waveform and of the highlighted area + QwtInterval fullInterval = plotInterval | dataInterval; + double wPos = 1 - (fullInterval.maxValue() - dataInterval.minValue()) / fullInterval.width(); + double wWidth = dataInterval.width() / fullInterval.width(); + + double hPos = 1 - (fullInterval.maxValue() - plotInterval.minValue()) / fullInterval.width(); + double hWidth = plotInterval.width() / fullInterval.width(); + if(left > right) { + hPos = wWidth - hPos - hWidth; + } + + m_bufferPreviewer->setWaveformWidth(wWidth); + m_bufferPreviewer->setWaveformPos(wPos); + m_bufferPreviewer->setHighlightWidth(hWidth); + m_bufferPreviewer->setHighlightPos(hPos); +} diff --git a/gui/src/widgets/plotinfo.cpp b/gui/src/widgets/plotinfo.cpp index c671805f70..2c7df05f19 100644 --- a/gui/src/widgets/plotinfo.cpp +++ b/gui/src/widgets/plotinfo.cpp @@ -47,99 +47,11 @@ TimePlotStatusInfo::TimePlotStatusInfo(QWidget *parent) TimePlotStatusInfo::~TimePlotStatusInfo() {} -void PlotBufferPreviewerController::setupBufferPreviewer() -{ - m_bufferPreviewer->setMinimumHeight(20); - m_bufferPreviewer->setCursorPos(0.5); - m_bufferPreviewer->setHighlightPos(0.05); - m_bufferPreviewer->setHighlightWidth(0.2); - m_bufferPreviewer->setCursorVisible(false); - m_bufferPreviewer->setWaveformPos(0.1); - m_bufferPreviewer->setWaveformWidth(0.5); - - updateDataLimits(m_plot->xAxis()->min(), m_plot->xAxis()->max()); - - connect(m_bufferPreviewer, &BufferPreviewer::bufferStopDrag, this, [=]() {}); - - connect(m_bufferPreviewer, &BufferPreviewer::bufferStartDrag, this, [=]() { - m_bufferPrevInitMin = m_plot->xAxis()->min(); - m_bufferPrevInitMax = m_plot->xAxis()->max(); - }); - - connect(m_bufferPreviewer, &BufferPreviewer::bufferMovedBy, this, [=](int value) { - double moveTo = 0.0; - - int width = m_bufferPreviewer->width(); - double xAxisWidth = m_bufferPrevData; - if(m_plot->xAxis()->min() > m_plot->xAxis()->max()) { - value *= -1; - } - - moveTo = value * xAxisWidth / width; - m_plot->xAxis()->setInterval(m_bufferPrevInitMin + moveTo, m_bufferPrevInitMax + moveTo); - m_plot->replot(); - - updateBufferPreviewer(); - }); - - connect(m_bufferPreviewer, &BufferPreviewer::bufferResetPosition, this, [=]() { - if(m_plot->xAxis()->min() > m_plot->xAxis()->max()) { - m_plot->xAxis()->setInterval(m_bufferPrevData, 0.); - } else { - m_plot->xAxis()->setInterval(0., m_bufferPrevData); - } - m_plot->xAxis()->updateAxisScale(); - }); -} - -void PlotBufferPreviewerController::updateDataLimits(double min, double max) -{ - m_bufferPrevData = abs(max - min); - updateBufferPreviewer(); -} - -void PlotBufferPreviewerController::updateBufferPreviewer() -{ - // Time interval within the plot canvas - double left = m_plot->plot()->axisScaleDiv(m_plot->xAxis()->axisId()).lowerBound(); - double right = m_plot->plot()->axisScaleDiv(m_plot->xAxis()->axisId()).upperBound(); - QwtInterval plotInterval(std::min(left, right), std::max(left, right)); - - // Time interval that represents the captured data - QwtInterval dataInterval(0.0, m_bufferPrevData); - - // Use the two intervals to determine the width and position of the - // waveform and of the highlighted area - QwtInterval fullInterval = plotInterval | dataInterval; - double wPos = 1 - (fullInterval.maxValue() - dataInterval.minValue()) / fullInterval.width(); - double wWidth = dataInterval.width() / fullInterval.width(); - - double hPos = 1 - (fullInterval.maxValue() - plotInterval.minValue()) / fullInterval.width(); - double hWidth = plotInterval.width() / fullInterval.width(); - if(left > right) { - hPos = wWidth - hPos - hWidth; - } - - m_bufferPreviewer->setWaveformWidth(wWidth); - m_bufferPreviewer->setWaveformPos(wPos); - m_bufferPreviewer->setHighlightWidth(hWidth); - m_bufferPreviewer->setHighlightPos(hPos); -} - -PlotBufferPreviewerController::PlotBufferPreviewerController(PlotWidget *p, BufferPreviewer *b, QWidget *parent) -{ - m_plot = p; - m_bufferPreviewer = b; - setupBufferPreviewer(); -} - -PlotBufferPreviewerController::~PlotBufferPreviewerController() {} - TimePlotInfo::TimePlotInfo(PlotWidget *plot, QWidget *parent) { m_plot = plot; QVBoxLayout *vlay = new QVBoxLayout(this); - vlay->setMargin(4); + vlay->setMargin(0); vlay->setSpacing(2); setLayout(vlay); QHBoxLayout *lay = new QHBoxLayout(); @@ -150,10 +62,6 @@ TimePlotInfo::TimePlotInfo(PlotWidget *plot, QWidget *parent) m_sampling = new TimePlotSamplingInfo(this); m_status = new TimePlotStatusInfo(this); - m_bufferPreviewer = new AnalogBufferPreviewer(this); - m_bufferController = new PlotBufferPreviewerController(plot, m_bufferPreviewer, this); - - vlay->addWidget(m_bufferPreviewer); vlay->addLayout(lay); #ifdef HOVER_INFO @@ -197,9 +105,6 @@ void TimePlotInfo::update(PlotSamplingInfo info) m_hdiv->update(abs(currMax - currMin) / divs, zoomed); m_sampling->update(info.plotSize, info.bufferSize, info.sampleRate); - m_bufferController->updateDataLimits(axisMin, axisMax); } -void TimePlotInfo::updateBufferPreviewer() { m_bufferController->updateBufferPreviewer(); } - #include "moc_plotinfo.cpp" diff --git a/plugins/datamonitor/include/datamonitorplugin/monitorplot.hpp b/plugins/datamonitor/include/datamonitorplugin/monitorplot.hpp index e9426a3132..87b7833da5 100644 --- a/plugins/datamonitor/include/datamonitorplugin/monitorplot.hpp +++ b/plugins/datamonitor/include/datamonitorplugin/monitorplot.hpp @@ -9,11 +9,11 @@ #include #include #include +#include #include "scopy-datamonitorplugin_export.h" namespace scopy { -class TimePlotInfo; namespace datamonitor { class MonitorPlotCurve; @@ -51,7 +51,6 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT MonitorPlot : public QWidget private: PlotWidget *m_plot; - TimePlotInfo *m_plotInfo; QMap *m_monitorCurves = nullptr; bool m_firstMonitor = true; @@ -69,6 +68,8 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT MonitorPlot : public QWidget void refreshXAxisInterval(); double m_xAxisIntervalMin; double m_xAxisIntervalMax; + + PlotBufferPreviewer *m_bufferPreviewer; }; } // namespace datamonitor } // namespace scopy diff --git a/plugins/datamonitor/src/datamonitor/monitorplot.cpp b/plugins/datamonitor/src/datamonitor/monitorplot.cpp index 08cc6f0fd7..f05c3900fd 100644 --- a/plugins/datamonitor/src/datamonitor/monitorplot.cpp +++ b/plugins/datamonitor/src/datamonitor/monitorplot.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -34,9 +33,9 @@ MonitorPlot::MonitorPlot(QWidget *parent) setupXAxis(); - m_plotInfo = new TimePlotInfo(m_plot, this); - - layout->addWidget(m_plotInfo); + AnalogBufferPreviewer *bufferPreviewer = new AnalogBufferPreviewer(this); + m_bufferPreviewer = new PlotBufferPreviewer(m_plot, bufferPreviewer, this); + layout->addWidget(m_bufferPreviewer); layout->addWidget(m_plot); m_monitorCurves = new QMap(); @@ -111,7 +110,7 @@ void MonitorPlot::updateXAxisIntervalMin(double min) { m_xAxisIntervalMax = min; refreshXAxisInterval(); - m_plotInfo->updateBufferPreviewer(); + m_bufferPreviewer->updateDataLimits(); m_plot->replot(); } @@ -119,7 +118,7 @@ void MonitorPlot::updateXAxisIntervalMax(double max) { m_xAxisIntervalMin = max; refreshXAxisInterval(); - m_plotInfo->updateBufferPreviewer(); + m_bufferPreviewer->updateDataLimits(); m_plot->replot(); }