14namespace KUnitConversion
24 ValuePrivate(qreal number, UnitId unitId = InvalidUnit)
27 m_unit = m_converter.
unit(unitId);
30 ValuePrivate(qreal number,
const Unit &unit)
36 ValuePrivate(qreal number,
const QString &unitString)
39 m_unit = m_converter.
unit(unitString);
42 ValuePrivate(
const ValuePrivate &other)
44 , m_number(other.m_number)
45 , m_unit(other.m_unit)
49 virtual ~ValuePrivate()
53 ValuePrivate &operator=(
const ValuePrivate &other)
55 m_number = other.m_number;
56 m_unit = other.m_unit;
62 return new ValuePrivate(*
this);
65 bool operator==(
const ValuePrivate &other)
const
67 return (m_number == other.m_number && m_unit == other.m_unit);
70 bool operator!=(
const ValuePrivate &other)
const
72 return !(*
this == other);
77 Converter m_converter;
91 : d(new ValuePrivate(number, unit))
96 : d(new ValuePrivate(number, unitString))
101 : d(new ValuePrivate(number, unitId))
106 : d(new ValuePrivate(number.toReal(), unitString))
123 return (*d == *other.d);
125 return (d == other.d);
132 return (*d != *other.d);
134 return (d != other.d);
145 return (d && d->m_unit.isValid() && !qIsNaN(d->m_number));
167 return d->m_unit.toString(d->m_number, fieldWidth, format, precision, fillChar);
175 return d->m_unit.toSymbolString(d->m_number, fieldWidth, format, precision, fillChar);
186 uint div = qPow(10, decimals);
187 qreal add = 0.5 / (qreal)div;
189 d->m_number = (int)((d->m_number + add) * div) / (qreal)div;
196 return d->m_converter.convert(*
this,
unit);
204 return d->m_converter.convert(*
this, unitId);
212 return d->m_converter.convert(*
this, unitString);
Unit unit(const QString &unitString) const
Find unit for string unit.
Class to define a unit of measurement.
Class to hold a value in a unit of measurement.
QString toSymbolString(int fieldWidth=0, char format='g', int precision=-1, const QChar &fillChar=QLatin1Char(' ')) const
Convert value to a string with symbol.
QString toString(int fieldWidth=0, char format='g', int precision=-1, const QChar &fillChar=QLatin1Char(' ')) const
Convert value to a string.
qreal number() const
Number part of the value.
bool isValid() const
Check if value is valid.
Value & operator=(const Value &other)
Assignment operator, assign other to this.
bool operator==(const Value &other) const
Unit unit() const
Unit part of the value.
Value convertTo(const Unit &unit) const
convert to another unit
Value()
Creates a null value.
Value & round(uint decimals)
rounds value to decimal count
~Value()
Destroys this Value instance.
bool operator!=(const Value &other) const
KIOCORE_EXPORT QString number(KIO::filesize_t size)