Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scopy 2.0: PlotInfo improvements #1609

Merged
merged 7 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gr-util/include/gr-util/grtimeplotaddon.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class SCOPY_GR_UTIL_EXPORT GRTimePlotAddon : public QObject,
void requestStop();
void newData();
void xAxisUpdated();
void statusChanged(QString status);

public Q_SLOTS:
void enable() override;
Expand Down Expand Up @@ -141,7 +142,6 @@ 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;
gr::blocks::stream_to_vector::sptr s2v, s2v_complex;
Expand All @@ -157,6 +157,7 @@ private Q_SLOTS:
QList<GRTimeChannelAddon *> grChannels;
QVBoxLayout *m_lay;
void setupBufferPreviewer();
void setupPlotInfo();

QFuture<void> refillFuture;
QFutureWatcher<void> *fw;
Expand All @@ -179,7 +180,6 @@ private Q_SLOTS:
void updateXAxis();
void updateFrameRate();
void drawTags();
QWidget *createPlotInfoSlot(QWidget *parent);
};
} // namespace grutil
} // namespace scopy
Expand Down
55 changes: 34 additions & 21 deletions gr-util/src/grtimeplotaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QLoggingCategory>
#include <QTimer>
#include <QwtWeedingCurveFitter>
#include <plotinfowidgets.h>
#include <plotnavigator.hpp>

#include <grdeviceaddon.h>
Expand Down Expand Up @@ -102,13 +103,8 @@ GRTimePlotAddon::GRTimePlotAddon(QString name, GRTopBlock *top, QObject *parent)
m_plotWidget->xAxis()->setVisible(true);
// m_plotWidget->topHandlesArea()->setVisible(true);

QWidget *plotInfoSlot = createPlotInfoSlot(m_plotWidget);
m_plotWidget->addPlotInfoSlot(plotInfoSlot);

connect(m_plotWidget->navigator(), &PlotNavigator::rectChanged, this, [=]() {
m_info->update(m_currentSamplingInfo);
m_bufferPreviewer->updateDataLimits();
});
connect(m_plotWidget->navigator(), &PlotNavigator::rectChanged, this,
[=]() { m_bufferPreviewer->updateDataLimits(); });

// m_lay->addWidget(m_plotWidget);
m_plotTimer = new QTimer(this);
Expand All @@ -125,6 +121,13 @@ GRTimePlotAddon::GRTimePlotAddon(QString name, GRTopBlock *top, QObject *parent)
m_plotTimer->start();
},
Qt::QueuedConnection);

connect(this, &GRTimePlotAddon::newData, m_plotWidget, &PlotWidget::newData);
connect(this, &GRTimePlotAddon::newData, m_fftPlotWidget, &PlotWidget::newData);
connect(this, &GRTimePlotAddon::newData, m_xyPlotWidget, &PlotWidget::newData);

setupBufferPreviewer();
setupPlotInfo();
}

GRTimePlotAddon::~GRTimePlotAddon() {}
Expand Down Expand Up @@ -199,20 +202,26 @@ void GRTimePlotAddon::drawTags()
}
}

QWidget *GRTimePlotAddon::createPlotInfoSlot(QWidget *parent)
void GRTimePlotAddon::setupPlotInfo()
{
QWidget *plotInfoSlot = new QWidget(parent);
QVBoxLayout *plotInfoLayout = new QVBoxLayout(plotInfoSlot);
plotInfoLayout->setSpacing(2);
plotInfoLayout->setMargin(4);
plotInfoSlot->setLayout(plotInfoLayout);
PlotInfo *info = m_plotWidget->getPlotInfo();

TimeSamplingInfo *samplingInfo = new TimeSamplingInfo(m_plotWidget);
info->addCustomInfo(samplingInfo, InfoPosition::IP_RIGHT);
connect(this, &GRTimePlotAddon::xAxisUpdated, this, [=]() { samplingInfo->update(m_currentSamplingInfo); });

info->addCustomInfo(new TimestampInfo(m_plotWidget), InfoPosition::IP_RIGHT);

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;
QLabel *statusInfo = info->addLabelInfo(InfoPosition::IP_RIGHT);
connect(this, &GRTimePlotAddon::statusChanged, this, [=](QString status) { statusInfo->setText(status); });
}

void GRTimePlotAddon::setupBufferPreviewer()
{
AnalogBufferPreviewer *bufferPreviewer = new AnalogBufferPreviewer(m_plotWidget);
m_bufferPreviewer = new PlotBufferPreviewer(m_plotWidget, bufferPreviewer, m_plotWidget);
m_bufferPreviewer->setContentsMargins(0, 4, 0, 4);
m_plotWidget->layout()->addWidget(m_bufferPreviewer, 0, 0);
}

void GRTimePlotAddon::drawPlot()
Expand Down Expand Up @@ -243,6 +252,8 @@ void GRTimePlotAddon::onStart()
m_top->build();
m_top->start();
m_started = true;

Q_EMIT statusChanged("running");
}
}

Expand All @@ -256,6 +267,8 @@ void GRTimePlotAddon::onStop()
disconnect(m_top, SIGNAL(builtSignalPaths()), this, SLOT(connectSignalPaths()));
disconnect(m_top, SIGNAL(teardownSignalPaths()), this, SLOT(tearDownSignalPaths()));
m_started = false;

Q_EMIT statusChanged("stopped");
}
}

Expand Down Expand Up @@ -307,6 +320,7 @@ void GRTimePlotAddon::setRawSamplesPtr()
m_currentSamplingInfo.bufferSize);
vector_sink->reset();
}
Q_EMIT newData();
}

void GRTimePlotAddon::replot()
Expand Down Expand Up @@ -398,7 +412,7 @@ void GRTimePlotAddon::connectSignalPaths()
time_sink->setFreqOffset(m_currentSamplingInfo.freqOffset);
updateXAxis();

auto fft_size = m_currentSamplingInfo.bufferSize;
auto fft_size = 1048576;
f2c = gr::blocks::float_to_complex::make();
auto window = gr::fft::window::build(m_fftwindow, fft_size);

Expand Down Expand Up @@ -484,7 +498,6 @@ void GRTimePlotAddon::updateXAxis()

qInfo() << fft_xPlotAxis->min() << fft_xPlotAxis->max();

m_info->update(m_currentSamplingInfo);
m_bufferPreviewer->updateDataLimits();
Q_EMIT xAxisUpdated();
}
Expand Down
8 changes: 6 additions & 2 deletions gui/include/gui/plotwidget.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef PLOT_H
#define PLOT_H
#include "handles_area.hpp"
#include "plotchannel.h"
#include "scopy-gui_export.h"

#include <QGridLayout>
#include <QWidget>
#include <QwtPlot>
#include <QwtPlotZoomer>
#include <plotinfo.h>

#include <buffer_previewer.hpp>
#include <graticule.h>
Expand Down Expand Up @@ -57,6 +57,7 @@ class SCOPY_GUI_EXPORT PlotWidget : public QWidget
bool eventFilter(QObject *object, QEvent *event) override;

QwtPlot *plot() const;
QGridLayout *layout();

void addPlotAxisHandle(PlotAxisHandle *ax);
void removePlotAxisHandle(PlotAxisHandle *ax);
Expand All @@ -69,7 +70,7 @@ class SCOPY_GUI_EXPORT PlotWidget : public QWidget
bool showYAxisLabels() const;
void setShowYAxisLabels(bool newShowYAxisLabels);

void addPlotInfoSlot(QWidget *w);
PlotInfo *getPlotInfo();

PlotAxis *plotAxisFromId(QwtAxisId axisId);

Expand All @@ -95,6 +96,7 @@ public Q_SLOTS:
void addedChannel(PlotChannel *ch);
void removedChannel(PlotChannel *ch);
void plotScaleChanged();
void newData();

private:
QwtPlot *m_plot;
Expand Down Expand Up @@ -125,12 +127,14 @@ public Q_SLOTS:
PlotChannel *m_selectedChannel;

BufferPreviewer *m_bufferPreviewer;
PlotInfo *m_plotInfo;

void setAxisScalesVisible(bool visible);
void setupAxisScales();
void setupOpenGLCanvas();
void setupNavigator();
void hideDefaultAxis();
void setupPlotInfo();
};

} // namespace scopy
Expand Down
3 changes: 1 addition & 2 deletions gui/include/gui/stylehelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class SCOPY_GUI_EXPORT StyleHelper : public QObject
static void StatsPanelLabel(StatsLabel *w, QString objectName = "");
static void MeasurementSelectorItemWidget(QString iconPath, MeasurementSelectorItem *w,
QString objectName = "");
static void TimePlotHDivInfo(QLabel *w, QString objectName = "");
static void TimePlotSamplingInfo(QLabel *w, QString objectName = "");
static void PlotInfoLabel(QLabel *w, QString objectName = "");
static void DeviceIconBackgroundShadow(QAbstractButton *w, QString objectName = "");
static void FrameBackgroundShadow(QFrame *w, QString objectName = "");
static void HoverWidget(QWidget *w, bool draggable = false, QString objectName = "");
Expand Down
72 changes: 24 additions & 48 deletions gui/include/gui/widgets/plotinfo.h
Original file line number Diff line number Diff line change
@@ -1,71 +1,47 @@
#ifndef PLOTINFO_H
#define PLOTINFO_H

#include "plotwidget.h"

#include <QLabel>
#include "hoverwidget.h"
#include <QWidget>

#include <plot_utils.hpp>
#include <scopy-gui_export.h>
#include <stylehelper.h>

class QLabel;
namespace scopy {

class SCOPY_GUI_EXPORT TimePlotHDivInfo : public QLabel
enum InfoPosition
{
Q_OBJECT
public:
TimePlotHDivInfo(QWidget *parent = nullptr);
virtual ~TimePlotHDivInfo();

public Q_SLOTS:
void update(double val, bool zoomed = false);

private:
MetricPrefixFormatter *m_mpf;
IP_LEFT,
IP_RIGHT
};

class SCOPY_GUI_EXPORT TimePlotSamplingInfo : public QLabel
class SCOPY_GUI_EXPORT PlotInfo : public QWidget
{
Q_OBJECT
public:
TimePlotSamplingInfo(QWidget *parent = nullptr);
virtual ~TimePlotSamplingInfo();
PlotInfo(QWidget *parent = nullptr);
virtual ~PlotInfo();

public Q_SLOTS:
void update(int ps, int bs, double sr);
void addCustomInfo(QWidget *info, InfoPosition pos);
QLabel *addLabelInfo(InfoPosition pos);

private:
MetricPrefixFormatter *m_mpf;
};
void removeInfo(uint index, InfoPosition pos);
QWidget *getInfo(uint index, InfoPosition pos);

class SCOPY_GUI_EXPORT TimePlotStatusInfo : public QLabel
{
Q_OBJECT
public:
TimePlotStatusInfo(QWidget *parent = nullptr);
virtual ~TimePlotStatusInfo();
};
protected:
void initLayouts();

class SCOPY_GUI_EXPORT TimePlotVDivInfo : public QWidget
{};

class SCOPY_GUI_EXPORT TimePlotInfo : public QWidget
{
Q_OBJECT
public:
TimePlotInfo(PlotWidget *plot, QWidget *parent = nullptr);
virtual ~TimePlotInfo();
private:
QWidget *m_parent;
int m_margin;
int m_spacing;

public Q_SLOTS:
void update(PlotSamplingInfo info);
QWidget *m_leftInfo;
HoverWidget *m_leftHover;
QVBoxLayout *m_leftLayout;

private:
PlotWidget *m_plot;
TimePlotHDivInfo *m_hdiv;
TimePlotSamplingInfo *m_sampling;
TimePlotStatusInfo *m_status;
QWidget *m_rightInfo;
HoverWidget *m_rightHover;
QVBoxLayout *m_rightLayout;
};

} // namespace scopy
Expand Down
72 changes: 72 additions & 0 deletions gui/include/gui/widgets/plotinfowidgets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#ifndef PLOTINFOWIDGETS_H
#define PLOTINFOWIDGETS_H

#include <QLabel>
#include <QWidget>
#include <plot_utils.hpp>
#include <plotwidget.h>
#include <scopy-gui_export.h>

namespace scopy {

class SCOPY_GUI_EXPORT HDivInfo : public QLabel
{
Q_OBJECT
public:
HDivInfo(PlotWidget *plot, QWidget *parent = nullptr);
virtual ~HDivInfo();

public Q_SLOTS:
void update(double val, bool zoomed = false);
void onRectChanged();

private:
MetricPrefixFormatter *m_mpf;
PlotWidget *m_plot;
};

class SCOPY_GUI_EXPORT TimeSamplingInfo : public QLabel
{
Q_OBJECT
public:
TimeSamplingInfo(QWidget *parent = nullptr);
virtual ~TimeSamplingInfo();

public Q_SLOTS:
void update(PlotSamplingInfo info);

private:
MetricPrefixFormatter *m_mpf;
};

class SCOPY_GUI_EXPORT FPSInfo : public QLabel
{
Q_OBJECT
public:
FPSInfo(PlotWidget *plot, QWidget *parent = nullptr);
virtual ~FPSInfo();

public Q_SLOTS:
void update(qint64 timestamp);

private:
PlotWidget *m_plot;
QList<qint64> *m_replotTimes;
qint64 m_lastTimeStamp;
int m_avgSize;
};

class SCOPY_GUI_EXPORT TimestampInfo : public QLabel
{
Q_OBJECT
public:
TimestampInfo(PlotWidget *plot, QWidget *parent = nullptr);
virtual ~TimestampInfo();

private:
PlotWidget *m_plot;
};

} // namespace scopy

#endif // PLOTINFOWIDGETS_H
2 changes: 1 addition & 1 deletion gui/src/plotnavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void PlotNavigator::initResetButton()
connect(m_resetButton, &QPushButton::clicked, this, [=]() { Q_EMIT reset(); });
connect(this, &PlotNavigator::rectChanged, this, [=]() { m_resetButton->setVisible(isZoomed()); });

m_resetHover = new HoverWidget(m_resetButton, m_plot, m_plot);
m_resetHover = new HoverWidget(m_resetButton, m_plot->canvas(), m_plot->canvas());
m_resetHover->setAnchorPos(HoverPosition::HP_BOTTOMRIGHT);
m_resetHover->setContentPos(HoverPosition::HP_TOPLEFT);
m_resetHover->setAnchorOffset(QPoint(-6, -6));
Expand Down
Loading
Loading