KCoreAddons

kformat.cpp
1 /* This file is part of the KDE Frameworks
2 
3  SPDX-FileCopyrightText: 2013 Alex Merry <[email protected]>
4  SPDX-FileCopyrightText: 2013 John Layt <[email protected]>
5  SPDX-FileCopyrightText: 2010 Michael Leupold <[email protected]>
6  SPDX-FileCopyrightText: 2009 Michael Pyne <[email protected]>
7  SPDX-FileCopyrightText: 2008 Albert Astals Cid <[email protected]>
8 
9  SPDX-License-Identifier: LGPL-2.0-or-later
10 */
11 
12 #include "kformatprivate_p.h"
13 
14 KFormat::KFormat(const QLocale &locale)
15  : d(new KFormatPrivate(locale))
16 {
17 }
18 
20  : d(other.d)
21 {
22 }
23 
24 KFormat& KFormat::operator=(const KFormat &other)
25 {
26  d = other.d;
27  return *this;
28 }
29 
31 {
32 }
33 
35  int precision,
37  KFormat::BinarySizeUnits units) const
38 {
39  return d->formatByteSize(size, precision, dialect, units);
40 }
41 
43  KFormat::Unit unit,
44  int precision,
45  KFormat::UnitPrefix prefix,
46  KFormat::BinaryUnitDialect dialect) const
47 {
48  return d->formatValue(value, unit, QString(), precision, prefix, dialect);
49 }
50 
52  const QString& unit,
53  int precision,
54  KFormat::UnitPrefix prefix) const
55 {
56  return d->formatValue(value, KFormat::Unit::Other, unit, precision, prefix, MetricBinaryDialect);
57 }
58 
59 // TODO KF6 Merge both methods
61  const QString& unit,
62  int precision,
63  KFormat::UnitPrefix prefix,
64  KFormat::BinaryUnitDialect dialect) const
65 {
66  return d->formatValue(value, KFormat::Unit::Other, unit, precision, prefix, dialect);
67 }
68 
70  KFormat::DurationFormatOptions options) const
71 {
72  return d->formatDuration(msecs, options);
73 }
74 
76  int decimalPlaces) const
77 {
78  return d->formatDecimalDuration(msecs, decimalPlaces);
79 }
80 
82 {
83  return d->formatSpelloutDuration(msecs);
84 }
85 
87  QLocale::FormatType format) const
88 {
89  return d->formatRelativeDate(date, format);
90 }
91 
93  QLocale::FormatType format) const
94 {
95  return d->formatRelativeDateTime(dateTime, format);
96 }
97 
98 #include "moc_kformat.cpp"
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
~KFormat()
Destructor.
Definition: kformat.cpp:30
QString formatDecimalDuration(quint64 msecs, int decimalPlaces=2) const
Given a number of milliseconds, converts that to a string containing the localized equivalent to the ...
Definition: kformat.cpp:75
QString formatSpelloutDuration(quint64 msecs) const
Given a number of milliseconds, converts that to a spell-out string containing the localized equivale...
Definition: kformat.cpp:81
QString formatByteSize(double size, int precision=1, KFormat::BinaryUnitDialect dialect=KFormat::DefaultBinaryDialect, KFormat::BinarySizeUnits units=KFormat::DefaultBinaryUnits) const
Converts size from bytes to the appropriate string representation using the binary unit dialect diale...
Definition: kformat.cpp:34
Unit
These units are used in KDE by the formatValue() function.
Definition: kformat.h:107
QString formatRelativeDateTime(const QDateTime &dateTime, QLocale::FormatType format) const
Returns a string formatted to a relative datetime style.
Definition: kformat.cpp:92
BinaryUnitDialect
This enum chooses what dialect is used for binary units.
Definition: kformat.h:171
KFormat(const QLocale &locale=QLocale())
Constructs a KFormat.
Definition: kformat.cpp:14
QString formatRelativeDate(const QDate &date, QLocale::FormatType format) const
Returns a string formatted to a relative date style.
Definition: kformat.cpp:86
QString formatValue(double value, KFormat::Unit unit, int precision=1, KFormat::UnitPrefix prefix=KFormat::UnitPrefix::AutoAdjust, KFormat::BinaryUnitDialect dialect=KFormat::DefaultBinaryDialect) const
Converts value to the appropriate string representation.
Definition: kformat.cpp:42
KFormat provides support for formatting numbers and datetimes in formats that are not supported by QL...
Definition: kformat.h:58
QString formatDuration(quint64 msecs, KFormat::DurationFormatOptions options=KFormat::DefaultDuration) const
Given a number of milliseconds, converts that to a string containing the localized equivalent...
Definition: kformat.cpp:69
SI Units, kB, MB, etc. 10^(3*n)
Definition: kformat.h:175
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jan 27 2021 23:01:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.