mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kdecore: sort conversion classes enums alphabetically
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
56e78a109e
commit
ee85422b2d
3 changed files with 140 additions and 140 deletions
|
@ -73,15 +73,6 @@ void KUnitConversionTest::testVelocity()
|
|||
KVelocity invalidvelo(12, "");
|
||||
QCOMPARE(invalidvelo.unitEnum(), KVelocity::Invalid);
|
||||
|
||||
KVelocity msvelo(12.3, "m/s");
|
||||
QCOMPARE(msvelo.unitEnum(), KVelocity::MeterPerSecond);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::MeterPerSecond), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::KilometerPerHour), 1), 44.3);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::MilePerHour), 1), 27.5);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::Knot), 1), 23.9);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::UnitCount), 1), 0.0);
|
||||
|
||||
KVelocity kmhvelo(12.3, "km/h");
|
||||
QCOMPARE(kmhvelo.unitEnum(), KVelocity::KilometerPerHour);
|
||||
QCOMPARE(KUnitConversion::round(kmhvelo.convertTo(KVelocity::Invalid), 1), 0.0);
|
||||
|
@ -91,15 +82,6 @@ void KUnitConversionTest::testVelocity()
|
|||
QCOMPARE(KUnitConversion::round(kmhvelo.convertTo(KVelocity::Knot), 1), 6.6);
|
||||
QCOMPARE(KUnitConversion::round(kmhvelo.convertTo(KVelocity::UnitCount), 1), 0.0);
|
||||
|
||||
KVelocity mphvelo(12.3, "mph");
|
||||
QCOMPARE(mphvelo.unitEnum(), KVelocity::MilePerHour);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::MeterPerSecond), 1), 5.5);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::KilometerPerHour), 1), 19.8);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::MilePerHour), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::Knot), 1), 10.7);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::UnitCount), 1), 0.0);
|
||||
|
||||
KVelocity ktvelo(12.3, "kt");
|
||||
QCOMPARE(ktvelo.unitEnum(), KVelocity::Knot);
|
||||
QCOMPARE(KUnitConversion::round(ktvelo.convertTo(KVelocity::Invalid), 1), 0.0);
|
||||
|
@ -108,6 +90,24 @@ void KUnitConversionTest::testVelocity()
|
|||
QCOMPARE(KUnitConversion::round(ktvelo.convertTo(KVelocity::MilePerHour), 1), 14.2);
|
||||
QCOMPARE(KUnitConversion::round(ktvelo.convertTo(KVelocity::Knot), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(ktvelo.convertTo(KVelocity::UnitCount), 1), 0.0);
|
||||
|
||||
KVelocity msvelo(12.3, "m/s");
|
||||
QCOMPARE(msvelo.unitEnum(), KVelocity::MeterPerSecond);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::MeterPerSecond), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::KilometerPerHour), 1), 44.3);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::MilePerHour), 1), 27.5);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::Knot), 1), 23.9);
|
||||
QCOMPARE(KUnitConversion::round(msvelo.convertTo(KVelocity::UnitCount), 1), 0.0);
|
||||
|
||||
KVelocity mphvelo(12.3, "mph");
|
||||
QCOMPARE(mphvelo.unitEnum(), KVelocity::MilePerHour);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::MeterPerSecond), 1), 5.5);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::KilometerPerHour), 1), 19.8);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::MilePerHour), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::Knot), 1), 10.7);
|
||||
QCOMPARE(KUnitConversion::round(mphvelo.convertTo(KVelocity::UnitCount), 1), 0.0);
|
||||
}
|
||||
|
||||
void KUnitConversionTest::testPressure()
|
||||
|
@ -115,15 +115,6 @@ void KUnitConversionTest::testPressure()
|
|||
KPressure invalidpres(12, "");
|
||||
QCOMPARE(invalidpres.unitEnum(), KPressure::Invalid);
|
||||
|
||||
KPressure kpapres(12.3, "kilopascal");
|
||||
QCOMPARE(kpapres.unitEnum(), KPressure::Kilopascal);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::Kilopascal), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::Hectopascal), 1), 123.0);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::Millibar), 1), 123.0);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::InchesOfMercury), 1), 3.6);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::UnitCount), 1), 0.0);
|
||||
|
||||
KPressure hpapres(12.3, "hectopascal");
|
||||
QCOMPARE(hpapres.unitEnum(), KPressure::Hectopascal);
|
||||
QCOMPARE(KUnitConversion::round(hpapres.convertTo(KPressure::Invalid), 1), 0.0);
|
||||
|
@ -133,15 +124,6 @@ void KUnitConversionTest::testPressure()
|
|||
QCOMPARE(KUnitConversion::round(hpapres.convertTo(KPressure::InchesOfMercury), 1), 0.4);
|
||||
QCOMPARE(KUnitConversion::round(hpapres.convertTo(KPressure::UnitCount), 1), 0.0);
|
||||
|
||||
KPressure mbarpres(12.3, "millibar");
|
||||
QCOMPARE(mbarpres.unitEnum(), KPressure::Millibar);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::Kilopascal), 1), 1.2);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::Hectopascal), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::Millibar), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::InchesOfMercury), 1), 0.4);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::UnitCount), 1), 0.0);
|
||||
|
||||
KPressure inhpres(12.3, "inch of mercury");
|
||||
QCOMPARE(inhpres.unitEnum(), KPressure::InchesOfMercury);
|
||||
QCOMPARE(KUnitConversion::round(inhpres.convertTo(KPressure::Invalid), 1), 0.0);
|
||||
|
@ -150,6 +132,24 @@ void KUnitConversionTest::testPressure()
|
|||
QCOMPARE(KUnitConversion::round(inhpres.convertTo(KPressure::Millibar), 1), 416.5);
|
||||
QCOMPARE(KUnitConversion::round(inhpres.convertTo(KPressure::InchesOfMercury), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(inhpres.convertTo(KPressure::UnitCount), 1), 0.0);
|
||||
|
||||
KPressure kpapres(12.3, "kilopascal");
|
||||
QCOMPARE(kpapres.unitEnum(), KPressure::Kilopascal);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::Kilopascal), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::Hectopascal), 1), 123.0);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::Millibar), 1), 123.0);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::InchesOfMercury), 1), 3.6);
|
||||
QCOMPARE(KUnitConversion::round(kpapres.convertTo(KPressure::UnitCount), 1), 0.0);
|
||||
|
||||
KPressure mbarpres(12.3, "millibar");
|
||||
QCOMPARE(mbarpres.unitEnum(), KPressure::Millibar);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::Kilopascal), 1), 1.2);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::Hectopascal), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::Millibar), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::InchesOfMercury), 1), 0.4);
|
||||
QCOMPARE(KUnitConversion::round(mbarpres.convertTo(KPressure::UnitCount), 1), 0.0);
|
||||
}
|
||||
|
||||
void KUnitConversionTest::testLength()
|
||||
|
@ -157,19 +157,19 @@ void KUnitConversionTest::testLength()
|
|||
KLength invalidleng(12, "");
|
||||
QCOMPARE(invalidleng.unitEnum(), KLength::Invalid);
|
||||
|
||||
KLength mileng(12.3, "mile");
|
||||
QCOMPARE(mileng.unitEnum(), KLength::Mile);
|
||||
QCOMPARE(KUnitConversion::round(mileng.convertTo(KLength::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(mileng.convertTo(KLength::Mile), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(mileng.convertTo(KLength::Kilometer), 1), 19.8);
|
||||
QCOMPARE(KUnitConversion::round(mileng.convertTo(KLength::UnitCount), 1), 0.0);
|
||||
|
||||
KLength kmleng(12.3, "kilometer");
|
||||
QCOMPARE(kmleng.unitEnum(), KLength::Kilometer);
|
||||
QCOMPARE(KUnitConversion::round(kmleng.convertTo(KLength::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(kmleng.convertTo(KLength::Mile), 1), 7.6);
|
||||
QCOMPARE(KUnitConversion::round(kmleng.convertTo(KLength::Kilometer), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(kmleng.convertTo(KLength::UnitCount), 1), 0.0);
|
||||
|
||||
KLength mileng(12.3, "mile");
|
||||
QCOMPARE(mileng.unitEnum(), KLength::Mile);
|
||||
QCOMPARE(KUnitConversion::round(mileng.convertTo(KLength::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(mileng.convertTo(KLength::Mile), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(mileng.convertTo(KLength::Kilometer), 1), 19.8);
|
||||
QCOMPARE(KUnitConversion::round(mileng.convertTo(KLength::UnitCount), 1), 0.0);
|
||||
}
|
||||
|
||||
#include "moc_kunitconversiontest.cpp"
|
||||
|
|
|
@ -179,22 +179,22 @@ KVelocityPrivate::KVelocityPrivate(const double number, const QString &unit)
|
|||
: m_number(number),
|
||||
m_unitenum(KVelocity::Invalid)
|
||||
{
|
||||
if (unit == QLatin1String("MeterPerSecond")
|
||||
|| unit == QLatin1String("meter per second") || unit == QLatin1String("meters per second")
|
||||
|| unit == QLatin1String("m/s") || unit == QLatin1String("ms")) {
|
||||
m_unitenum = KVelocity::MeterPerSecond;
|
||||
} else if (unit == QLatin1String("KilometerPerHour")
|
||||
if (unit == QLatin1String("KilometerPerHour")
|
||||
|| unit == QLatin1String("kilometer per hour") || unit == QLatin1String("kilometers per hour")
|
||||
|| unit == QLatin1String("km/h") || unit == QLatin1String("kmh")) {
|
||||
m_unitenum = KVelocity::KilometerPerHour;
|
||||
} else if (unit == QLatin1String("MilePerHour")
|
||||
|| unit == QLatin1String("mile per hour") || unit == QLatin1String("miles per hour")
|
||||
|| unit == QLatin1String("mph")) {
|
||||
m_unitenum = KVelocity::MilePerHour;
|
||||
} else if (unit == QLatin1String("Knot")
|
||||
|| unit == QLatin1String("knot") || unit == QLatin1String("knots")
|
||||
|| unit == QLatin1String("kt") || unit == QLatin1String("nautical miles per hour")) {
|
||||
m_unitenum = KVelocity::Knot;
|
||||
} else if (unit == QLatin1String("MeterPerSecond")
|
||||
|| unit == QLatin1String("meter per second") || unit == QLatin1String("meters per second")
|
||||
|| unit == QLatin1String("m/s") || unit == QLatin1String("ms")) {
|
||||
m_unitenum = KVelocity::MeterPerSecond;
|
||||
} else if (unit == QLatin1String("MilePerHour")
|
||||
|| unit == QLatin1String("mile per hour") || unit == QLatin1String("miles per hour")
|
||||
|| unit == QLatin1String("mph")) {
|
||||
m_unitenum = KVelocity::MilePerHour;
|
||||
} else {
|
||||
kDebug() << "invalid velocity unit" << unit;
|
||||
}
|
||||
|
@ -223,14 +223,14 @@ double KVelocity::number() const
|
|||
QString KVelocity::unit() const
|
||||
{
|
||||
switch (d->m_unitenum) {
|
||||
case KVelocity::MeterPerSecond:
|
||||
return QLatin1String("m/s");
|
||||
case KVelocity::KilometerPerHour:
|
||||
return QLatin1String("km/h");
|
||||
case KVelocity::MilePerHour:
|
||||
return QLatin1String("mph");
|
||||
case KVelocity::Knot:
|
||||
return QLatin1String("kt");
|
||||
case KVelocity::MeterPerSecond:
|
||||
return QLatin1String("m/s");
|
||||
case KVelocity::MilePerHour:
|
||||
return QLatin1String("mph");
|
||||
case KVelocity::Invalid:
|
||||
case KVelocity::UnitCount:
|
||||
break;
|
||||
|
@ -255,42 +255,42 @@ double KVelocity::convertTo(const KVeloUnit unit) const
|
|||
}
|
||||
|
||||
// for reference:
|
||||
// https://www.metric-conversions.org/speed/meters-per-second-to-kilometers-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/meters-per-second-to-miles-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/meters-per-second-to-knots.htm
|
||||
// https://www.metric-conversions.org/speed/kilometers-per-hour-to-knots.htm
|
||||
// https://www.metric-conversions.org/speed/kilometers-per-hour-to-meters-per-second.htm
|
||||
// https://www.metric-conversions.org/speed/kilometers-per-hour-to-miles-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/kilometers-per-hour-to-knots.htm
|
||||
// https://www.metric-conversions.org/speed/miles-per-hour-to-meters-per-second.htm
|
||||
// https://www.metric-conversions.org/speed/knots-to-kilometers-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/knots-to-meters-per-second.htm
|
||||
// https://www.metric-conversions.org/speed/knots-to-miles-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/meters-per-second-to-kilometers-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/meters-per-second-to-knots.htm
|
||||
// https://www.metric-conversions.org/speed/meters-per-second-to-miles-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/miles-per-hour-to-kilometers-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/miles-per-hour-to-knots.htm
|
||||
// https://www.metric-conversions.org/speed/knots-to-meters-per-second.htm
|
||||
// https://www.metric-conversions.org/speed/knots-to-kilometers-per-hour.htm
|
||||
// https://www.metric-conversions.org/speed/knots-to-miles-per-hour.htm
|
||||
if (d->m_unitenum == KVelocity::MeterPerSecond && unit == KVelocity::KilometerPerHour) {
|
||||
return (d->m_number * 3.6);
|
||||
} else if (d->m_unitenum == KVelocity::MeterPerSecond && unit == KVelocity::MilePerHour) {
|
||||
return (d->m_number * 2.236936);
|
||||
} else if (d->m_unitenum == KVelocity::MeterPerSecond && unit == KVelocity::Knot) {
|
||||
return (d->m_number * 1.943844);
|
||||
// https://www.metric-conversions.org/speed/miles-per-hour-to-meters-per-second.htm
|
||||
if (d->m_unitenum == KVelocity::KilometerPerHour && unit == KVelocity::Knot) {
|
||||
return d->m_number / 1.852;
|
||||
} else if (d->m_unitenum == KVelocity::KilometerPerHour && unit == KVelocity::MeterPerSecond) {
|
||||
return (d->m_number / 3.6);
|
||||
} else if (d->m_unitenum == KVelocity::KilometerPerHour && unit == KVelocity::MilePerHour) {
|
||||
return (d->m_number / 1.609344);
|
||||
} else if (d->m_unitenum == KVelocity::KilometerPerHour && unit == KVelocity::Knot) {
|
||||
return d->m_number / 1.852;
|
||||
} else if (d->m_unitenum == KVelocity::MilePerHour && unit == KVelocity::MeterPerSecond) {
|
||||
return (d->m_number / 2.236936);
|
||||
} else if (d->m_unitenum == KVelocity::Knot && unit == KVelocity::KilometerPerHour) {
|
||||
return (d->m_number * 1.852);
|
||||
} else if (d->m_unitenum == KVelocity::Knot && unit == KVelocity::MeterPerSecond) {
|
||||
return (d->m_number / 1.943844);
|
||||
} else if (d->m_unitenum == KVelocity::Knot && unit == KVelocity::MilePerHour) {
|
||||
return (d->m_number * 1.150779);
|
||||
} else if (d->m_unitenum == KVelocity::MeterPerSecond && unit == KVelocity::KilometerPerHour) {
|
||||
return (d->m_number * 3.6);
|
||||
} else if (d->m_unitenum == KVelocity::MeterPerSecond && unit == KVelocity::Knot) {
|
||||
return (d->m_number * 1.943844);
|
||||
} else if (d->m_unitenum == KVelocity::MeterPerSecond && unit == KVelocity::MilePerHour) {
|
||||
return (d->m_number * 2.236936);
|
||||
} else if (d->m_unitenum == KVelocity::MilePerHour && unit == KVelocity::KilometerPerHour) {
|
||||
return (d->m_number * 1.609344);
|
||||
} else if (d->m_unitenum == KVelocity::MilePerHour && unit == KVelocity::Knot) {
|
||||
return (d->m_number / 1.150779);
|
||||
} else if (d->m_unitenum == KVelocity::Knot && unit == KVelocity::MeterPerSecond) {
|
||||
return (d->m_number / 1.943844);
|
||||
} else if (d->m_unitenum == KVelocity::Knot && unit == KVelocity::KilometerPerHour) {
|
||||
return (d->m_number * 1.852);
|
||||
} else if (d->m_unitenum == KVelocity::Knot && unit == KVelocity::MilePerHour) {
|
||||
return (d->m_number * 1.150779);
|
||||
} else if (d->m_unitenum == KVelocity::MilePerHour && unit == KVelocity::MeterPerSecond) {
|
||||
return (d->m_number / 2.236936);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
@ -303,14 +303,14 @@ QString KVelocity::description()
|
|||
QString KVelocity::unitDescription(const KVeloUnit unit)
|
||||
{
|
||||
switch (unit) {
|
||||
case KVelocity::MeterPerSecond:
|
||||
return i18n("Meter per second (m/s)");
|
||||
case KVelocity::KilometerPerHour:
|
||||
return i18n("Kilometer per hour (km/h)");
|
||||
case KVelocity::MilePerHour:
|
||||
return i18n("Mile per hour (mph)");
|
||||
case KVelocity::Knot:
|
||||
return i18n("Knot (kt)");
|
||||
case KVelocity::MeterPerSecond:
|
||||
return i18n("Meter per second (m/s)");
|
||||
case KVelocity::MilePerHour:
|
||||
return i18n("Mile per hour (mph)");
|
||||
case KVelocity::Invalid:
|
||||
case KVelocity::UnitCount:
|
||||
break;
|
||||
|
@ -338,22 +338,22 @@ KPressurePrivate::KPressurePrivate(const double number, const QString &unit)
|
|||
: m_number(number),
|
||||
m_unitenum(KPressure::Invalid)
|
||||
{
|
||||
if (unit == QLatin1String("Kilopascal")
|
||||
|| unit == QLatin1String("kilopascal") || unit == QLatin1String("kilopascals")
|
||||
|| unit == QLatin1String("kPa")) {
|
||||
m_unitenum = KPressure::Kilopascal;
|
||||
} else if (unit == QLatin1String("Hectopascal")
|
||||
if (unit == QLatin1String("Hectopascal")
|
||||
|| unit == QLatin1String("hectopascal") || unit == QLatin1String("hectopascals")
|
||||
|| unit == QLatin1String("hPa")) {
|
||||
m_unitenum = KPressure::Hectopascal;
|
||||
} else if (unit == QLatin1String("Millibar")
|
||||
|| unit == QLatin1String("millibar") || unit == QLatin1String("millibars")
|
||||
|| unit == QLatin1String("mbar") || unit == QLatin1String("mb")) {
|
||||
m_unitenum = KPressure::Millibar;
|
||||
} else if (unit == QLatin1String("InchesOfMercury")
|
||||
|| unit == QLatin1String("inch of mercury") || unit == QLatin1String("inches of mercury")
|
||||
|| unit == QLatin1String("inHg")) {
|
||||
m_unitenum = KPressure::InchesOfMercury;
|
||||
} else if (unit == QLatin1String("Kilopascal")
|
||||
|| unit == QLatin1String("kilopascal") || unit == QLatin1String("kilopascals")
|
||||
|| unit == QLatin1String("kPa")) {
|
||||
m_unitenum = KPressure::Kilopascal;
|
||||
} else if (unit == QLatin1String("Millibar")
|
||||
|| unit == QLatin1String("millibar") || unit == QLatin1String("millibars")
|
||||
|| unit == QLatin1String("mbar") || unit == QLatin1String("mb")) {
|
||||
m_unitenum = KPressure::Millibar;
|
||||
} else {
|
||||
kDebug() << "invalid pressure unit" << unit;
|
||||
}
|
||||
|
@ -382,14 +382,14 @@ double KPressure::number() const
|
|||
QString KPressure::unit() const
|
||||
{
|
||||
switch (d->m_unitenum) {
|
||||
case KPressure::Kilopascal:
|
||||
return QLatin1String("kPa");
|
||||
case KPressure::Hectopascal:
|
||||
return QLatin1String("hPa");
|
||||
case KPressure::Millibar:
|
||||
return QLatin1String("mbar");
|
||||
case KPressure::InchesOfMercury:
|
||||
return QLatin1String("inHg");
|
||||
case KPressure::Kilopascal:
|
||||
return QLatin1String("kPa");
|
||||
case KPressure::Millibar:
|
||||
return QLatin1String("mbar");
|
||||
case KPressure::Invalid:
|
||||
case KPressure::UnitCount:
|
||||
break;
|
||||
|
@ -413,30 +413,30 @@ double KPressure::convertTo(const KPresUnit unit) const
|
|||
return d->m_number;
|
||||
}
|
||||
|
||||
if (d->m_unitenum == KPressure::Kilopascal && unit == KPressure::Hectopascal) {
|
||||
return (d->m_number * 10.0);
|
||||
} else if (d->m_unitenum == KPressure::Kilopascal && unit == KPressure::Millibar) {
|
||||
return (d->m_number * 10.0);
|
||||
} else if (d->m_unitenum == KPressure::Kilopascal && unit == KPressure::InchesOfMercury) {
|
||||
return (d->m_number / 3.386398);
|
||||
if (d->m_unitenum == KPressure::Hectopascal && unit == KPressure::InchesOfMercury) {
|
||||
return (d->m_number / 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::Hectopascal && unit == KPressure::Kilopascal) {
|
||||
return (d->m_number / 10.0);
|
||||
} else if (d->m_unitenum == KPressure::Hectopascal && unit == KPressure::Millibar) {
|
||||
return (d->m_number * 1.0);
|
||||
} else if (d->m_unitenum == KPressure::Hectopascal && unit == KPressure::InchesOfMercury) {
|
||||
return (d->m_number / 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::Millibar && unit == KPressure::Kilopascal) {
|
||||
return (d->m_number / 10.0);
|
||||
} else if (d->m_unitenum == KPressure::InchesOfMercury && unit == KPressure::Hectopascal) {
|
||||
return (d->m_number * 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::InchesOfMercury && unit == KPressure::Kilopascal) {
|
||||
return (d->m_number * 3.386398);
|
||||
} else if (d->m_unitenum == KPressure::InchesOfMercury && unit == KPressure::Millibar) {
|
||||
return (d->m_number * 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::Kilopascal && unit == KPressure::Hectopascal) {
|
||||
return (d->m_number * 10.0);
|
||||
} else if (d->m_unitenum == KPressure::Kilopascal && unit == KPressure::InchesOfMercury) {
|
||||
return (d->m_number / 3.386398);
|
||||
} else if (d->m_unitenum == KPressure::Kilopascal && unit == KPressure::Millibar) {
|
||||
return (d->m_number * 10.0);
|
||||
} else if (d->m_unitenum == KPressure::Millibar && unit == KPressure::Hectopascal) {
|
||||
return (d->m_number * 1.0);
|
||||
} else if (d->m_unitenum == KPressure::Millibar && unit == KPressure::InchesOfMercury) {
|
||||
return (d->m_number / 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::InchesOfMercury && unit == KPressure::Kilopascal) {
|
||||
return (d->m_number * 3.386398);
|
||||
} else if (d->m_unitenum == KPressure::InchesOfMercury && unit == KPressure::Hectopascal) {
|
||||
return (d->m_number * 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::InchesOfMercury && unit == KPressure::Millibar) {
|
||||
return (d->m_number * 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::Millibar && unit == KPressure::Kilopascal) {
|
||||
return (d->m_number / 10.0);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
@ -449,14 +449,14 @@ QString KPressure::description()
|
|||
QString KPressure::unitDescription(const KPresUnit unit)
|
||||
{
|
||||
switch (unit) {
|
||||
case KPressure::Kilopascal:
|
||||
return i18n("Kilopascal (kPa)");
|
||||
case KPressure::Hectopascal:
|
||||
return i18n("Hectopascal (hPa)");
|
||||
case KPressure::Millibar:
|
||||
return i18n("Millibar (mbar)");
|
||||
case KPressure::InchesOfMercury:
|
||||
return i18n("Inch of mercury (inHg)");
|
||||
case KPressure::Kilopascal:
|
||||
return i18n("Kilopascal (kPa)");
|
||||
case KPressure::Millibar:
|
||||
return i18n("Millibar (mbar)");
|
||||
case KPressure::Invalid:
|
||||
case KPressure::UnitCount:
|
||||
break;
|
||||
|
@ -484,14 +484,14 @@ KLengthPrivate::KLengthPrivate(const double number, const QString &unit)
|
|||
: m_number(number),
|
||||
m_unitenum(KLength::Invalid)
|
||||
{
|
||||
if (unit == QLatin1String("Mile")
|
||||
|| unit == QLatin1String("mile") || unit == QLatin1String("miles")
|
||||
|| unit == QLatin1String("mi")) {
|
||||
m_unitenum = KLength::Mile;
|
||||
} else if (unit == QLatin1String("Kilometer")
|
||||
if (unit == QLatin1String("Kilometer")
|
||||
|| unit == QLatin1String("kilometer") || unit == QLatin1String("kilometers")
|
||||
|| unit == QLatin1String("km")) {
|
||||
m_unitenum = KLength::Kilometer;
|
||||
} else if (unit == QLatin1String("Mile")
|
||||
|| unit == QLatin1String("mile") || unit == QLatin1String("miles")
|
||||
|| unit == QLatin1String("mi")) {
|
||||
m_unitenum = KLength::Mile;
|
||||
} else {
|
||||
kDebug() << "invalid length unit" << unit;
|
||||
}
|
||||
|
@ -520,10 +520,10 @@ double KLength::number() const
|
|||
QString KLength::unit() const
|
||||
{
|
||||
switch (d->m_unitenum) {
|
||||
case KLength::Mile:
|
||||
return QLatin1String("mi");
|
||||
case KLength::Kilometer:
|
||||
return QLatin1String("km");
|
||||
case KLength::Mile:
|
||||
return QLatin1String("mi");
|
||||
case KLength::Invalid:
|
||||
case KLength::UnitCount:
|
||||
break;
|
||||
|
@ -548,12 +548,12 @@ double KLength::convertTo(const KLengUnit unit) const
|
|||
}
|
||||
|
||||
// for reference:
|
||||
// https://www.rapidtables.com/convert/length/mile-to-km.html
|
||||
// https://www.rapidtables.com/convert/length/km-to-mile.html
|
||||
if (d->m_unitenum == KLength::Mile && unit == KLength::Kilometer) {
|
||||
return (d->m_number * 1.609344);
|
||||
} else if (d->m_unitenum == KLength::Kilometer && unit == KLength::Mile) {
|
||||
// https://www.rapidtables.com/convert/length/mile-to-km.html
|
||||
if (d->m_unitenum == KLength::Kilometer && unit == KLength::Mile) {
|
||||
return (d->m_number / 1.609344);
|
||||
} else if (d->m_unitenum == KLength::Mile && unit == KLength::Kilometer) {
|
||||
return (d->m_number * 1.609344);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
@ -566,10 +566,10 @@ QString KLength::description()
|
|||
QString KLength::unitDescription(const KLengUnit unit)
|
||||
{
|
||||
switch (unit) {
|
||||
case KLength::Mile:
|
||||
return i18n("Mile (mi)");
|
||||
case KLength::Kilometer:
|
||||
return i18n("Kilometer (km)");
|
||||
case KLength::Mile:
|
||||
return i18n("Mile (mi)");
|
||||
case KLength::Invalid:
|
||||
case KLength::UnitCount:
|
||||
break;
|
||||
|
|
|
@ -117,10 +117,10 @@ class KVelocity : public KUnitConversion {
|
|||
public:
|
||||
enum KVeloUnit {
|
||||
Invalid = -1,
|
||||
MeterPerSecond = 0,
|
||||
KilometerPerHour = 1,
|
||||
MilePerHour = 2,
|
||||
Knot = 3,
|
||||
KilometerPerHour = 0,
|
||||
Knot = 1,
|
||||
MeterPerSecond = 2,
|
||||
MilePerHour = 3,
|
||||
UnitCount = 4
|
||||
};
|
||||
|
||||
|
@ -150,10 +150,10 @@ class KPressure : public KUnitConversion {
|
|||
public:
|
||||
enum KPresUnit {
|
||||
Invalid = -1,
|
||||
Kilopascal = 0,
|
||||
Hectopascal = 1,
|
||||
Millibar = 2,
|
||||
InchesOfMercury = 3,
|
||||
Hectopascal = 0,
|
||||
InchesOfMercury = 1,
|
||||
Kilopascal = 2,
|
||||
Millibar = 3,
|
||||
UnitCount = 4
|
||||
};
|
||||
|
||||
|
@ -183,8 +183,8 @@ class KLength : public KUnitConversion {
|
|||
public:
|
||||
enum KLengUnit {
|
||||
Invalid = -1,
|
||||
Mile = 0,
|
||||
Kilometer = 1,
|
||||
Kilometer = 0,
|
||||
Mile = 1,
|
||||
UnitCount = 2
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue