diff options
author | Niels Weber <niels.2.weber@nokia.com> | 2012-02-14 11:16:29 +0100 |
---|---|---|
committer | Niels Weber <niels.2.weber@nokia.com> | 2012-02-14 12:24:51 +0100 |
commit | ff7b53da62ca750a66e77436d6a72f09474be6f8 (patch) | |
tree | a3a9f40ff5215b185e8c535524d35273cfbc125a | |
parent | 1b2ceb1e7e87bfa36cf608bdf00523f60dd9ff4d (diff) |
use the same function in the example
Change-Id: I0c67d86256325bbca5f6d0aaad1e18ff1f80c1d5
Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
-rw-r--r-- | examples/downloadspeed/main.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
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 <QtNetwork/QNetworkProxy> -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 |