KCoreAddons

kformatprivate.cpp
1 /*
2  This file is part of the KDE Frameworks
3 
4  SPDX-FileCopyrightText: 2013 Alex Merry <[email protected]>
5  SPDX-FileCopyrightText: 2013 John Layt <[email protected]>
6  SPDX-FileCopyrightText: 2010 Michael Leupold <[email protected]>
7  SPDX-FileCopyrightText: 2009 Michael Pyne <[email protected]>
8  SPDX-FileCopyrightText: 2008 Albert Astals Cid <[email protected]>
9 
10  SPDX-License-Identifier: LGPL-2.0-or-later
11 */
12 
13 #include "kformatprivate_p.h"
14 
15 #include <QDateTime>
16 
17 #include <math.h>
18 
19 KFormatPrivate::KFormatPrivate(const QLocale &locale)
20 {
21  m_locale = locale;
22 }
23 
24 KFormatPrivate::~KFormatPrivate()
25 {
26 }
27 
28 constexpr double bpow(int exp) {
29  return (exp > 0) ? 2.0 * bpow(exp - 1) :
30  (exp < 0) ? 0.5 * bpow(exp + 1) :
31  1.0;
32 }
33 
34 QString KFormatPrivate::formatValue(double value,
35  KFormat::Unit unit,
36  QString unitString,
37  int precision,
38  KFormat::UnitPrefix prefix,
39  KFormat::BinaryUnitDialect dialect) const
40 {
41  if (dialect <= KFormat::DefaultBinaryDialect || dialect > KFormat::LastBinaryDialect) {
42  dialect = KFormat::IECBinaryDialect;
43  }
44 
45  if (static_cast<int>(prefix) < static_cast<int>(KFormat::UnitPrefix::Yocto) ||
46  static_cast<int>(prefix) > static_cast<int>(KFormat::UnitPrefix::Yotta)) {
48  }
49 
50  double multiplier = 1024.0;
51  if (dialect == KFormat::MetricBinaryDialect) {
52  multiplier = 1000.0;
53  }
54 
55  int power = 0;
56  if (prefix == KFormat::UnitPrefix::AutoAdjust) {
57  double adjustValue = qAbs(value);
58  while (adjustValue >= multiplier) {
59  adjustValue /= multiplier;
60  power += 1;
61  }
62  while (adjustValue && adjustValue < 1.0) {
63  adjustValue *= multiplier;
64  power -= 1;
65  }
66  const KFormat::UnitPrefix map[] = {
84  };
85  power = std::max(-8, std::min(8, power));
86  prefix = map[power + 8];
87  }
88 
89  if (prefix == KFormat::UnitPrefix::Unity &&
90  unit == KFormat::Unit::Byte) {
91  precision = 0;
92  }
93 
94  struct PrefixMapEntry
95  {
96  KFormat::UnitPrefix prefix;
97  double decimalFactor;
98  double binaryFactor;
99  QString prefixCharSI;
100  QString prefixCharIEC;
101  };
102 
103  const PrefixMapEntry map[] = {
104  { KFormat::UnitPrefix::Yocto, 1e-24, bpow(-80), tr("y", "SI prefix for 10^⁻24"), QString() },
105  { KFormat::UnitPrefix::Zepto, 1e-21, bpow(-70), tr("z", "SI prefix for 10^⁻21"), QString() },
106  { KFormat::UnitPrefix::Atto, 1e-18, bpow(-60), tr("a", "SI prefix for 10^⁻18"), QString() },
107  { KFormat::UnitPrefix::Femto, 1e-15, bpow(-50), tr("f", "SI prefix for 10^⁻15"), QString() },
108  { KFormat::UnitPrefix::Pico, 1e-12, bpow(-40), tr("p", "SI prefix for 10^⁻12"), QString() },
109  { KFormat::UnitPrefix::Nano, 1e-9, bpow(-30), tr("n", "SI prefix for 10^⁻9") , QString() },
110  { KFormat::UnitPrefix::Micro, 1e-6, bpow(-20), tr("µ", "SI prefix for 10^⁻6") , QString() },
111  { KFormat::UnitPrefix::Milli, 1e-3, bpow(-10), tr("m", "SI prefix for 10^⁻3") , QString() },
112  { KFormat::UnitPrefix::Unity, 1.0, 1.0 , QString() , QString() },
113  { KFormat::UnitPrefix::Kilo, 1e3, bpow(10) , tr("k", "SI prefix for 10^3") , tr("Ki", "IEC binary prefix for 2^10") },
114  { KFormat::UnitPrefix::Mega, 1e6, bpow(20) , tr("M", "SI prefix for 10^6") , tr("Mi", "IEC binary prefix for 2^20") },
115  { KFormat::UnitPrefix::Giga, 1e9, bpow(30) , tr("G", "SI prefix for 10^9") , tr("Gi", "IEC binary prefix for 2^30") },
116  { KFormat::UnitPrefix::Tera, 1e12, bpow(40) , tr("T", "SI prefix for 10^12") , tr("Ti", "IEC binary prefix for 2^40") },
117  { KFormat::UnitPrefix::Peta, 1e15, bpow(50) , tr("P", "SI prefix for 10^15") , tr("Pi", "IEC binary prefix for 2^50") },
118  { KFormat::UnitPrefix::Exa, 1e18, bpow(60) , tr("E", "SI prefix for 10^18") , tr("Ei", "IEC binary prefix for 2^60") },
119  { KFormat::UnitPrefix::Zetta, 1e21, bpow(70) , tr("Z", "SI prefix for 10^21") , tr("Zi", "IEC binary prefix for 2^70") },
120  { KFormat::UnitPrefix::Yotta, 1e24, bpow(80) , tr("Y", "SI prefix for 10^24") , tr("Yi", "IEC binary prefix for 2^80") },
121  };
122 
123  auto entry = std::find_if(std::begin(map), std::end(map),
124  [prefix](const PrefixMapEntry& e) { return e.prefix == prefix; });
125 
126  switch (unit) {
127  case KFormat::Unit::Bit:
128  unitString = tr("bit", "Symbol of binary digit");
129  break;
130  case KFormat::Unit::Byte:
131  unitString = tr("B", "Symbol of byte");
132  break;
134  unitString = tr("m", "Symbol of meter");
135  break;
137  unitString = tr("Hz", "Symbol of hertz");
138  break;
139  case KFormat::Unit::Other:
140  break;
141  }
142 
143  if (prefix == KFormat::UnitPrefix::Unity) {
144  QString numString = m_locale.toString(value, 'f', precision);
145  //: value without prefix, format "<val> <unit>"
146  return tr("%1 %2", "no Prefix").arg(numString, unitString);
147  }
148 
149  QString prefixString;
150  if (dialect == KFormat::MetricBinaryDialect) {
151  value /= entry->decimalFactor;
152  prefixString = entry->prefixCharSI;
153  } else {
154  value /= entry->binaryFactor;
155  if (dialect == KFormat::IECBinaryDialect) {
156  prefixString = entry->prefixCharIEC;
157  } else {
158  prefixString = entry->prefixCharSI.toUpper();
159  }
160  }
161 
162  QString numString = m_locale.toString(value, 'f', precision);
163 
164  //: value with prefix, format "<val> <prefix><unit>"
165  return tr("%1 %2%3", "MetricBinaryDialect").arg(numString, prefixString, unitString);
166 }
167 
168 QString KFormatPrivate::formatByteSize(double size, int precision,
170 {
171  // Current KDE default is IECBinaryDialect
172  if (dialect <= KFormat::DefaultBinaryDialect || dialect > KFormat::LastBinaryDialect) {
173  dialect = KFormat::IECBinaryDialect;
174  }
175 
176  // Current KDE default is to auto-adjust so the size falls in the range 0 to 1000/1024
177  if (units < KFormat::DefaultBinaryUnits || units > KFormat::UnitLastUnit) {
179  }
180 
181  int unit = 0; // Selects what unit to use
182  double multiplier = 1024.0;
183 
184  if (dialect == KFormat::MetricBinaryDialect) {
185  multiplier = 1000.0;
186  }
187 
188  // If a specific unit conversion is given, use it directly. Otherwise
189  // search until the result is in [0, multiplier] (or out of our range).
190  if (units == KFormat::DefaultBinaryUnits) {
191  while (qAbs(size) >= multiplier && unit < int(KFormat::UnitYottaByte)) {
192  size /= multiplier;
193  ++unit;
194  }
195  } else {
196  // A specific unit is in use
197  unit = static_cast<int>(units);
198  if (unit > 0) {
199  size /= pow(multiplier, unit);
200  }
201  }
202 
203  // Bytes, no rounding
204  if (unit == 0) {
205  precision = 0;
206  }
207 
208  QString numString = m_locale.toString(size, 'f', precision);
209 
210  // Do not remove "//:" comments below, they are used by the translators.
211  // NB: we cannot pass pluralization arguments, as the size may be negative
212  if (dialect == KFormat::MetricBinaryDialect) {
213  switch (unit) {
214  case KFormat::UnitByte:
215  //: MetricBinaryDialect size in bytes
216  return tr("%1 B", "MetricBinaryDialect").arg(numString);
218  //: MetricBinaryDialect size in 1000 bytes
219  return tr("%1 kB", "MetricBinaryDialect").arg(numString);
221  //: MetricBinaryDialect size in 10^6 bytes
222  return tr("%1 MB", "MetricBinaryDialect").arg(numString);
224  //: MetricBinaryDialect size in 10^9 bytes
225  return tr("%1 GB", "MetricBinaryDialect").arg(numString);
227  //: MetricBinaryDialect size in 10^12 bytes
228  return tr("%1 TB", "MetricBinaryDialect").arg(numString);
230  //: MetricBinaryDialect size in 10^15 bytes
231  return tr("%1 PB", "MetricBinaryDialect").arg(numString);
233  //: MetricBinaryDialect size in 10^18 byte
234  return tr("%1 EB", "MetricBinaryDialect").arg(numString);
236  //: MetricBinaryDialect size in 10^21 bytes
237  return tr("%1 ZB", "MetricBinaryDialect").arg(numString);
239  //: MetricBinaryDialect size in 10^24 bytes
240  return tr("%1 YB", "MetricBinaryDialect").arg(numString);
241  }
242  } else if (dialect == KFormat::JEDECBinaryDialect) {
243  switch (unit) {
244  case KFormat::UnitByte:
245  //: JEDECBinaryDialect memory size in bytes
246  return tr("%1 B", "JEDECBinaryDialect").arg(numString);
248  //: JEDECBinaryDialect memory size in 1024 bytes
249  return tr("%1 KB", "JEDECBinaryDialect").arg(numString);
251  //: JEDECBinaryDialect memory size in 10^20 bytes
252  return tr("%1 MB", "JEDECBinaryDialect").arg(numString);
254  //: JEDECBinaryDialect memory size in 10^30 bytes
255  return tr("%1 GB", "JEDECBinaryDialect").arg(numString);
257  //: JEDECBinaryDialect memory size in 10^40 bytes
258  return tr("%1 TB", "JEDECBinaryDialect").arg(numString);
260  //: JEDECBinaryDialect memory size in 10^50 bytes
261  return tr("%1 PB", "JEDECBinaryDialect").arg(numString);
263  //: JEDECBinaryDialect memory size in 10^60 bytes
264  return tr("%1 EB", "JEDECBinaryDialect").arg(numString);
266  //: JEDECBinaryDialect memory size in 10^70 bytes
267  return tr("%1 ZB", "JEDECBinaryDialect").arg(numString);
269  //: JEDECBinaryDialect memory size in 10^80 bytes
270  return tr("%1 YB", "JEDECBinaryDialect").arg(numString);
271  }
272  } else { // KFormat::IECBinaryDialect, KFormat::DefaultBinaryDialect
273  switch (unit) {
274  case KFormat::UnitByte:
275  //: IECBinaryDialect size in bytes
276  return tr("%1 B", "IECBinaryDialect").arg(numString);
278  //: IECBinaryDialect size in 1024 bytes
279  return tr("%1 KiB", "IECBinaryDialect").arg(numString);
281  //: IECBinaryDialect size in 10^20 bytes
282  return tr("%1 MiB", "IECBinaryDialect").arg(numString);
284  //: IECBinaryDialect size in 10^30 bytes
285  return tr("%1 GiB", "IECBinaryDialect").arg(numString);
287  //: IECBinaryDialect size in 10^40 bytes
288  return tr("%1 TiB", "IECBinaryDialect").arg(numString);
290  //: IECBinaryDialect size in 10^50 bytes
291  return tr("%1 PiB", "IECBinaryDialect").arg(numString);
293  //: IECBinaryDialect size in 10^60 bytes
294  return tr("%1 EiB", "IECBinaryDialect").arg(numString);
296  //: IECBinaryDialect size in 10^70 bytes
297  return tr("%1 ZiB", "IECBinaryDialect").arg(numString);
299  //: IECBinaryDialect size in 10^80 bytes
300  return tr("%1 YiB", "IECBinaryDialect").arg(numString);
301  }
302  }
303 
304  // Should never reach here
305  Q_ASSERT(false);
306  return numString;
307 }
308 
309 enum TimeConstants {
310  MSecsInDay = 86400000,
311  MSecsInHour = 3600000,
312  MSecsInMinute = 60000,
313  MSecsInSecond = 1000
314 };
315 
316 QString KFormatPrivate::formatDuration(quint64 msecs, KFormat::DurationFormatOptions options) const
317 {
318  quint64 ms = msecs;
319  if (options & KFormat::HideSeconds) {
320  //round to nearest minute
321  ms = qRound64(ms / (qreal)MSecsInMinute) * MSecsInMinute ;
322  } else if (!(options & KFormat::ShowMilliseconds)) {
323  //round to nearest second
324  ms = qRound64(ms / (qreal)MSecsInSecond) * MSecsInSecond ;
325  }
326 
327  int hours = ms / MSecsInHour;
328  ms = ms % MSecsInHour;
329  int minutes = ms / MSecsInMinute;
330  ms = ms % MSecsInMinute;
331  int seconds = ms / MSecsInSecond;
332  ms = ms % MSecsInSecond;
333 
334  if ((options & KFormat::InitialDuration) == KFormat::InitialDuration) {
335 
336  if ((options & KFormat::FoldHours) == KFormat::FoldHours
337  && (options & KFormat::ShowMilliseconds) == KFormat::ShowMilliseconds) {
338  //: @item:intext Duration format minutes, seconds and milliseconds
339  return tr("%1m%2.%3s").arg(hours * 60 + minutes, 1, 10, QLatin1Char('0'))
340  .arg(seconds, 2, 10, QLatin1Char('0'))
341  .arg(ms, 3, 10, QLatin1Char('0'));
342  } else if ((options & KFormat::FoldHours) == KFormat::FoldHours) {
343  //: @item:intext Duration format minutes and seconds
344  return tr("%1m%2s").arg(hours * 60 + minutes, 1, 10, QLatin1Char('0'))
345  .arg(seconds, 2, 10, QLatin1Char('0'));
346  } else if ((options & KFormat::HideSeconds) == KFormat::HideSeconds) {
347  //: @item:intext Duration format hours and minutes
348  return tr("%1h%2m").arg(hours, 1, 10, QLatin1Char('0'))
349  .arg(minutes, 2, 10, QLatin1Char('0'));
350  } else if ((options & KFormat::ShowMilliseconds) == KFormat::ShowMilliseconds) {
351  //: @item:intext Duration format hours, minutes, seconds, milliseconds
352  return tr("%1h%2m%3.%4s").arg(hours, 1, 10, QLatin1Char('0'))
353  .arg(minutes, 2, 10, QLatin1Char('0'))
354  .arg(seconds, 2, 10, QLatin1Char('0'))
355  .arg(ms, 3, 10, QLatin1Char('0'));
356  } else { // Default
357  //: @item:intext Duration format hours, minutes, seconds
358  return tr("%1h%2m%3s").arg(hours, 1, 10, QLatin1Char('0'))
359  .arg(minutes, 2, 10, QLatin1Char('0'))
360  .arg(seconds, 2, 10, QLatin1Char('0'));
361  }
362 
363  } else {
364 
365  if ((options & KFormat::FoldHours) == KFormat::FoldHours
366  && (options & KFormat::ShowMilliseconds) == KFormat::ShowMilliseconds) {
367  //: @item:intext Duration format minutes, seconds and milliseconds
368  return tr("%1:%2.%3").arg(hours * 60 + minutes, 1, 10, QLatin1Char('0'))
369  .arg(seconds, 2, 10, QLatin1Char('0'))
370  .arg(ms, 3, 10, QLatin1Char('0'));
371  } else if ((options & KFormat::FoldHours) == KFormat::FoldHours) {
372  //: @item:intext Duration format minutes and seconds
373  return tr("%1:%2").arg(hours * 60 + minutes, 1, 10, QLatin1Char('0'))
374  .arg(seconds, 2, 10, QLatin1Char('0'));
375  } else if ((options & KFormat::HideSeconds) == KFormat::HideSeconds) {
376  //: @item:intext Duration format hours and minutes
377  return tr("%1:%2").arg(hours, 1, 10, QLatin1Char('0'))
378  .arg(minutes, 2, 10, QLatin1Char('0'));
379  } else if ((options & KFormat::ShowMilliseconds) == KFormat::ShowMilliseconds) {
380  //: @item:intext Duration format hours, minutes, seconds, milliseconds
381  return tr("%1:%2:%3.%4").arg(hours, 1, 10, QLatin1Char('0'))
382  .arg(minutes, 2, 10, QLatin1Char('0'))
383  .arg(seconds, 2, 10, QLatin1Char('0'))
384  .arg(ms, 3, 10, QLatin1Char('0'));
385  } else { // Default
386  //: @item:intext Duration format hours, minutes, seconds
387  return tr("%1:%2:%3").arg(hours, 1, 10, QLatin1Char('0'))
388  .arg(minutes, 2, 10, QLatin1Char('0'))
389  .arg(seconds, 2, 10, QLatin1Char('0'));
390  }
391 
392  }
393 
394  Q_UNREACHABLE();
395  return QString();
396 }
397 
398 QString KFormatPrivate::formatDecimalDuration(quint64 msecs, int decimalPlaces) const
399 {
400  if (msecs >= MSecsInDay) {
401  //: @item:intext %1 is a real number, e.g. 1.23 days
402  return tr("%1 days").arg(m_locale.toString(msecs / (MSecsInDay * 1.0), 'f', decimalPlaces));
403  } else if (msecs >= MSecsInHour) {
404  //: @item:intext %1 is a real number, e.g. 1.23 hours
405  return tr("%1 hours").arg(m_locale.toString(msecs / (MSecsInHour * 1.0), 'f', decimalPlaces));
406  } else if (msecs >= MSecsInMinute) {
407  //: @item:intext %1 is a real number, e.g. 1.23 minutes
408  return tr("%1 minutes").arg(m_locale.toString(msecs / (MSecsInMinute * 1.0), 'f', decimalPlaces));
409  } else if (msecs >= MSecsInSecond) {
410  //: @item:intext %1 is a real number, e.g. 1.23 seconds
411  return tr("%1 seconds").arg(m_locale.toString(msecs / (MSecsInSecond * 1.0), 'f', decimalPlaces));
412  }
413  //: @item:intext %1 is a whole number
414  //~ singular %n millisecond
415  //~ plural %n milliseconds
416  return tr("%n millisecond(s)", nullptr, msecs);
417 }
418 
419 enum DurationUnits {
420  Days = 0,
421  Hours,
422  Minutes,
423  Seconds
424 };
425 
426 static QString formatSingleDuration(DurationUnits units, int n)
427 {
428  // NB: n is guaranteed to be non-negative
429  switch (units) {
430  case Days:
431  //: @item:intext %n is a whole number
432  //~ singular %n day
433  //~ plural %n days
434  return KFormatPrivate::tr("%n day(s)", nullptr, n);
435  case Hours:
436  //: @item:intext %n is a whole number
437  //~ singular %n hour
438  //~ plural %n hours
439  return KFormatPrivate::tr("%n hour(s)", nullptr, n);
440  case Minutes:
441  //: @item:intext %n is a whole number
442  //~ singular %n minute
443  //~ plural %n minutes
444  return KFormatPrivate::tr("%n minute(s)", nullptr, n);
445  case Seconds:
446  //: @item:intext %n is a whole number
447  //~ singular %n second
448  //~ plural %n seconds
449  return KFormatPrivate::tr("%n second(s)", nullptr, n);
450  }
451  Q_ASSERT(false);
452  return QString();
453 }
454 
455 QString KFormatPrivate::formatSpelloutDuration(quint64 msecs) const
456 {
457  quint64 ms = msecs;
458  int days = ms / MSecsInDay;
459  ms = ms % (MSecsInDay);
460  int hours = ms / MSecsInHour;
461  ms = ms % MSecsInHour;
462  int minutes = ms / MSecsInMinute;
463  ms = ms % MSecsInMinute;
464  int seconds = qRound(ms / 1000.0);
465 
466  // Handle correctly problematic case #1 (look at KFormatTest::prettyFormatDuration())
467  if (seconds == 60) {
468  return formatSpelloutDuration(msecs - ms + MSecsInMinute);
469  }
470 
471  if (days && hours) {
472  /*: @item:intext days and hours. This uses the previous item:intext messages.
473  If this does not fit the grammar of your language please contact the i18n team to solve the problem */
474  return tr("%1 and %2").arg(formatSingleDuration(Days, days), formatSingleDuration(Hours, hours));
475  } else if (days) {
476  return formatSingleDuration(Days, days);
477  } else if (hours && minutes) {
478  /*: @item:intext hours and minutes. This uses the previous item:intext messages.
479  If this does not fit the grammar of your language please contact the i18n team to solve the problem */
480  return tr("%1 and %2").arg(formatSingleDuration(Hours, hours), formatSingleDuration(Minutes, minutes));
481  } else if (hours) {
482  return formatSingleDuration(Hours, hours);
483  } else if (minutes && seconds) {
484  /*: @item:intext minutes and seconds. This uses the previous item:intext messages.
485  If this does not fit the grammar of your language please contact the i18n team to solve the problem */
486  return tr("%1 and %2").arg(formatSingleDuration(Minutes, minutes), formatSingleDuration(Seconds, seconds));
487  } else if (minutes) {
488  return formatSingleDuration(Minutes, minutes);
489  } else {
490  return formatSingleDuration(Seconds, seconds);
491  }
492 }
493 
494 QString KFormatPrivate::formatRelativeDate(const QDate &date, QLocale::FormatType format) const
495 {
496  if (!date.isValid()) {
497  return tr("Invalid date", "used when a relative date string can't be generated because the date is invalid");
498  }
499 
500  const qint64 daysTo = QDate::currentDate().daysTo(date);
501  if (daysTo > 2 || daysTo < -2) {
502  return m_locale.toString(date, format);
503  }
504 
505  switch (daysTo) {
506  case 2:
507  return tr("In two days");
508  case 1:
509  return tr("Tomorrow");
510  case 0:
511  return tr("Today");
512  case -1:
513  return tr("Yesterday");
514  case -2:
515  return tr("Two days ago");
516  }
517  Q_UNREACHABLE();
518 }
519 
520 QString KFormatPrivate::formatRelativeDateTime(const QDateTime &dateTime, QLocale::FormatType format) const
521 {
522  const qint64 daysTo = QDate::currentDate().daysTo(dateTime.date());
523  if (daysTo > 2 || daysTo < -2) {
524  return m_locale.toString(dateTime, format);
525  }
526 
527  /*: relative datetime with %1 result of formatReleativeDate() and %2 the formatted time
528  If this does not fit the grammar of your language please contact the i18n team to solve the problem */
529  return tr("%1, %2").arg(formatRelativeDate(dateTime.date(), format), m_locale.toString(dateTime.time(), format));
530 }
Yi/Y/Y 2^80/10^24.
PiB/PB/PB 2^50/10^15 bytes.
Definition: kformat.h:94
qint64 daysTo(const QDate &d) const const
KiB, MiB, etc. 2^(10*n)
Definition: kformat.h:173
QString toUpper() const const
GiB/GB/GB 2^30/10^09 bytes.
Definition: kformat.h:92
UnitPrefix
These prefixes are used in KDE by the formatValue() function.
Definition: kformat.h:126
BinarySizeUnits
These binary units are used in KDE by the formatByteSize() function.
Definition: kformat.h:84
Mi/M/M 2^20/10^06.
Auto-choose a unit such that the result is in the range [0, 1000 or 1024)
time_t date() const
KiB/KB/kB 1024/1000 bytes.
Definition: kformat.h:90
QTime time() const const
Ei/E/E 2^60/10^18.
Pi/P/P 2^50/10^15.
Fold the hours into the minutes, e.g. 83:45 or 83m45s, overrides HideSeconds.
Definition: kformat.h:188
Zi/Z/Z 2^70/10^21.
Hide the seconds, e.g. 1:23 or 1h23m, overrides ShowMilliseconds.
Definition: kformat.h:187
MiB/MB/MB 2^20/10^06 bytes.
Definition: kformat.h:91
Ki/K/k 1024/1000.
bool isValid() const const
KB, MB, etc. 2^(10*n)
Definition: kformat.h:174
YiB/YB/YB 2^80/10^24 bytes.
Definition: kformat.h:97
Ti/T/T 2^40/10^12.
EiB/EB/EB 2^60/10^18 bytes.
Definition: kformat.h:95
ZiB/ZB/ZB 2^70/10^21 bytes.
Definition: kformat.h:96
Unit
These units are used in KDE by the formatValue() function.
Definition: kformat.h:107
QDate date() const const
BinaryUnitDialect
This enum chooses what dialect is used for binary units.
Definition: kformat.h:171
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QDate currentDate()
Default formatting in localized 1h23m45s format.
Definition: kformat.h:185
Gi/G/G 2^30/10^09.
Auto-choose a unit such that the result is in the range [0, 1000 or 1024)
Definition: kformat.h:86
TiB/TB/TB 2^40/10^12 bytes.
Definition: kformat.h:93
QFuture< void > map(Sequence &sequence, MapFunctor function)
SI Units, kB, MB, etc. 10^(3*n)
Definition: kformat.h:175
B 1 byte.
Definition: kformat.h:89
Include milliseconds in format, e.g. 1:23:45.678.
Definition: kformat.h:186
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun May 31 2020 23:11:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.