10#include "unitcategory.h"
12#include <KLocalizedString>
14namespace KUnitConversion
16UnitPrivate::UnitPrivate()
17 : m_categoryId(InvalidCategory)
23UnitPrivate::UnitPrivate(CategoryId categoryId,
32 : m_categoryId(categoryId)
34 , m_multiplier(multiplier)
36 , m_description(description)
37 , m_matchString(matchString)
38 , m_symbolString(symbolString)
39 , m_realString(realString)
40 , m_integerString(integerString)
44UnitPrivate::~UnitPrivate()
48UnitPrivate *UnitPrivate::clone()
50 return new UnitPrivate(*
this);
53bool UnitPrivate::operator==(
const UnitPrivate &other)
const
55 return (m_id == other.m_id && m_symbol == other.m_symbol);
58bool UnitPrivate::operator!=(
const UnitPrivate &other)
const
60 return !(*
this == other);
63void UnitPrivate::setUnitMultiplier(qreal multiplier)
65 m_multiplier = multiplier;
68qreal UnitPrivate::unitMultiplier()
const
73qreal UnitPrivate::toDefault(qreal value)
const
75 return value * m_multiplier;
78qreal UnitPrivate::fromDefault(qreal value)
const
80 return value / m_multiplier;
117 return (*d == *other.d);
119 return (d == other.d);
126 return (*d != *other.d);
128 return (d != other.d);
139 return (d && !d->m_symbol.isEmpty());
153 return d->m_categoryId;
155 return InvalidCategory;
169 return d->m_description;
182void Unit::setUnitMultiplier(qreal multiplier)
185 d->setUnitMultiplier(multiplier);
189qreal Unit::toDefault(qreal value)
const
192 return d->toDefault(value);
197qreal Unit::fromDefault(qreal value)
const
200 return d->fromDefault(value);
210 if ((
int)value == value && precision < 1) {
211 return d->m_integerString.subs((
int)value).toString();
213 return d->m_realString.subs(value, fieldWidth, format, precision, fillChar).toString();
219 return d->m_symbolString.subs(value, fieldWidth, format, precision, fillChar).subs(d->m_symbol).toString();
Class to define a category of units of measurement.
Class to define a unit of measurement.
bool operator==(const Unit &other) const
QString toString(qreal value, int fieldWidth=0, char format='g', int precision=-1, const QChar &fillChar=QLatin1Char(' ')) const
QString toSymbolString(qreal value, int fieldWidth=0, char format='g', int precision=-1, const QChar &fillChar=QLatin1Char(' ')) const
Unit & operator=(const Unit &other)
Assignment operator, assign other to this.
UnitCategory category() const
QString description() const
CategoryId categoryId() const
bool operator!=(const Unit &other) const
void swap(QExplicitlySharedDataPointer< T > &other)