10#include <QPainterPath>
17#define DESIRED_SAMPLES 800
27 timer =
new QTimer(
this);
44 int sampleCount = samples.size();
49 for(
int i = 0; i < sampleCount; ++i) {
51 int y =
YMARGIN + h - (int)(h * samples.at(i) /
fMax);
60 QPainter painter(
this);
61 painter.fillRect(rect(), Qt::black);
63 if(
fMax <= 0.0f)
return;
65 QColor axisCol(Qt::gray);
67 painter.setPen(axisCol);
71 int base = std::floor(std::log10(
fMax));
72 float val = std::pow(10.0f, base);
74 const QString units = tr(
"kB/s");
75 const float yMarginText = 2.0;
78 painter.setPen(axisCol);
79 painter.drawText(
XMARGIN,
YMARGIN + h - h * val /
fMax-yMarginText, QString(
"%1 %2").arg(val).arg(units));
80 for(
float y = val; y <
fMax; y += val) {
85 if(
fMax / val <= 3.0f) {
86 axisCol = axisCol.darker();
87 val = pow(10.0f, base - 1);
88 painter.setPen(axisCol);
89 painter.drawText(
XMARGIN,
YMARGIN + h - h * val /
fMax-yMarginText, QString(
"%1 %2").arg(val).arg(units));
91 for(
float y = val; y <
fMax; y += val,
count++) {
100 painter.setRenderHint(QPainter::Antialiasing);
104 painter.fillPath(p, QColor(0, 255, 0, 128));
105 painter.setPen(Qt::green);
111 painter.fillPath(p, QColor(255, 0, 0, 128));
112 painter.setPen(Qt::red);
123 float in_rate_kilobytes_per_sec =
static_cast<float>(bytesIn -
nLastBytesIn) /
timer->interval();
124 float out_rate_kilobytes_per_sec =
static_cast<float>(bytesOut -
nLastBytesOut) /
timer->interval();
125 vSamplesIn.push_front(in_rate_kilobytes_per_sec);
126 vSamplesOut.push_front(out_rate_kilobytes_per_sec);
139 if(f > tmax) tmax = f;
142 if(f > tmax) tmax = f;
151 const auto msecs_per_sample{std::chrono::duration_cast<std::chrono::milliseconds>(
m_range) /
DESIRED_SAMPLES};
153 timer->setInterval(msecs_per_sample);
Model for Bitcoin network client.
interfaces::Node & node() const
virtual int64_t getTotalBytesRecv()=0
Get total bytes recv.
virtual int64_t getTotalBytesSent()=0
Get total bytes sent.