2017-04-27 18:26:05 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-04 17:21:30 +00:00
|
|
|
|
#include "TabDiveInformation.h"
|
|
|
|
|
#include "ui_TabDiveInformation.h"
|
|
|
|
|
#include "../tagwidget.h"
|
2019-04-30 10:42:33 +00:00
|
|
|
|
#include "core/units.h"
|
|
|
|
|
#include "core/dive.h"
|
|
|
|
|
#include "desktop-widgets/command.h"
|
2019-06-07 12:00:16 +00:00
|
|
|
|
#include "core/qthelper.h"
|
|
|
|
|
#include "core/statistics.h"
|
|
|
|
|
#include "core/display.h"
|
2019-07-15 21:44:39 +00:00
|
|
|
|
#include "core/divelist.h"
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2019-04-30 10:42:33 +00:00
|
|
|
|
#define COMBO_CHANGED 0
|
|
|
|
|
#define TEXT_EDITED 1
|
|
|
|
|
|
2017-04-04 17:21:30 +00:00
|
|
|
|
TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation())
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2019-04-26 08:03:32 +00:00
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveInformation::divesChanged);
|
2019-04-30 10:42:33 +00:00
|
|
|
|
QStringList atmPressTypes { "mbar", get_depth_unit() ,"use dc"};
|
|
|
|
|
ui->atmPressType->insertItems(0, atmPressTypes);
|
|
|
|
|
pressTypeIndex = 0;
|
2017-04-04 17:21:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TabDiveInformation::~TabDiveInformation()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::clear()
|
|
|
|
|
{
|
|
|
|
|
ui->sacText->clear();
|
|
|
|
|
ui->otuText->clear();
|
|
|
|
|
ui->maxcnsText->clear();
|
|
|
|
|
ui->oxygenHeliumText->clear();
|
|
|
|
|
ui->gasUsedText->clear();
|
|
|
|
|
ui->dateText->clear();
|
|
|
|
|
ui->diveTimeText->clear();
|
|
|
|
|
ui->surfaceIntervalText->clear();
|
|
|
|
|
ui->maximumDepthText->clear();
|
|
|
|
|
ui->averageDepthText->clear();
|
|
|
|
|
ui->waterTemperatureText->clear();
|
|
|
|
|
ui->airTemperatureText->clear();
|
2019-04-30 10:42:33 +00:00
|
|
|
|
ui->atmPressVal->clear();
|
2017-04-04 17:21:30 +00:00
|
|
|
|
ui->salinityText->clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-26 08:03:32 +00:00
|
|
|
|
// Update fields that depend on the dive profile
|
|
|
|
|
void TabDiveInformation::updateProfile()
|
2017-04-04 17:21:30 +00:00
|
|
|
|
{
|
2019-04-26 07:46:36 +00:00
|
|
|
|
ui->maxcnsText->setText(QString("%1\%").arg(current_dive->maxcns));
|
|
|
|
|
ui->otuText->setText(QString("%1").arg(current_dive->otu));
|
|
|
|
|
ui->maximumDepthText->setText(get_depth_string(current_dive->maxdepth, true));
|
|
|
|
|
ui->averageDepthText->setText(get_depth_string(current_dive->meandepth, true));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2019-06-27 05:42:09 +00:00
|
|
|
|
volume_t *gases = get_gas_used(current_dive);
|
2017-04-04 17:21:30 +00:00
|
|
|
|
QString volumes;
|
|
|
|
|
int mean[MAX_CYLINDERS], duration[MAX_CYLINDERS];
|
2019-04-26 07:46:36 +00:00
|
|
|
|
per_cylinder_mean_depth(current_dive, select_dc(current_dive), mean, duration);
|
2017-04-04 17:21:30 +00:00
|
|
|
|
volume_t sac;
|
|
|
|
|
QString gaslist, SACs, separator;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2019-04-26 07:46:36 +00:00
|
|
|
|
if (!is_cylinder_used(current_dive, i))
|
2017-04-04 17:21:30 +00:00
|
|
|
|
continue;
|
|
|
|
|
gaslist.append(separator); volumes.append(separator); SACs.append(separator);
|
|
|
|
|
separator = "\n";
|
|
|
|
|
|
2019-04-26 07:46:36 +00:00
|
|
|
|
gaslist.append(gasname(current_dive->cylinder[i].gasmix));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
if (!gases[i].mliter)
|
|
|
|
|
continue;
|
|
|
|
|
volumes.append(get_volume_string(gases[i], true));
|
|
|
|
|
if (duration[i]) {
|
2019-04-26 07:46:36 +00:00
|
|
|
|
sac.mliter = lrint(gases[i].mliter / (depth_to_atm(mean[i], current_dive) * duration[i] / 60));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
SACs.append(get_volume_string(sac, true).append(tr("/min")));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-27 05:42:09 +00:00
|
|
|
|
free(gases);
|
2017-04-04 17:21:30 +00:00
|
|
|
|
ui->gasUsedText->setText(volumes);
|
|
|
|
|
ui->oxygenHeliumText->setText(gaslist);
|
|
|
|
|
|
2019-04-26 07:46:36 +00:00
|
|
|
|
ui->diveTimeText->setText(get_dive_duration_string(current_dive->duration.seconds, tr("h"), tr("min"), tr("sec"),
|
|
|
|
|
" ", current_dive->dc.divemode == FREEDIVE));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2019-04-26 08:03:32 +00:00
|
|
|
|
ui->sacText->setText( mean[0] ? SACs : QString());
|
2019-04-30 10:42:33 +00:00
|
|
|
|
|
|
|
|
|
if (current_dive->surface_pressure.mbar == 0) {
|
|
|
|
|
ui->atmPressVal->clear(); // If no atm pressure for dive then clear text box
|
2019-05-15 14:42:14 +00:00
|
|
|
|
} else {
|
2019-04-30 10:42:33 +00:00
|
|
|
|
|
|
|
|
|
ui->atmPressVal->setEnabled(true);
|
|
|
|
|
QString pressStr;
|
|
|
|
|
pressStr.sprintf("%d",current_dive->surface_pressure.mbar);
|
|
|
|
|
ui->atmPressVal->setText(pressStr); // else display atm pressure
|
|
|
|
|
}
|
2019-04-26 08:03:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update fields that depend on start of dive
|
|
|
|
|
void TabDiveInformation::updateWhen()
|
|
|
|
|
{
|
|
|
|
|
ui->dateText->setText(get_short_dive_date_string(current_dive->when));
|
2019-04-26 07:46:36 +00:00
|
|
|
|
timestamp_t surface_interval = get_surface_interval(current_dive->when);
|
2018-10-06 07:21:27 +00:00
|
|
|
|
if (surface_interval >= 0)
|
|
|
|
|
ui->surfaceIntervalText->setText(get_dive_surfint_string(surface_interval, tr("d"), tr("h"), tr("min")));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
else
|
|
|
|
|
ui->surfaceIntervalText->clear();
|
2019-04-26 08:03:32 +00:00
|
|
|
|
}
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2019-10-12 22:01:44 +00:00
|
|
|
|
void TabDiveInformation::updateSalinity()
|
|
|
|
|
{
|
|
|
|
|
if (current_dive->salinity)
|
|
|
|
|
ui->salinityText->setText(QString("%1g/ℓ").arg(current_dive->salinity / 10.0));
|
|
|
|
|
else
|
|
|
|
|
ui->salinityText->clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-26 08:03:32 +00:00
|
|
|
|
void TabDiveInformation::updateData()
|
|
|
|
|
{
|
|
|
|
|
if (!current_dive) {
|
|
|
|
|
clear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateProfile();
|
|
|
|
|
updateWhen();
|
|
|
|
|
ui->waterTemperatureText->setText(get_temperature_string(current_dive->watertemp, true));
|
|
|
|
|
ui->airTemperatureText->setText(get_temperature_string(current_dive->airtemp, true));
|
2019-10-12 22:01:44 +00:00
|
|
|
|
updateSalinity();
|
2019-04-30 10:42:33 +00:00
|
|
|
|
|
|
|
|
|
ui->atmPressType->setEditable(true);
|
|
|
|
|
ui->atmPressType->setItemText(1, get_depth_unit()); // Check for changes in depth unit (imperial/metric)
|
|
|
|
|
ui->atmPressType->setEditable(false);
|
|
|
|
|
ui->atmPressType->setCurrentIndex(0); // Set the atmospheric pressure combo box to mbar
|
2019-04-26 08:03:32 +00:00
|
|
|
|
}
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2019-04-26 08:03:32 +00:00
|
|
|
|
// This function gets called if a field gets updated by an undo command.
|
|
|
|
|
// Refresh the corresponding UI field.
|
2019-06-23 07:22:26 +00:00
|
|
|
|
void TabDiveInformation::divesChanged(const QVector<dive *> &dives, DiveField field)
|
2019-04-26 08:03:32 +00:00
|
|
|
|
{
|
|
|
|
|
// If the current dive is not in list of changed dives, do nothing
|
|
|
|
|
if (!current_dive || !dives.contains(current_dive))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.duration || field.depth || field.mode)
|
2019-04-26 08:03:32 +00:00
|
|
|
|
updateProfile();
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.air_temp)
|
2019-04-26 08:03:32 +00:00
|
|
|
|
ui->airTemperatureText->setText(get_temperature_string(current_dive->airtemp, true));
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.water_temp)
|
2019-04-26 08:03:32 +00:00
|
|
|
|
ui->waterTemperatureText->setText(get_temperature_string(current_dive->watertemp, true));
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.atm_press)
|
2019-04-30 10:42:33 +00:00
|
|
|
|
ui->atmPressVal->setText(ui->atmPressVal->text().sprintf("%d",current_dive->surface_pressure.mbar));
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.datetime)
|
2019-04-26 08:03:32 +00:00
|
|
|
|
updateWhen();
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.salinity)
|
2019-10-12 22:01:44 +00:00
|
|
|
|
updateSalinity();
|
2017-04-04 17:21:30 +00:00
|
|
|
|
}
|
2019-04-30 10:42:33 +00:00
|
|
|
|
|
|
|
|
|
void TabDiveInformation::on_atmPressType_currentIndexChanged(int index) { updateTextBox(COMBO_CHANGED); }
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::on_atmPressVal_editingFinished() { updateTextBox(TEXT_EDITED); }
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::updateTextBox(int event) // Either the text box has been edited or the pressure type has changed.
|
|
|
|
|
{ // Either way this gets a numeric value and puts it on the text box atmPressVal,
|
|
|
|
|
pressure_t atmpress = { 0 }; // then stores it in dive->surface_pressure.The undo stack for the text box content is
|
|
|
|
|
double altitudeVal; // maintained even though two independent events trigger saving the text box contents.
|
|
|
|
|
if (current_dive) {
|
|
|
|
|
switch (ui->atmPressType->currentIndex()) {
|
|
|
|
|
case 0: // If an atm pressure has been specified in mbar:
|
|
|
|
|
if (event == TEXT_EDITED) // this is only triggered by on_atmPressVal_editingFinished()
|
|
|
|
|
atmpress.mbar = ui->atmPressVal->text().toInt(); // use the specified mbar pressure
|
|
|
|
|
break;
|
|
|
|
|
case 1: // If an altitude has been specified:
|
|
|
|
|
if (event == TEXT_EDITED) { // this is only triggered by on_atmPressVal_editingFinished()
|
|
|
|
|
altitudeVal = (ui->atmPressVal->text().toFloat()); // get altitude from text box
|
|
|
|
|
if (prefs.units.length == units::FEET) // if altitude in feet
|
|
|
|
|
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)
|
|
|
|
|
ui->atmPressVal->setText(ui->atmPressVal->text().sprintf("%d",atmpress.mbar));
|
|
|
|
|
ui->atmPressType->setCurrentIndex(0); // reset combobox to mbar
|
|
|
|
|
} else { // i.e. event == COMBO_CHANGED, that is, "m" or "ft" was selected from combobox
|
|
|
|
|
ui->atmPressVal->clear(); // Clear the text box so that altitude can be typed
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2: // i.e. event = COMBO_CHANGED, that is, the option "Use dc" was selected from combobox
|
|
|
|
|
atmpress = calculate_surface_pressure(current_dive); // re-calculate air pressure from dc data
|
|
|
|
|
ui->atmPressVal->setText(QString::number(atmpress.mbar)); // display it in text box
|
|
|
|
|
ui->atmPressType->setCurrentIndex(0); // reset combobox to mbar
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
atmpress.mbar = 1013; // This line should never execute
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (atmpress.mbar)
|
|
|
|
|
Command::editAtmPress(atmpress.mbar, false); // and save the pressure for undo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|