mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 22:35:27 +00:00
Clean up conversion helpers
- coding style (ugh - I should have fixed that when I first committed them) - remove redundant variables - add similar code to the length and temperature helpers Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
bbbd479914
commit
75bd37e3e5
1 changed files with 37 additions and 33 deletions
|
@ -794,6 +794,11 @@ int parseLengthToMm(const QString &text)
|
|||
if (numOnly.isEmpty())
|
||||
return 0;
|
||||
double number = numOnly.toDouble();
|
||||
if (text.contains(QObject::tr("m"))) {
|
||||
mm = number * 1000;
|
||||
} else if (text.contains(QObject::tr("ft"))) {
|
||||
mm = feet_to_mm(number);
|
||||
} else {
|
||||
switch (prefs.units.length) {
|
||||
case units::FEET:
|
||||
mm = feet_to_mm(number);
|
||||
|
@ -804,6 +809,7 @@ int parseLengthToMm(const QString &text)
|
|||
default:
|
||||
mm = 0;
|
||||
}
|
||||
}
|
||||
return mm;
|
||||
|
||||
}
|
||||
|
@ -816,6 +822,11 @@ int parseTemperatureToMkelvin(const QString &text)
|
|||
if (numOnly.isEmpty())
|
||||
return 0;
|
||||
double number = numOnly.toDouble();
|
||||
if (text.contains(QObject::tr("C"))) {
|
||||
mkelvin = C_to_mkelvin(number);
|
||||
} else if (text.contains(QObject::tr("F"))) {
|
||||
mkelvin = F_to_mkelvin(number);
|
||||
} else {
|
||||
switch (prefs.units.temperature) {
|
||||
case units::CELSIUS:
|
||||
mkelvin = C_to_mkelvin(number);
|
||||
|
@ -826,23 +837,23 @@ int parseTemperatureToMkelvin(const QString &text)
|
|||
default:
|
||||
mkelvin = 0;
|
||||
}
|
||||
}
|
||||
return mkelvin;
|
||||
}
|
||||
|
||||
int parseWeightToGrams(const QString &text)
|
||||
{
|
||||
int grams;
|
||||
QString kg_or_lbs = text;
|
||||
QString numOnly = text;
|
||||
numOnly.replace(",", ".").remove(QRegExp("[^0-9.]"));
|
||||
if (numOnly.isEmpty())
|
||||
return 0;
|
||||
double number = numOnly.toDouble();
|
||||
if (kg_or_lbs.contains(QObject::tr("kg")))
|
||||
if (text.contains(QObject::tr("kg"))) {
|
||||
grams = rint(number * 1000);
|
||||
else if (kg_or_lbs.contains(QObject::tr("lbs")))
|
||||
} else if (text.contains(QObject::tr("lbs"))) {
|
||||
grams = lbs_to_grams(number);
|
||||
else {
|
||||
} else {
|
||||
switch (prefs.units.weight) {
|
||||
case units::KG:
|
||||
grams = rint(number * 1000);
|
||||
|
@ -860,17 +871,16 @@ int parseWeightToGrams(const QString &text)
|
|||
int parsePressureToMbar(const QString &text)
|
||||
{
|
||||
int mbar;
|
||||
QString psi_or_bar = text;
|
||||
QString numOnly = text;
|
||||
numOnly.replace(",", ".").remove(QRegExp("[^0-9.]"));
|
||||
if (numOnly.isEmpty())
|
||||
return 0;
|
||||
double number = numOnly.toDouble();
|
||||
if (psi_or_bar.contains(QObject::tr("bar")))
|
||||
if (text.contains(QObject::tr("bar"))) {
|
||||
mbar = rint(number * 1000);
|
||||
else if (psi_or_bar.contains(QObject::tr("psi")))
|
||||
} else if (text.contains(QObject::tr("psi"))) {
|
||||
mbar = psi_to_mbar(number);
|
||||
else {
|
||||
} else {
|
||||
switch (prefs.units.pressure) {
|
||||
case units::BAR:
|
||||
mbar = rint(number * 1000);
|
||||
|
@ -891,22 +901,18 @@ int parseGasMixO2(const QString &text)
|
|||
int o2, number;
|
||||
if (gasString.contains(QObject::tr("AIR"), Qt::CaseInsensitive)) {
|
||||
o2 = O2_IN_AIR;
|
||||
}
|
||||
else if (gasString.contains(QObject::tr("EAN"), Qt::CaseInsensitive)) {
|
||||
} else if (gasString.contains(QObject::tr("EAN"), Qt::CaseInsensitive)) {
|
||||
gasString.remove(QRegExp("[^0-9]"));
|
||||
number = gasString.toInt();
|
||||
o2 = number * 10;
|
||||
}
|
||||
else if (gasString.contains("/")) {
|
||||
} else if (gasString.contains("/")) {
|
||||
QStringList gasSplit = gasString.split("/");
|
||||
number = gasSplit[0].toInt();
|
||||
o2 = number * 10;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
number = gasString.toInt();
|
||||
o2 = number * 10;
|
||||
}
|
||||
|
||||
return o2;
|
||||
}
|
||||
|
||||
|
@ -918,11 +924,9 @@ int parseGasMixHE(const QString &text)
|
|||
QStringList gasSplit = gasString.split("/");
|
||||
number = gasSplit[1].toInt();
|
||||
he = number * 10;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
he = 0;
|
||||
}
|
||||
|
||||
return he;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue