diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-04-10 12:44:20 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-06-20 09:53:14 +0000 |
commit | 9d23aebb271ea534a66cb3aceb2e63d9a1c870d6 (patch) | |
tree | a78a9b2739aabc594e04cb73cae3a81a24c54dd1 /src/corelib/tools/qlocale.h | |
parent | ccca8c94359e7f07333b710119bfdf00b25b78fd (diff) |
Add QLocale::formattedDataSize and consolidate use cases
It should be easier to translate sizes in bytes to human-readable
strings consistently rather than having to repeat this code (and the
string translations) in various places. The FileDialog in QtQuick.Controls
has a use for this, too.
[ChangeLog][QtCore][QLocale] Added QLocale::formattedDataSize() for
formatting quantities of bytes as kB, MB, GB etc.
Done-with: Edward Welbourne <edward.welbourne@qt.io>
Change-Id: I27bca146c3eba90fa7a5d52ef6626ce85723e3f0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlocale.h')
-rw-r--r-- | src/corelib/tools/qlocale.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index f9482a7e3a..54b1a32946 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -913,6 +913,19 @@ public: CurrencyDisplayName }; + enum DataSizeFormat { + // Single-bit values, for internal use. + DataSizeBase1000 = 1, // use factors of 1000 instead of IEC's 1024; + DataSizeSIQuantifiers = 2, // use SI quantifiers instead of IEC ones. + + // Flags values for use in API: + DataSizeIecFormat = 0, // base 1024, KiB, MiB, GiB, ... + DataSizeTraditionalFormat = DataSizeSIQuantifiers, // base 1024, kB, MB, GB, ... + DataSizeSIFormat = DataSizeBase1000 | DataSizeSIQuantifiers // base 1000, kB, MB, GB, ... + }; + Q_DECLARE_FLAGS(DataSizeFormats, DataSizeFormat) + Q_FLAG(DataSizeFormats) + QLocale(); QLocale(const QString &name); QLocale(Language language, Country country = AnyCountry); @@ -1045,6 +1058,8 @@ public: { return toCurrencyString(double(i), symbol, precision); } #endif + QString formattedDataSize(qint64 bytes, int precision = 2, DataSizeFormats format = DataSizeIecFormat); + QStringList uiLanguages() const; bool operator==(const QLocale &other) const; |