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"
|
|
|
|
|
|
2018-06-03 20:15:19 +00:00
|
|
|
|
#include <core/qthelper.h>
|
2017-04-04 17:21:30 +00:00
|
|
|
|
#include <core/statistics.h>
|
|
|
|
|
#include <core/display.h>
|
|
|
|
|
|
|
|
|
|
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);
|
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();
|
|
|
|
|
ui->airPressureText->clear();
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
volume_t gases[MAX_CYLINDERS] = {};
|
2019-04-26 07:46:36 +00:00
|
|
|
|
get_gas_used(current_dive, gases);
|
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")));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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-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));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2019-04-26 07:46:36 +00:00
|
|
|
|
if (current_dive->surface_pressure.mbar) /* this is ALWAYS displayed in mbar */
|
|
|
|
|
ui->airPressureText->setText(QString("%1mbar").arg(current_dive->surface_pressure.mbar));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
else
|
|
|
|
|
ui->airPressureText->clear();
|
|
|
|
|
|
2019-04-26 07:46:36 +00:00
|
|
|
|
if (current_dive->salinity)
|
|
|
|
|
ui->salinityText->setText(QString("%1g/ℓ").arg(current_dive->salinity / 10.0));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
else
|
|
|
|
|
ui->salinityText->clear();
|
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.
|
|
|
|
|
void TabDiveInformation::divesChanged(dive_trip *trip, const QVector<dive *> &dives, DiveField field)
|
|
|
|
|
{
|
|
|
|
|
// If the current dive is not in list of changed dives, do nothing
|
|
|
|
|
if (!current_dive || !dives.contains(current_dive))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch(field) {
|
|
|
|
|
case DiveField::DURATION:
|
|
|
|
|
case DiveField::DEPTH:
|
|
|
|
|
case DiveField::MODE:
|
|
|
|
|
updateProfile();
|
|
|
|
|
break;
|
|
|
|
|
case DiveField::AIR_TEMP:
|
|
|
|
|
ui->airTemperatureText->setText(get_temperature_string(current_dive->airtemp, true));
|
|
|
|
|
break;
|
|
|
|
|
case DiveField::WATER_TEMP:
|
|
|
|
|
ui->waterTemperatureText->setText(get_temperature_string(current_dive->watertemp, true));
|
|
|
|
|
break;
|
|
|
|
|
case DiveField::DATETIME:
|
|
|
|
|
updateWhen();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-04-04 17:21:30 +00:00
|
|
|
|
}
|