mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 10:52:49 +00:00
kdecore: add additional constructor and validation method to conversion classes
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
f84251afc8
commit
abfb3e5eff
2 changed files with 123 additions and 0 deletions
|
@ -29,6 +29,7 @@ double KUnitConversion::round(const double number, const uint digits)
|
||||||
|
|
||||||
class KTemperaturePrivate {
|
class KTemperaturePrivate {
|
||||||
public:
|
public:
|
||||||
|
KTemperaturePrivate(const double number, const KTemperature::KTempUnit unit);
|
||||||
KTemperaturePrivate(const double number, const QString &unit);
|
KTemperaturePrivate(const double number, const QString &unit);
|
||||||
|
|
||||||
double m_number;
|
double m_number;
|
||||||
|
@ -36,6 +37,21 @@ public:
|
||||||
KTemperature::KTempUnit m_unitenum;
|
KTemperature::KTempUnit m_unitenum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
KTemperaturePrivate::KTemperaturePrivate(const double number, const KTemperature::KTempUnit unit)
|
||||||
|
: m_number(number),
|
||||||
|
m_unitenum(unit)
|
||||||
|
{
|
||||||
|
if (unit == KTemperature::Celsius) {
|
||||||
|
m_unit = QString::fromUtf8("°C");
|
||||||
|
} else if (unit == KTemperature::Fahrenheit) {
|
||||||
|
m_unit = QString::fromUtf8("°F");
|
||||||
|
} else if (unit == KTemperature::Kelvin) {
|
||||||
|
m_unit = QString::fromUtf8("K");
|
||||||
|
} else {
|
||||||
|
m_unit = QLatin1String("Unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KTemperaturePrivate::KTemperaturePrivate(const double number, const QString &unit)
|
KTemperaturePrivate::KTemperaturePrivate(const double number, const QString &unit)
|
||||||
: m_number(number),
|
: m_number(number),
|
||||||
m_unitenum(KTemperature::Invalid)
|
m_unitenum(KTemperature::Invalid)
|
||||||
|
@ -60,6 +76,11 @@ KTemperaturePrivate::KTemperaturePrivate(const double number, const QString &uni
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KTemperature::KTemperature(const double number, const KTempUnit unit)
|
||||||
|
: d(new KTemperaturePrivate(number, unit))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
KTemperature::KTemperature(const double number, const QString &unit)
|
KTemperature::KTemperature(const double number, const QString &unit)
|
||||||
: d(new KTemperaturePrivate(number, unit))
|
: d(new KTemperaturePrivate(number, unit))
|
||||||
{
|
{
|
||||||
|
@ -70,6 +91,11 @@ KTemperature::~KTemperature()
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KTemperature::isValid() const
|
||||||
|
{
|
||||||
|
return (d->m_unitenum != KTemperature::Invalid);
|
||||||
|
}
|
||||||
|
|
||||||
double KTemperature::number() const
|
double KTemperature::number() const
|
||||||
{
|
{
|
||||||
return d->m_number;
|
return d->m_number;
|
||||||
|
@ -117,6 +143,7 @@ double KTemperature::convertTo(const KTempUnit unit) const
|
||||||
|
|
||||||
class KVelocityPrivate {
|
class KVelocityPrivate {
|
||||||
public:
|
public:
|
||||||
|
KVelocityPrivate(const double number, const KVelocity::KVeloUnit unit);
|
||||||
KVelocityPrivate(const double number, const QString &unit);
|
KVelocityPrivate(const double number, const QString &unit);
|
||||||
|
|
||||||
double m_number;
|
double m_number;
|
||||||
|
@ -124,6 +151,23 @@ public:
|
||||||
KVelocity::KVeloUnit m_unitenum;
|
KVelocity::KVeloUnit m_unitenum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
KVelocityPrivate::KVelocityPrivate(const double number, const KVelocity::KVeloUnit unit)
|
||||||
|
: m_number(number),
|
||||||
|
m_unitenum(unit)
|
||||||
|
{
|
||||||
|
if (unit == KVelocity::MeterPerSecond) {
|
||||||
|
m_unit = QLatin1String("m/s");
|
||||||
|
} else if (unit == KVelocity::KilometerPerHour) {
|
||||||
|
m_unit = QLatin1String("km/h");
|
||||||
|
} else if (unit == KVelocity::MilePerHour) {
|
||||||
|
m_unit = QLatin1String("mph");
|
||||||
|
} else if (unit == KVelocity::Knot) {
|
||||||
|
m_unit = QLatin1String("kt");
|
||||||
|
} else {
|
||||||
|
m_unit = QLatin1String("Unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KVelocityPrivate::KVelocityPrivate(const double number, const QString &unit)
|
KVelocityPrivate::KVelocityPrivate(const double number, const QString &unit)
|
||||||
: m_number(number),
|
: m_number(number),
|
||||||
m_unitenum(KVelocity::Invalid)
|
m_unitenum(KVelocity::Invalid)
|
||||||
|
@ -154,6 +198,11 @@ KVelocityPrivate::KVelocityPrivate(const double number, const QString &unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KVelocity::KVelocity(const double number, const KVeloUnit unit)
|
||||||
|
: d(new KVelocityPrivate(number, unit))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
KVelocity::KVelocity(const double number, const QString &unit)
|
KVelocity::KVelocity(const double number, const QString &unit)
|
||||||
: d(new KVelocityPrivate(number, unit))
|
: d(new KVelocityPrivate(number, unit))
|
||||||
{
|
{
|
||||||
|
@ -164,6 +213,11 @@ KVelocity::~KVelocity()
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KVelocity::isValid() const
|
||||||
|
{
|
||||||
|
return (d->m_unitenum != KVelocity::Invalid);
|
||||||
|
}
|
||||||
|
|
||||||
double KVelocity::number() const
|
double KVelocity::number() const
|
||||||
{
|
{
|
||||||
return d->m_number;
|
return d->m_number;
|
||||||
|
@ -229,6 +283,7 @@ double KVelocity::convertTo(const KVeloUnit unit) const
|
||||||
|
|
||||||
class KPressurePrivate {
|
class KPressurePrivate {
|
||||||
public:
|
public:
|
||||||
|
KPressurePrivate(const double number, const KPressure::KPresUnit unit);
|
||||||
KPressurePrivate(const double number, const QString &unit);
|
KPressurePrivate(const double number, const QString &unit);
|
||||||
|
|
||||||
double m_number;
|
double m_number;
|
||||||
|
@ -236,6 +291,23 @@ public:
|
||||||
KPressure::KPresUnit m_unitenum;
|
KPressure::KPresUnit m_unitenum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
KPressurePrivate::KPressurePrivate(const double number, const KPressure::KPresUnit unit)
|
||||||
|
: m_number(number),
|
||||||
|
m_unitenum(unit)
|
||||||
|
{
|
||||||
|
if (unit == KPressure::Kilopascal) {
|
||||||
|
m_unit = QLatin1String("kPa");
|
||||||
|
} else if (unit == KPressure::Hectopascal) {
|
||||||
|
m_unit = QLatin1String("hPa");
|
||||||
|
} else if (unit == KPressure::Millibar) {
|
||||||
|
m_unit = QLatin1String("mbar");
|
||||||
|
} else if (unit == KPressure::InchesOfMercury) {
|
||||||
|
m_unit = QLatin1String("inHg");
|
||||||
|
} else {
|
||||||
|
m_unit = QLatin1String("Unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KPressurePrivate::KPressurePrivate(const double number, const QString &unit)
|
KPressurePrivate::KPressurePrivate(const double number, const QString &unit)
|
||||||
: m_number(number),
|
: m_number(number),
|
||||||
m_unitenum(KPressure::Invalid)
|
m_unitenum(KPressure::Invalid)
|
||||||
|
@ -266,6 +338,11 @@ KPressurePrivate::KPressurePrivate(const double number, const QString &unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KPressure::KPressure(const double number, const KPresUnit unit)
|
||||||
|
: d(new KPressurePrivate(number, unit))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
KPressure::KPressure(const double number, const QString &unit)
|
KPressure::KPressure(const double number, const QString &unit)
|
||||||
: d(new KPressurePrivate(number, unit))
|
: d(new KPressurePrivate(number, unit))
|
||||||
{
|
{
|
||||||
|
@ -276,6 +353,11 @@ KPressure::~KPressure()
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KPressure::isValid() const
|
||||||
|
{
|
||||||
|
return (d->m_unitenum != KPressure::Invalid);
|
||||||
|
}
|
||||||
|
|
||||||
double KPressure::number() const
|
double KPressure::number() const
|
||||||
{
|
{
|
||||||
return d->m_number;
|
return d->m_number;
|
||||||
|
@ -326,8 +408,10 @@ double KPressure::convertTo(const KPresUnit unit) const
|
||||||
return d->m_number;
|
return d->m_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class KLengthPrivate {
|
class KLengthPrivate {
|
||||||
public:
|
public:
|
||||||
|
KLengthPrivate(const double number, const KLength::KLengUnit unit);
|
||||||
KLengthPrivate(const double number, const QString &unit);
|
KLengthPrivate(const double number, const QString &unit);
|
||||||
|
|
||||||
double m_number;
|
double m_number;
|
||||||
|
@ -335,6 +419,19 @@ public:
|
||||||
KLength::KLengUnit m_unitenum;
|
KLength::KLengUnit m_unitenum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
KLengthPrivate::KLengthPrivate(const double number, const KLength::KLengUnit unit)
|
||||||
|
: m_number(number),
|
||||||
|
m_unitenum(unit)
|
||||||
|
{
|
||||||
|
if (unit == KLength::Mile) {
|
||||||
|
m_unit = QLatin1String("mi");
|
||||||
|
} else if (unit == KLength::Kilometer) {
|
||||||
|
m_unit = QLatin1String("km");
|
||||||
|
} else {
|
||||||
|
m_unit = QLatin1String("Unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KLengthPrivate::KLengthPrivate(const double number, const QString &unit)
|
KLengthPrivate::KLengthPrivate(const double number, const QString &unit)
|
||||||
: m_number(number),
|
: m_number(number),
|
||||||
m_unitenum(KLength::Invalid)
|
m_unitenum(KLength::Invalid)
|
||||||
|
@ -360,11 +457,21 @@ KLength::KLength(const double number, const QString &unit)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KLength::KLength(const double number, const KLengUnit unit)
|
||||||
|
: d(new KLengthPrivate(number, unit))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
KLength::~KLength()
|
KLength::~KLength()
|
||||||
{
|
{
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KLength::isValid() const
|
||||||
|
{
|
||||||
|
return (d->m_unitenum != KLength::Invalid);
|
||||||
|
}
|
||||||
|
|
||||||
double KLength::number() const
|
double KLength::number() const
|
||||||
{
|
{
|
||||||
return d->m_number;
|
return d->m_number;
|
||||||
|
|
|
@ -51,6 +51,12 @@ public:
|
||||||
Kelvin
|
Kelvin
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief Constructs convertor
|
||||||
|
@param number value of the unit
|
||||||
|
@param unit unit enum, one of: Invalid, Celsius, Fahrenheit or Kelvin
|
||||||
|
*/
|
||||||
|
KTemperature(const double number, const KTempUnit unit);
|
||||||
/*!
|
/*!
|
||||||
@brief Constructs convertor
|
@brief Constructs convertor
|
||||||
@param number value of the unit
|
@param number value of the unit
|
||||||
|
@ -59,6 +65,10 @@ public:
|
||||||
KTemperature(const double number, const QString &unit);
|
KTemperature(const double number, const QString &unit);
|
||||||
~KTemperature();
|
~KTemperature();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@return Whether or not the unit passed to the constructor is valid
|
||||||
|
*/
|
||||||
|
bool isValid() const;
|
||||||
/*!
|
/*!
|
||||||
@return Same number as the value passed to the constructor
|
@return Same number as the value passed to the constructor
|
||||||
*/
|
*/
|
||||||
|
@ -95,9 +105,11 @@ public:
|
||||||
Knot
|
Knot
|
||||||
};
|
};
|
||||||
|
|
||||||
|
KVelocity(const double number, const KVeloUnit unit);
|
||||||
KVelocity(const double number, const QString &unit);
|
KVelocity(const double number, const QString &unit);
|
||||||
~KVelocity();
|
~KVelocity();
|
||||||
|
|
||||||
|
bool isValid() const;
|
||||||
double number() const;
|
double number() const;
|
||||||
QString unit() const;
|
QString unit() const;
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
@ -122,9 +134,11 @@ public:
|
||||||
InchesOfMercury
|
InchesOfMercury
|
||||||
};
|
};
|
||||||
|
|
||||||
|
KPressure(const double number, const KPresUnit unit);
|
||||||
KPressure(const double number, const QString &unit);
|
KPressure(const double number, const QString &unit);
|
||||||
~KPressure();
|
~KPressure();
|
||||||
|
|
||||||
|
bool isValid() const;
|
||||||
double number() const;
|
double number() const;
|
||||||
QString unit() const;
|
QString unit() const;
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
@ -147,9 +161,11 @@ public:
|
||||||
Kilometer
|
Kilometer
|
||||||
};
|
};
|
||||||
|
|
||||||
|
KLength(const double number, const KLengUnit unit);
|
||||||
KLength(const double number, const QString &unit);
|
KLength(const double number, const QString &unit);
|
||||||
~KLength();
|
~KLength();
|
||||||
|
|
||||||
|
bool isValid() const;
|
||||||
double number() const;
|
double number() const;
|
||||||
QString unit() const;
|
QString unit() const;
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue