Skip to content

Commit

Permalink
WIP plotinfo stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei47w committed Apr 19, 2024
1 parent b6659ff commit c692afe
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
1 change: 1 addition & 0 deletions gui/include/gui/plotwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public Q_SLOTS:
void channelSelected(PlotChannel *ch);
void addedChannel(PlotChannel *ch);
void removedChannel(PlotChannel *ch);
void reploted();

private:
QwtPlot *m_plot;
Expand Down
26 changes: 26 additions & 0 deletions gui/include/gui/widgets/plotinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ public Q_SLOTS:
MetricPrefixFormatter *m_mpf;
};

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

public Q_SLOTS:
void update(qint64 timestamp);

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

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

class SCOPY_GUI_EXPORT TimePlotStatusInfo : public QLabel
{
Q_OBJECT
Expand All @@ -66,6 +90,8 @@ public Q_SLOTS:
TimePlotHDivInfo *m_hdiv;
TimePlotSamplingInfo *m_sampling;
TimePlotStatusInfo *m_status;
TimePlotFPS *m_fps;
TimePlotTimestamp *m_timestamp;
};

} // namespace scopy
Expand Down
8 changes: 6 additions & 2 deletions gui/src/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void PlotWidget::setDisplayGraticule(bool newDisplayGraticule)
displayGraticule = newDisplayGraticule;
setAxisScalesVisible(!displayGraticule);
graticule->enableGraticule(displayGraticule);
m_plot->replot();
replot();
}

bool PlotWidget::eventFilter(QObject *object, QEvent *event)
Expand Down Expand Up @@ -281,7 +281,11 @@ PlotAxis *PlotWidget::yAxis() { return m_yAxis; }

QwtPlot *PlotWidget::plot() const { return m_plot; }

void PlotWidget::replot() { m_plot->replot(); }
void PlotWidget::replot()
{
m_plot->replot();
Q_EMIT reploted();
}

void PlotWidget::hideAxisLabels()
{
Expand Down
68 changes: 68 additions & 0 deletions gui/src/widgets/plotinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "hoverwidget.h"
#include "plotaxis.h"
#include "qdatetime.h"

using namespace scopy;

Expand Down Expand Up @@ -39,6 +40,49 @@ void TimePlotSamplingInfo::update(int ps, int bs, double sr)
setText(text);
}

TimePlotFPS::TimePlotFPS(QWidget *parent)
{
StyleHelper::TimePlotSamplingInfo(this);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_replotTimes = new QList<qint64>();
m_lastTimeStamp = 0;
m_avgSize = 10;
}

TimePlotFPS::~TimePlotFPS() {}

void TimePlotFPS::update(qint64 timestamp)
{
if(m_lastTimeStamp == 0) {
m_lastTimeStamp = timestamp;
return;
}

if(abs(timestamp - m_lastTimeStamp) > 2) {
m_replotTimes->append(timestamp - m_lastTimeStamp);
if(m_replotTimes->size() > m_avgSize) {
m_replotTimes->removeAt(0);
}

qint64 avg = 0;
for(qint64 time: *m_replotTimes) {
avg += time;
}
avg /= m_replotTimes->size();
m_lastTimeStamp = timestamp;

setText(QString(QString::number(1000. / avg, 'g', 3) + " FPS"));
}
}

TimePlotTimestamp::TimePlotTimestamp(QWidget *parent)
{
StyleHelper::TimePlotSamplingInfo(this);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
}

TimePlotTimestamp::~TimePlotTimestamp() {}

TimePlotStatusInfo::TimePlotStatusInfo(QWidget *parent)
{
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
Expand All @@ -61,6 +105,14 @@ TimePlotInfo::TimePlotInfo(PlotWidget *plot, QWidget *parent)
m_hdiv = new TimePlotHDivInfo(this);
m_sampling = new TimePlotSamplingInfo(this);
m_status = new TimePlotStatusInfo(this);
m_fps = new TimePlotFPS(this);
connect(plot, &PlotWidget::reploted, this, [=](){
m_fps->update(QDateTime::currentMSecsSinceEpoch());
});
m_timestamp = new TimePlotTimestamp(this);
connect(plot, &PlotWidget::reploted, this, [=](){
m_timestamp->setText(QDateTime::currentDateTime().time().toString());
});

vlay->addLayout(lay);

Expand All @@ -85,6 +137,22 @@ TimePlotInfo::TimePlotInfo(PlotWidget *plot, QWidget *parent)
samplinginfohover->setAnchorOffset(QPoint(-8, 6));
samplinginfohover->show();
samplinginfohover->setAttribute(Qt::WA_TransparentForMouseEvents);

HoverWidget *fpsHover = new HoverWidget(nullptr, plot->plot()->canvas(), plot->plot());
fpsHover->setContent(m_fps);
fpsHover->setAnchorPos(HoverPosition::HP_TOPLEFT);
fpsHover->setContentPos(HoverPosition::HP_BOTTOMRIGHT);
fpsHover->setAnchorOffset(QPoint(8, 26));
fpsHover->show();
fpsHover->setAttribute(Qt::WA_TransparentForMouseEvents);

HoverWidget *timestampHover = new HoverWidget(nullptr, plot->plot()->canvas(), plot->plot());
timestampHover->setContent(m_timestamp);
timestampHover->setAnchorPos(HoverPosition::HP_TOPRIGHT);
timestampHover->setContentPos(HoverPosition::HP_BOTTOMLEFT);
timestampHover->setAnchorOffset(QPoint(-8, 26));
timestampHover->show();
timestampHover->setAttribute(Qt::WA_TransparentForMouseEvents);
#endif
}

Expand Down

0 comments on commit c692afe

Please sign in to comment.