aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-03-23 15:57:52 +0100
committerMarcoFalke <falke.marco@gmail.com>2021-03-23 15:57:58 +0100
commit837e59eff6acb03c6c93b5fd36a249c28b39eacf (patch)
tree8a740daef0d1ad8f594798dd99a740af94c4a607 /src
parent3c87dbe95c925274f80234ad4a88beb5a05fdfff (diff)
parentd09ebc47233187ab8dd5a70df4d261353958978c (diff)
Merge bitcoin-core/gui#248: Fix: For values of "Bytes transferred" and "Bytes/s" with 1000-based prefix names use 1000-based divisor instead of 1024-based
d09ebc47233187ab8dd5a70df4d261353958978c Fix wrong(1024) divisor for 1000-based prefixes (wodry) Pull request description: v.0.21.0 I saw in the GUI peer window in the "received" column `1007 KB`, and after increasing to >=1024 I guess, it switched to `1 MB`. I would have expected the display unit to change from KB to MB already at value >=1000. I looked into the code, and the values appear to be power-of-2 byte values, so the switching at >=1024 and not >=1000 seems correct. But the unit display is not precisely correct, binary prefixes should be used for power-of-2 byte values. To be correct, this PR changes ~~KB/MB/GB to KiB/MiB/GiB.~~ KB to kB and the divisor from 1024 to 1000. ACKs for top commit: hebasto: ACK d09ebc47233187ab8dd5a70df4d261353958978c, tested on Linux Mint 20.1 (Qt 5.12.8) the both "Network Traffic" and "Peers" tabs of the "Node Window". jarolrod: ACK d09ebc47233187ab8dd5a70df4d261353958978c leonardojobim: Tested ACK https://github.com/bitcoin-core/gui/pull/248/commits/d09ebc47233187ab8dd5a70df4d261353958978c on Ubuntu 20.04 Qt 5.12.8 Tree-SHA512: 8f830b08cc3fd36dc8a18f1192959fe55d1644938044bf31d770f7c3bf8475fba6da5019a2d2024d5b2c81a8dab112f360c555367814a14f4d05c89d130f25b0
Diffstat (limited to 'src')
-rw-r--r--src/qt/guiutil.cpp12
-rw-r--r--src/qt/trafficgraphwidget.cpp10
2 files changed, 11 insertions, 11 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 32890ed0fe..b4afdbcc22 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -759,14 +759,14 @@ QString formatNiceTimeOffset(qint64 secs)
QString formatBytes(uint64_t bytes)
{
- if(bytes < 1024)
+ if (bytes < 1'000)
return QObject::tr("%1 B").arg(bytes);
- if(bytes < 1024 * 1024)
- return QObject::tr("%1 KB").arg(bytes / 1024);
- if(bytes < 1024 * 1024 * 1024)
- return QObject::tr("%1 MB").arg(bytes / 1024 / 1024);
+ if (bytes < 1'000'000)
+ return QObject::tr("%1 kB").arg(bytes / 1'000);
+ if (bytes < 1'000'000'000)
+ return QObject::tr("%1 MB").arg(bytes / 1'000'000);
- return QObject::tr("%1 GB").arg(bytes / 1024 / 1024 / 1024);
+ return QObject::tr("%1 GB").arg(bytes / 1'000'000'000);
}
qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize, qreal font_size) {
diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp
index dabdf9d887..7e12410c80 100644
--- a/src/qt/trafficgraphwidget.cpp
+++ b/src/qt/trafficgraphwidget.cpp
@@ -79,7 +79,7 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *)
int base = floor(log10(fMax));
float val = pow(10.0f, base);
- const QString units = tr("KB/s");
+ const QString units = tr("kB/s");
const float yMarginText = 2.0;
// draw lines
@@ -128,10 +128,10 @@ void TrafficGraphWidget::updateRates()
quint64 bytesIn = clientModel->node().getTotalBytesRecv(),
bytesOut = clientModel->node().getTotalBytesSent();
- float inRate = (bytesIn - nLastBytesIn) / 1024.0f * 1000 / timer->interval();
- float outRate = (bytesOut - nLastBytesOut) / 1024.0f * 1000 / timer->interval();
- vSamplesIn.push_front(inRate);
- vSamplesOut.push_front(outRate);
+ float in_rate_kilobytes_per_sec = static_cast<float>(bytesIn - nLastBytesIn) / timer->interval();
+ float out_rate_kilobytes_per_sec = static_cast<float>(bytesOut - nLastBytesOut) / timer->interval();
+ vSamplesIn.push_front(in_rate_kilobytes_per_sec);
+ vSamplesOut.push_front(out_rate_kilobytes_per_sec);
nLastBytesIn = bytesIn;
nLastBytesOut = bytesOut;