units: replace SURFACE_PRESSURE by 1_atm

Moreover, convert diveplan::surface_pressure from int to
pressure_t.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-09-09 13:55:37 +02:00 committed by bstoeger
parent ae81b42fe2
commit dd5def35f5
11 changed files with 56 additions and 64 deletions

View file

@ -170,8 +170,9 @@ void DivePlannerWidget::settingsChanged()
ui.startTime->setDisplayFormat(QString::fromStdString(prefs.time_format));
}
void DivePlannerWidget::atmPressureChanged(const int pressure)
void DivePlannerWidget::atmPressureChanged(int pressure_in_mbar)
{
pressure_t pressure { .mbar = pressure_in_mbar };
DivePlannerPointsModel::instance()->setSurfacePressure(pressure);
ui.atmHeight->blockSignals(true);
ui.atmHeight->setValue((int) get_depth_units((int) pressure_to_altitude(pressure), NULL, NULL));
@ -180,9 +181,9 @@ void DivePlannerWidget::atmPressureChanged(const int pressure)
void DivePlannerWidget::heightChanged(const int height)
{ // height is in ft or in meters
int pressure = (int) (altitude_to_pressure(units_to_depth((double) height).mm));
pressure_t pressure = altitude_to_pressure(units_to_depth((double) height).mm);
ui.ATMPressure->blockSignals(true);
ui.ATMPressure->setValue(pressure);
ui.ATMPressure->setValue(pressure.mbar);
ui.ATMPressure->blockSignals(false);
DivePlannerPointsModel::instance()->setSurfacePressure(pressure);
}

View file

@ -439,18 +439,18 @@ void TabDiveInformation::updateTextBox(int event) // Either the text box has bee
altitudeVal = feet_to_mm(altitudeVal); // imperial: convert altitude from feet to mm
else
altitudeVal = altitudeVal * 1000; // metric: convert altitude from meters to mm
atmpress.mbar = altitude_to_pressure((int32_t) altitudeVal); // convert altitude (mm) to pressure (mbar)
atmpress = altitude_to_pressure((int32_t) altitudeVal); // convert altitude (mm) to pressure (mbar)
ui->atmPressVal->setText(QString::number(atmpress.mbar));
setIndexNoSignal(ui->atmPressType, 0); // reset combobox to mbar
} else { // i.e. event == COMBO_CHANGED, that is, "m" or "ft" was selected from combobox
// Show estimated altitude
bool ok;
double convertVal = 0.0010; // Metric conversion fro mm to m
int pressure_as_integer = ui->atmPressVal->text().toInt(&ok,10);
pressure_t pressure = { .mbar = ui->atmPressVal->text().toInt(&ok,10) };
if (ok && ui->atmPressVal->text().length()) { // Show existing atm press as an altitude:
if (prefs.units.length == units::FEET) // For imperial units
convertVal = mm_to_feet(1); // convert from mm to ft
ui->atmPressVal->setText(QString::number((int)(pressure_to_altitude(pressure_as_integer) * convertVal)));
ui->atmPressVal->setText(QString::number((int)(pressure_to_altitude(pressure) * convertVal)));
}
}
break;