mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 10:52:49 +00:00
Merge branch 'master' of https://github.com/fluxer/kdelibs into devinfo
This commit is contained in:
commit
57a8bb1e1f
4 changed files with 281 additions and 82 deletions
|
@ -62,6 +62,7 @@ KDECORE_UNIT_TESTS(
|
|||
qcoreapptest
|
||||
kdebug_qcoreapptest
|
||||
kmimetype_nomimetypes
|
||||
kunitconversiontest
|
||||
)
|
||||
|
||||
KDECORE_EXECUTABLE_TESTS(
|
||||
|
|
175
kdecore/tests/kunitconversiontest.cpp
Normal file
175
kdecore/tests/kunitconversiontest.cpp
Normal file
|
@ -0,0 +1,175 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kunitconversiontest.h"
|
||||
#include "kunitconversion.h"
|
||||
#include "qtest_kde.h"
|
||||
|
||||
QTEST_KDEMAIN_CORE(KUnitConversionTest)
|
||||
|
||||
void KUnitConversionTest::initTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void KUnitConversionTest::testRound()
|
||||
{
|
||||
static const double toround = 1.23456789;
|
||||
QCOMPARE(KUnitConversion::round(toround, 1), 1.2);
|
||||
QCOMPARE(KUnitConversion::round(toround, 2), 1.23);
|
||||
QCOMPARE(KUnitConversion::round(toround, 3), 1.235);
|
||||
}
|
||||
|
||||
void KUnitConversionTest::testTemperature()
|
||||
{
|
||||
KTemperature invalidtemp(12, "");
|
||||
QCOMPARE(invalidtemp.unitEnum(), KTemperature::Invalid);
|
||||
|
||||
KTemperature tostringtemp(123.4, "°F");
|
||||
QCOMPARE(tostringtemp.toString(), QString::fromUtf8("123.4 °F"));
|
||||
|
||||
KTemperature ctemp(12.3, "°C");
|
||||
QCOMPARE(ctemp.unitEnum(), KTemperature::Celsius);
|
||||
QCOMPARE(KUnitConversion::round(ctemp.convertTo(KTemperature::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(ctemp.convertTo(KTemperature::Fahrenheit), 1), 54.1);
|
||||
QCOMPARE(KUnitConversion::round(ctemp.convertTo(KTemperature::Celsius), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(ctemp.convertTo(KTemperature::Kelvin), 1), 285.5);
|
||||
QCOMPARE(KUnitConversion::round(ctemp.convertTo(KTemperature::UnitCount), 1), 0.0);
|
||||
|
||||
KTemperature ftemp(123.4, "°F");
|
||||
QCOMPARE(ftemp.unitEnum(), KTemperature::Fahrenheit);
|
||||
QCOMPARE(KUnitConversion::round(ftemp.convertTo(KTemperature::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(ftemp.convertTo(KTemperature::Fahrenheit), 1), 123.4);
|
||||
QCOMPARE(KUnitConversion::round(ftemp.convertTo(KTemperature::Celsius), 1), 50.8);
|
||||
QCOMPARE(KUnitConversion::round(ftemp.convertTo(KTemperature::Kelvin), 1), 323.9);
|
||||
QCOMPARE(KUnitConversion::round(ftemp.convertTo(KTemperature::UnitCount), 1), 0.0);
|
||||
|
||||
KTemperature ktemp(1234.5, "K");
|
||||
QCOMPARE(ktemp.unitEnum(), KTemperature::Kelvin);
|
||||
QCOMPARE(KUnitConversion::round(ktemp.convertTo(KTemperature::Invalid), 1), 0.0);
|
||||
QCOMPARE(KUnitConversion::round(ktemp.convertTo(KTemperature::Fahrenheit), 1), 1762.4);
|
||||
QCOMPARE(KUnitConversion::round(ktemp.convertTo(KTemperature::Celsius), 1), 961.4);
|
||||
QCOMPARE(KUnitConversion::round(ktemp.convertTo(KTemperature::Kelvin), 1), 1234.5);
|
||||
QCOMPARE(KUnitConversion::round(ktemp.convertTo(KTemperature::UnitCount), 1), 0.0);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
QCOMPARE(KUnitConversion::round(kmhvelo.convertTo(KVelocity::MeterPerSecond), 1), 3.4);
|
||||
QCOMPARE(KUnitConversion::round(kmhvelo.convertTo(KVelocity::KilometerPerHour), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(kmhvelo.convertTo(KVelocity::MilePerHour), 1), 7.6);
|
||||
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);
|
||||
QCOMPARE(KUnitConversion::round(ktvelo.convertTo(KVelocity::MeterPerSecond), 1), 6.3);
|
||||
QCOMPARE(KUnitConversion::round(ktvelo.convertTo(KVelocity::KilometerPerHour), 1), 22.8);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
QCOMPARE(KUnitConversion::round(hpapres.convertTo(KPressure::Kilopascal), 1), 1.2);
|
||||
QCOMPARE(KUnitConversion::round(hpapres.convertTo(KPressure::Hectopascal), 1), 12.3);
|
||||
QCOMPARE(KUnitConversion::round(hpapres.convertTo(KPressure::Millibar), 1), 12.3);
|
||||
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);
|
||||
QCOMPARE(KUnitConversion::round(inhpres.convertTo(KPressure::Kilopascal), 1), 41.7);
|
||||
QCOMPARE(KUnitConversion::round(inhpres.convertTo(KPressure::Hectopascal), 1), 416.5);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#include "moc_kunitconversiontest.cpp"
|
37
kdecore/tests/kunitconversiontest.h
Normal file
37
kdecore/tests/kunitconversiontest.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KUNITCONVERSIONTEST_H
|
||||
#define KUNITCONVERSIONTEST_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class KUnitConversionTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
void testRound();
|
||||
void testTemperature();
|
||||
void testVelocity();
|
||||
void testPressure();
|
||||
void testLength();
|
||||
};
|
||||
|
||||
#endif // KUNITCONVERSIONTEST_H
|
|
@ -33,8 +33,7 @@ public:
|
|||
KTemperaturePrivate(const double number, const KTemperature::KTempUnit unit);
|
||||
KTemperaturePrivate(const double number, const QString &unit);
|
||||
|
||||
double m_number;
|
||||
QString m_unit;
|
||||
const double m_number;
|
||||
KTemperature::KTempUnit m_unitenum;
|
||||
};
|
||||
|
||||
|
@ -42,15 +41,6 @@ KTemperaturePrivate::KTemperaturePrivate(const double number, const KTemperature
|
|||
: 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)
|
||||
|
@ -61,19 +51,15 @@ KTemperaturePrivate::KTemperaturePrivate(const double number, const QString &uni
|
|||
if (unit == QLatin1String("Celsius")
|
||||
|| unit == QString::fromUtf8("°C") || unit == QLatin1String("C")) {
|
||||
m_unitenum = KTemperature::Celsius;
|
||||
m_unit = QString::fromUtf8("°C");
|
||||
} else if (unit == QLatin1String("Fahrenheit")
|
||||
|| unit == QString::fromUtf8("°F") || unit == QLatin1String("F")) {
|
||||
m_unitenum = KTemperature::Fahrenheit;
|
||||
m_unit = QString::fromUtf8("°F");
|
||||
} else if (unit == QLatin1String("Kelvin")
|
||||
|| unit == QLatin1String("K") || unit == QLatin1String("kelvin")
|
||||
|| unit == QLatin1String("kelvins")) {
|
||||
m_unitenum = KTemperature::Kelvin;
|
||||
m_unit = QLatin1String("K");
|
||||
} else {
|
||||
kDebug() << "invalid temperature unit" << unit;
|
||||
m_unit = QLatin1String("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +85,18 @@ double KTemperature::number() const
|
|||
|
||||
QString KTemperature::unit() const
|
||||
{
|
||||
return d->m_unit;
|
||||
switch (d->m_unitenum) {
|
||||
case KTemperature::Celsius:
|
||||
return QString::fromUtf8("°C");
|
||||
case KTemperature::Fahrenheit:
|
||||
return QString::fromUtf8("°F");
|
||||
case KTemperature::Kelvin:
|
||||
return QLatin1String("K");
|
||||
case KTemperature::Invalid:
|
||||
case KTemperature::UnitCount:
|
||||
break;
|
||||
}
|
||||
return QLatin1String("Unknown");
|
||||
}
|
||||
|
||||
KTemperature::KTempUnit KTemperature::unitEnum() const
|
||||
|
@ -109,7 +106,7 @@ KTemperature::KTempUnit KTemperature::unitEnum() const
|
|||
|
||||
QString KTemperature::toString() const
|
||||
{
|
||||
return QString::fromLatin1("%1 %2").arg(QString::number(d->m_number), d->m_unit);
|
||||
return QString::fromLatin1("%1 %2").arg(QString::number(d->m_number), KTemperature::unit());
|
||||
}
|
||||
|
||||
double KTemperature::convertTo(const KTempUnit unit) const
|
||||
|
@ -126,17 +123,17 @@ double KTemperature::convertTo(const KTempUnit unit) const
|
|||
// https://www.rapidtables.com/convert/temperature/kelvin-to-celsius.html
|
||||
// https://www.rapidtables.com/convert/temperature/kelvin-to-fahrenheit.html
|
||||
if (d->m_unitenum == KTemperature::Celsius && unit == KTemperature::Fahrenheit) {
|
||||
return (d->m_number * 1.8 + 32);
|
||||
return ((d->m_number * 1.8) + 32);
|
||||
} else if (d->m_unitenum == KTemperature::Celsius && unit == KTemperature::Kelvin) {
|
||||
return (d->m_number + 273.15);
|
||||
} else if (d->m_unitenum == KTemperature::Fahrenheit && unit == KTemperature::Celsius) {
|
||||
return ((d->m_number - 32) / 1.8);
|
||||
} else if (d->m_unitenum == KTemperature::Fahrenheit && unit == KTemperature::Kelvin) {
|
||||
return ((d->m_number + 459.67) * 0.5);
|
||||
return (((d->m_number + 459.67) * 5) / 9);
|
||||
} else if (d->m_unitenum == KTemperature::Kelvin && unit == KTemperature::Celsius) {
|
||||
return (d->m_number - 273.15);
|
||||
} else if (d->m_unitenum == KTemperature::Kelvin && unit == KTemperature::Fahrenheit) {
|
||||
return (d->m_number * 1.8 - 459.67);
|
||||
return ((d->m_number * 1.8) - 459.67);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
@ -168,8 +165,7 @@ public:
|
|||
KVelocityPrivate(const double number, const KVelocity::KVeloUnit unit);
|
||||
KVelocityPrivate(const double number, const QString &unit);
|
||||
|
||||
double m_number;
|
||||
QString m_unit;
|
||||
const double m_number;
|
||||
KVelocity::KVeloUnit m_unitenum;
|
||||
};
|
||||
|
||||
|
@ -177,17 +173,6 @@ KVelocityPrivate::KVelocityPrivate(const double number, const KVelocity::KVeloUn
|
|||
: 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)
|
||||
|
@ -198,25 +183,20 @@ KVelocityPrivate::KVelocityPrivate(const double number, const QString &unit)
|
|||
|| unit == QLatin1String("meter per second") || unit == QLatin1String("meters per second")
|
||||
|| unit == QLatin1String("m/s") || unit == QLatin1String("ms")) {
|
||||
m_unitenum = KVelocity::MeterPerSecond;
|
||||
m_unit = QLatin1String("m/s");
|
||||
} else 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;
|
||||
m_unit = QLatin1String("km/h");
|
||||
} else if (unit == QLatin1String("MilePerHour")
|
||||
|| unit == QLatin1String("mile per hour") || unit == QLatin1String("miles per hour")
|
||||
|| unit == QLatin1String("mph")) {
|
||||
m_unitenum = KVelocity::MilePerHour;
|
||||
m_unit = QLatin1String("mph");
|
||||
} else if (unit == QLatin1String("Knot")
|
||||
|| unit == QLatin1String("knot") || unit == QLatin1String("knots")
|
||||
|| unit == QLatin1String("kt") || unit == QLatin1String("nautical miles per hour")) {
|
||||
m_unitenum = KVelocity::Knot;
|
||||
m_unit = QLatin1String("kt");
|
||||
} else {
|
||||
kDebug() << "invalid velocity unit" << unit;
|
||||
m_unit = QLatin1String("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,7 +222,20 @@ double KVelocity::number() const
|
|||
|
||||
QString KVelocity::unit() const
|
||||
{
|
||||
return d->m_unit;
|
||||
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::Invalid:
|
||||
case KVelocity::UnitCount:
|
||||
break;
|
||||
}
|
||||
return QLatin1String("Unknown");
|
||||
}
|
||||
|
||||
KVelocity::KVeloUnit KVelocity::unitEnum() const
|
||||
|
@ -252,7 +245,7 @@ KVelocity::KVeloUnit KVelocity::unitEnum() const
|
|||
|
||||
QString KVelocity::toString() const
|
||||
{
|
||||
return QString::fromLatin1("%1 %2").arg(QString::number(d->m_number), d->m_unit);
|
||||
return QString::fromLatin1("%1 %2").arg(QString::number(d->m_number), KVelocity::unit());
|
||||
}
|
||||
|
||||
double KVelocity::convertTo(const KVeloUnit unit) const
|
||||
|
@ -331,8 +324,7 @@ public:
|
|||
KPressurePrivate(const double number, const KPressure::KPresUnit unit);
|
||||
KPressurePrivate(const double number, const QString &unit);
|
||||
|
||||
double m_number;
|
||||
QString m_unit;
|
||||
const double m_number;
|
||||
KPressure::KPresUnit m_unitenum;
|
||||
};
|
||||
|
||||
|
@ -340,17 +332,6 @@ KPressurePrivate::KPressurePrivate(const double number, const KPressure::KPresUn
|
|||
: 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)
|
||||
|
@ -361,25 +342,20 @@ KPressurePrivate::KPressurePrivate(const double number, const QString &unit)
|
|||
|| unit == QLatin1String("kilopascal") || unit == QLatin1String("kilopascals")
|
||||
|| unit == QLatin1String("kPa")) {
|
||||
m_unitenum = KPressure::Kilopascal;
|
||||
m_unit = QLatin1String("kPa");
|
||||
} else if (unit == QLatin1String("Hectopascal")
|
||||
|| unit == QLatin1String("hectopascal") || unit == QLatin1String("hectopascals")
|
||||
|| unit == QLatin1String("hPa")) {
|
||||
m_unitenum = KPressure::Hectopascal;
|
||||
m_unit = QLatin1String("hPa");
|
||||
} else if (unit == QLatin1String("Millibar")
|
||||
|| unit == QLatin1String("millibar") || unit == QLatin1String("millibars")
|
||||
|| unit == QLatin1String("mbar") || unit == QLatin1String("mb")) {
|
||||
m_unitenum = KPressure::Millibar;
|
||||
m_unit = QLatin1String("mbar");
|
||||
} else if (unit == QLatin1String("InchesOfMercury")
|
||||
|| unit == QLatin1String("inch of mercury") || unit == QLatin1String("inches of mercury")
|
||||
|| unit == QLatin1String("inHg")) {
|
||||
m_unitenum = KPressure::InchesOfMercury;
|
||||
m_unit = QLatin1String("inHg");
|
||||
} else {
|
||||
kDebug() << "invalid pressure unit" << unit;
|
||||
m_unit = QLatin1String("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -405,7 +381,20 @@ double KPressure::number() const
|
|||
|
||||
QString KPressure::unit() const
|
||||
{
|
||||
return d->m_unit;
|
||||
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::Invalid:
|
||||
case KPressure::UnitCount:
|
||||
break;
|
||||
}
|
||||
return QLatin1String("Unknown");
|
||||
}
|
||||
|
||||
KPressure::KPresUnit KPressure::unitEnum() const
|
||||
|
@ -415,7 +404,7 @@ KPressure::KPresUnit KPressure::unitEnum() const
|
|||
|
||||
QString KPressure::toString() const
|
||||
{
|
||||
return QString::fromLatin1("%1 %2").arg(QString::number(d->m_number), d->m_unit);
|
||||
return QString::fromLatin1("%1 %2").arg(QString::number(d->m_number), KPressure::unit());
|
||||
}
|
||||
|
||||
double KPressure::convertTo(const KPresUnit unit) const
|
||||
|
@ -429,28 +418,27 @@ double KPressure::convertTo(const KPresUnit unit) const
|
|||
} 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);
|
||||
return (d->m_number / 3.386398);
|
||||
} 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 / 3.386398);
|
||||
return (d->m_number / 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::Millibar && unit == KPressure::Kilopascal) {
|
||||
return (d->m_number / 0.1);
|
||||
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.8639);
|
||||
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.8639);
|
||||
return (d->m_number * 33.86398);
|
||||
} else if (d->m_unitenum == KPressure::InchesOfMercury && unit == KPressure::Millibar) {
|
||||
return (d->m_number * 33.8639);
|
||||
return (d->m_number * 33.86398);
|
||||
}
|
||||
|
||||
return d->m_number;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
QString KPressure::description()
|
||||
|
@ -482,8 +470,7 @@ public:
|
|||
KLengthPrivate(const double number, const KLength::KLengUnit unit);
|
||||
KLengthPrivate(const double number, const QString &unit);
|
||||
|
||||
double m_number;
|
||||
QString m_unit;
|
||||
const double m_number;
|
||||
KLength::KLengUnit m_unitenum;
|
||||
};
|
||||
|
||||
|
@ -491,13 +478,6 @@ KLengthPrivate::KLengthPrivate(const double number, const KLength::KLengUnit uni
|
|||
: 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)
|
||||
|
@ -508,15 +488,12 @@ KLengthPrivate::KLengthPrivate(const double number, const QString &unit)
|
|||
|| unit == QLatin1String("mile") || unit == QLatin1String("miles")
|
||||
|| unit == QLatin1String("mi")) {
|
||||
m_unitenum = KLength::Mile;
|
||||
m_unit = QLatin1String("mi");
|
||||
} else if (unit == QLatin1String("Kilometer")
|
||||
|| unit == QLatin1String("kilometer") || unit == QLatin1String("kilometers")
|
||||
|| unit == QLatin1String("km")) {
|
||||
m_unitenum = KLength::Kilometer;
|
||||
m_unit = QLatin1String("km");
|
||||
} else {
|
||||
kDebug() << "invalid length unit" << unit;
|
||||
m_unit = QLatin1String("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -542,7 +519,16 @@ double KLength::number() const
|
|||
|
||||
QString KLength::unit() const
|
||||
{
|
||||
return d->m_unit;
|
||||
switch (d->m_unitenum) {
|
||||
case KLength::Mile:
|
||||
return QLatin1String("mi");
|
||||
case KLength::Kilometer:
|
||||
return QLatin1String("km");
|
||||
case KLength::Invalid:
|
||||
case KLength::UnitCount:
|
||||
break;
|
||||
}
|
||||
return QLatin1String("Unknown");
|
||||
}
|
||||
|
||||
KLength::KLengUnit KLength::unitEnum() const
|
||||
|
@ -552,7 +538,7 @@ KLength::KLengUnit KLength::unitEnum() const
|
|||
|
||||
QString KLength::toString() const
|
||||
{
|
||||
return QString::fromLatin1("%1 %2").arg(QString::number(d->m_number), d->m_unit);
|
||||
return QString::fromLatin1("%1 %2").arg(QString::number(d->m_number), KLength::unit());
|
||||
}
|
||||
|
||||
double KLength::convertTo(const KLengUnit unit) const
|
||||
|
|
Loading…
Add table
Reference in a new issue