Skip to content

Commit

Permalink
gui/widgets/plotinfo: Removed buffer previewer from plotinfo.
Browse files Browse the repository at this point in the history
I made a standalone class (PlotBufferPreviewer) for the buffer previewer
which contains the controller and the actual previewer.

Signed-off-by: andrei.danila <[email protected]>
  • Loading branch information
andreidanila1 committed Apr 17, 2024
1 parent 42eb8d7 commit c9f6334
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 135 deletions.
3 changes: 3 additions & 0 deletions gr-util/include/gr-util/grtimeplotaddon.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QtConcurrent>

#include <gui/oscilloscope_plot.hpp>
#include <gui/widgets/plotbufferpreviewer.h>
#include <plotwidget.h>
#include <gnuradio/blocks/stream_to_vector.h>
#include <gnuradio/fft/fft_v.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -177,6 +179,7 @@ private Q_SLOTS:
void updateXAxis();
void updateFrameRate();
void drawTags();
QWidget *createPlotInfoSlot(QWidget *parent);
};
} // namespace grutil
} // namespace scopy
Expand Down
30 changes: 25 additions & 5 deletions gr-util/src/grtimeplotaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -313,7 +332,7 @@ void GRTimePlotAddon::replot()
#endif
}

void GRTimePlotAddon::updateBufferPreviewer() { m_info->updateBufferPreviewer(); }
void GRTimePlotAddon::updateBufferPreviewer() { m_bufferPreviewer->updateBufferPreviewer(); }

void GRTimePlotAddon::onInit()
{
Expand Down Expand Up @@ -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();
}

Expand Down
36 changes: 36 additions & 0 deletions gui/include/gui/widgets/plotbufferpreviewer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef PLOTBUFFERPREVIEWER_H
#define PLOTBUFFERPREVIEWER_H

#include "scopy-gui_export.h"
#include <QWidget>
#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
26 changes: 0 additions & 26 deletions gui/include/gui/widgets/plotinfo.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef PLOTINFO_H
#define PLOTINFO_H

#include "buffer_previewer.hpp"
#include "plotwidget.h"

#include <QLabel>
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
106 changes: 106 additions & 0 deletions gui/src/widgets/plotbufferpreviewer.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit c9f6334

Please sign in to comment.