From ff7b53da62ca750a66e77436d6a72f09474be6f8 Mon Sep 17 00:00:00 2001 From: Niels Weber Date: Tue, 14 Feb 2012 11:16:29 +0100 Subject: use the same function in the example Change-Id: I0c67d86256325bbca5f6d0aaad1e18ff1f80c1d5 Reviewed-by: Tim Jenssen --- examples/downloadspeed/main.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/downloadspeed/main.cpp b/examples/downloadspeed/main.cpp index 74686b510..2ed6651bf 100644 --- a/examples/downloadspeed/main.cpp +++ b/examples/downloadspeed/main.cpp @@ -40,20 +40,25 @@ #include -static QString format(double data) +static QString humanReadableSize(quint64 intSize) { - if (data < 1024.0) - return QString::fromLatin1("%L1 B").arg(data); - data /= 1024.0; - if (data < 1024.0) - return QString::fromLatin1("%L1 KB").arg(data, 0, 'f', 2); - data /= 1024.0; - if (data < 1024.0) - return QString::fromLatin1("%L1 MB").arg(data, 0, 'f', 2); - data /= 1024.0; - return QString::fromLatin1("%L1 GB").arg(data, 0, 'f', 2); -} + QString unit; + double size; + + if (intSize < 1024 * 1024) { + size = 1. + intSize / 1024.; + unit = QObject::tr("kB"); + } else if (intSize < 1024 * 1024 * 1024) { + size = 1. + intSize / 1024. / 1024.; + unit = QObject::tr("MB"); + } else { + size = 1. + intSize / 1024. / 1024. / 1024.; + unit = QObject::tr("GB"); + } + size = qRound(size * 10) / 10.0; + return QString::fromLatin1("%L1 %2").arg(size, 0, 'g', 4).arg(unit); +} // -- Receiver -- cgit v1.2.3