-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef PLOTINFO_H | ||
#define PLOTINFO_H | ||
|
||
#include "hoverwidget.h" | ||
#include <QWidget> | ||
#include <scopy-gui_export.h> | ||
|
||
class QLabel; | ||
namespace scopy { | ||
|
||
enum InfoPosition | ||
{ | ||
IP_LEFT, | ||
IP_RIGHT | ||
}; | ||
|
||
class SCOPY_GUI_EXPORT PlotInfo : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
PlotInfo(QWidget *parent = nullptr); | ||
virtual ~PlotInfo(); | ||
|
||
void addCustomInfo(QWidget *info, InfoPosition pos); | ||
QLabel *addLabelInfo(InfoPosition pos); | ||
|
||
Q_SIGNALS: | ||
|
||
protected: | ||
void initLayouts(); | ||
|
||
private: | ||
QWidget *m_parent; | ||
QWidget *m_leftInfo; | ||
HoverWidget *m_leftHover; | ||
QWidget *m_rightInfo; | ||
HoverWidget *m_rightHover; | ||
int m_margin; | ||
int m_spacing; | ||
}; | ||
|
||
} // namespace scopy | ||
|
||
#endif // PLOTINFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#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); | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "plotinfo2.h" | ||
|
||
#include <QLabel> | ||
#include <stylehelper.h> | ||
|
||
using namespace scopy; | ||
|
||
PlotInfo::PlotInfo(QWidget *parent) | ||
: QWidget(parent) | ||
, m_parent(parent) | ||
, m_margin(6) | ||
, m_spacing(6) | ||
, m_leftInfo(new QWidget()) | ||
, m_rightInfo(new QWidget()) | ||
{ | ||
initLayouts(); | ||
} | ||
|
||
PlotInfo::~PlotInfo() {} | ||
|
||
void PlotInfo::addCustomInfo(QWidget *info, InfoPosition pos) | ||
{ | ||
switch(pos) { | ||
case InfoPosition::IP_LEFT: | ||
m_leftInfo->layout()->addWidget(info); | ||
info->setParent(m_leftInfo); | ||
break; | ||
|
||
case InfoPosition::IP_RIGHT: | ||
m_rightInfo->layout()->addWidget(info); | ||
info->setParent(m_rightInfo); | ||
break; | ||
} | ||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | ||
} | ||
|
||
QLabel *PlotInfo::addLabelInfo(InfoPosition pos) | ||
{ | ||
QLabel *label = new QLabel(); | ||
StyleHelper::TimePlotSamplingInfo(label); | ||
addCustomInfo(label, pos); | ||
|
||
return label; | ||
} | ||
|
||
void PlotInfo::initLayouts() | ||
{ | ||
// left info | ||
m_leftInfo->setAttribute(Qt::WA_TransparentForMouseEvents); | ||
QVBoxLayout *leftLayout = new QVBoxLayout(m_leftInfo); | ||
leftLayout->setSpacing(m_spacing); | ||
leftLayout->setMargin(m_margin); | ||
leftLayout->setAlignment(Qt::AlignLeft); | ||
|
||
m_leftHover = new HoverWidget(m_leftInfo, m_parent, m_parent); | ||
m_leftHover->setAnchorPos(HoverPosition::HP_TOPLEFT); | ||
m_leftHover->setContentPos(HoverPosition::HP_BOTTOMRIGHT); | ||
m_leftHover->setAttribute(Qt::WA_TransparentForMouseEvents); | ||
m_leftHover->show(); | ||
|
||
// right info | ||
m_rightInfo->setAttribute(Qt::WA_TransparentForMouseEvents); | ||
QVBoxLayout *rightLayout = new QVBoxLayout(m_rightInfo); | ||
rightLayout->setSpacing(m_spacing); | ||
rightLayout->setMargin(m_margin); | ||
rightLayout->setAlignment(Qt::AlignRight); | ||
|
||
m_rightHover = new HoverWidget(m_rightInfo, m_parent, m_parent); | ||
m_rightHover->setAnchorPos(HoverPosition::HP_TOPRIGHT); | ||
m_rightHover->setContentPos(HoverPosition::HP_BOTTOMLEFT); | ||
m_rightHover->setAttribute(Qt::WA_TransparentForMouseEvents); | ||
m_rightHover->show(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "plotinfowidgets.h" | ||
#include "plotaxis.h" | ||
#include "plotnavigator.hpp" | ||
#include "plotwidget.h" | ||
#include <QDateTime> | ||
#include <stylehelper.h> | ||
|
||
using namespace scopy; | ||
|
||
HDivInfo::HDivInfo(PlotWidget *plot, QWidget *parent) | ||
: m_mpf(new MetricPrefixFormatter(this)) | ||
, m_plot(plot) | ||
{ | ||
StyleHelper::TimePlotHDivInfo(this); | ||
m_mpf->setTrimZeroes(true); | ||
connect(m_plot->navigator(), &PlotNavigator::rectChanged, [=]() { | ||
PlotAxis *xAxis = m_plot->xAxis(); | ||
double currMin, currMax, axisMax, axisMin, divs; | ||
bool zoomed; | ||
|
||
axisMax = xAxis->max(); | ||
axisMin = xAxis->min(); | ||
currMax = xAxis->visibleMax(); | ||
currMin = xAxis->visibleMin(); | ||
zoomed = axisMax != currMax || axisMin != currMin; | ||
divs = xAxis->divs(); | ||
update(abs(currMax - currMin) / divs, zoomed); | ||
}); | ||
} | ||
|
||
HDivInfo::~HDivInfo() {} | ||
|
||
void HDivInfo::update(double val, bool zoomed) | ||
{ | ||
setText(m_mpf->format(val, "s", 2) + "/div" + (zoomed ? " (zoomed)" : "")); | ||
} | ||
|
||
TimeSamplingInfo::TimeSamplingInfo(QWidget *parent) | ||
: m_mpf(new MetricPrefixFormatter(this)) | ||
{ | ||
StyleHelper::TimePlotSamplingInfo(this); | ||
m_mpf->setTrimZeroes(true); | ||
} | ||
|
||
TimeSamplingInfo::~TimeSamplingInfo() {} | ||
|
||
void TimeSamplingInfo::update(PlotSamplingInfo info) | ||
{ | ||
QString text; | ||
text = QString("%1").arg(m_mpf->format(info.plotSize, "samples", 2)); | ||
//.arg(m_mpf->format(binfo.bufferSizes, "samples", 2)); | ||
// if(info.sampleRate != 1.0) | ||
text += QString(" at %2").arg(m_mpf->format(info.sampleRate, "sps", 2)); | ||
|
||
setText(text); | ||
} | ||
|
||
FPSInfo::FPSInfo(PlotWidget *plot, QWidget *parent) | ||
: m_plot(plot) | ||
, m_replotTimes(new QList<qint64>()) | ||
, m_lastTimeStamp(0) | ||
, m_avgSize(10) | ||
{ | ||
StyleHelper::TimePlotSamplingInfo(this); | ||
connect(m_plot, &PlotWidget::newData, this, [=]() { update(QDateTime::currentMSecsSinceEpoch()); }); | ||
} | ||
|
||
FPSInfo::~FPSInfo() {} | ||
|
||
void FPSInfo::update(qint64 timestamp) | ||
{ | ||
if(m_lastTimeStamp == 0) { | ||
m_lastTimeStamp = timestamp; | ||
return; | ||
} | ||
|
||
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")); | ||
} | ||
|
||
TimestampInfo::TimestampInfo(PlotWidget *plot, QWidget *parent) | ||
{ | ||
StyleHelper::TimePlotSamplingInfo(this); | ||
connect(plot, &PlotWidget::newData, this, | ||
[=]() { setText(QDateTime::currentDateTime().time().toString("hh:mm:ss.zzz")); }); | ||
} | ||
|
||
TimestampInfo::~TimestampInfo() {} |