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"
|
2022-09-17 14:21:17 +00:00
|
|
|
|
#include "maintab.h"
|
2017-04-04 17:21:30 +00:00
|
|
|
|
#include "ui_TabDiveInformation.h"
|
2019-11-10 21:09:19 +00:00
|
|
|
|
#include "profile-widget/profilewidget2.h"
|
2017-04-04 17:21:30 +00:00
|
|
|
|
#include "../tagwidget.h"
|
2019-11-13 14:08:40 +00:00
|
|
|
|
#include "commands/command.h"
|
2019-11-20 18:40:23 +00:00
|
|
|
|
#include "core/subsurface-string.h"
|
2019-04-30 10:42:33 +00:00
|
|
|
|
#include "core/units.h"
|
|
|
|
|
#include "core/dive.h"
|
2019-06-07 12:00:16 +00:00
|
|
|
|
#include "core/qthelper.h"
|
2022-04-04 16:57:28 +00:00
|
|
|
|
#include "core/selection.h"
|
2019-06-07 12:00:16 +00:00
|
|
|
|
#include "core/statistics.h"
|
2019-07-15 21:44:39 +00:00
|
|
|
|
#include "core/divelist.h"
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2024-01-16 17:11:02 +00:00
|
|
|
|
#include <QSignalBlocker>
|
|
|
|
|
|
2019-04-30 10:42:33 +00:00
|
|
|
|
#define COMBO_CHANGED 0
|
|
|
|
|
#define TEXT_EDITED 1
|
|
|
|
|
|
2024-01-16 17:11:02 +00:00
|
|
|
|
// Helper function to set index of combobox without emitting a signal
|
|
|
|
|
// that would fire an editing event.
|
|
|
|
|
static void setIndexNoSignal(QComboBox *combobox, int index)
|
|
|
|
|
{
|
|
|
|
|
QSignalBlocker blocker(combobox);
|
|
|
|
|
combobox->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 16:12:31 +00:00
|
|
|
|
TabDiveInformation::TabDiveInformation(MainTab *parent) : TabBase(parent), ui(new Ui::TabDiveInformation())
|
2017-04-04 17:21:30 +00:00
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2019-04-26 08:03:32 +00:00
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveInformation::divesChanged);
|
2020-05-05 09:51:20 +00:00
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::cylinderAdded, this, &TabDiveInformation::cylinderChanged);
|
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::cylinderRemoved, this, &TabDiveInformation::cylinderChanged);
|
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::cylinderEdited, this, &TabDiveInformation::cylinderChanged);
|
2020-11-01 18:43:54 +00:00
|
|
|
|
|
2020-05-05 12:30:29 +00:00
|
|
|
|
QStringList atmPressTypes { "mbar", get_depth_unit() ,tr("Use DC")};
|
2019-04-30 10:42:33 +00:00
|
|
|
|
ui->atmPressType->insertItems(0, atmPressTypes);
|
|
|
|
|
pressTypeIndex = 0;
|
2020-09-21 19:44:35 +00:00
|
|
|
|
ui->waterTypeCombo->insertItems(0, getWaterTypesAsString());
|
2019-11-19 10:27:18 +00:00
|
|
|
|
|
2019-11-10 21:09:19 +00:00
|
|
|
|
// This needs to be the same order as enum dive_comp_type in dive.h!
|
|
|
|
|
QStringList types;
|
|
|
|
|
for (int i = 0; i < NUM_DIVEMODE; i++)
|
|
|
|
|
types.append(gettextFromC::tr(divemode_text_ui[i]));
|
|
|
|
|
ui->diveType->insertItems(0, types);
|
|
|
|
|
connect(ui->diveType, SIGNAL(currentIndexChanged(int)), this, SLOT(diveModeChanged(int)));
|
2019-11-28 10:35:39 +00:00
|
|
|
|
if (!prefs.extraEnvironmentalDefault) // if extraEnvironmental preference is turned off
|
|
|
|
|
showCurrentWidget(false, 0); // Show current star widget at lefthand side
|
2019-11-10 21:09:19 +00:00
|
|
|
|
QAction *action = new QAction(tr("OK"), this);
|
|
|
|
|
connect(action, &QAction::triggered, this, &TabDiveInformation::closeWarning);
|
|
|
|
|
ui->multiDiveWarningMessage->addAction(action);
|
|
|
|
|
action = new QAction(tr("Undo"), this);
|
|
|
|
|
connect(action, &QAction::triggered, Command::undoAction(this), &QAction::trigger);
|
|
|
|
|
connect(action, &QAction::triggered, this, &TabDiveInformation::closeWarning);
|
|
|
|
|
ui->multiDiveWarningMessage->addAction(action);
|
|
|
|
|
ui->multiDiveWarningMessage->hide();
|
2019-11-19 10:27:18 +00:00
|
|
|
|
updateWaterTypeWidget();
|
|
|
|
|
QPixmap warning (":salinity-warning-icon");
|
|
|
|
|
ui->salinityOverWrittenIcon->setPixmap(warning);
|
2023-03-29 15:49:55 +00:00
|
|
|
|
ui->salinityOverWrittenIcon->setToolTip("Water type differs from that of DC(s)");
|
2019-11-19 10:27:18 +00:00
|
|
|
|
ui->salinityOverWrittenIcon->setToolTipDuration(2500);
|
2020-01-05 00:12:59 +00:00
|
|
|
|
ui->salinityOverWrittenIcon->setVisible(false);
|
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->diveTimeText->clear();
|
|
|
|
|
ui->surfaceIntervalText->clear();
|
|
|
|
|
ui->maximumDepthText->clear();
|
|
|
|
|
ui->averageDepthText->clear();
|
2019-11-11 09:47:12 +00:00
|
|
|
|
ui->watertemp->clear();
|
|
|
|
|
ui->airtemp->clear();
|
2019-04-30 10:42:33 +00:00
|
|
|
|
ui->atmPressVal->clear();
|
2017-04-04 17:21:30 +00:00
|
|
|
|
ui->salinityText->clear();
|
2019-11-10 21:09:19 +00:00
|
|
|
|
ui->waterTypeText->clear();
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->waterTypeCombo, 0);
|
2019-11-10 21:09:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::divesEdited(int i)
|
|
|
|
|
{
|
|
|
|
|
// No warning if only one dive was edited
|
|
|
|
|
if (i <= 1)
|
|
|
|
|
return;
|
|
|
|
|
ui->multiDiveWarningMessage->setCloseButtonVisible(false);
|
|
|
|
|
ui->multiDiveWarningMessage->setText(tr("Warning: edited %1 dives").arg(i));
|
|
|
|
|
ui->multiDiveWarningMessage->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::closeWarning()
|
|
|
|
|
{
|
|
|
|
|
ui->multiDiveWarningMessage->hide();
|
2017-04-04 17:21:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-19 10:27:18 +00:00
|
|
|
|
void TabDiveInformation::updateWaterTypeWidget()
|
2023-03-29 15:49:55 +00:00
|
|
|
|
{
|
|
|
|
|
// Decide on whether to show the water type/salinity combobox or not
|
2023-07-12 21:49:03 +00:00
|
|
|
|
bool hasDCSalinity = parent.currentDive && parent.currentDive->salinity != 0;
|
2023-03-29 15:49:55 +00:00
|
|
|
|
if (prefs.salinityEditDefault || !hasDCSalinity) { // if the preference setting has been checked or DC doesnt have salinity info
|
2019-11-19 10:27:18 +00:00
|
|
|
|
ui->waterTypeText->setVisible(false);
|
2019-11-20 18:40:23 +00:00
|
|
|
|
ui->waterTypeCombo->setVisible(true); // show combobox
|
|
|
|
|
} else { // if the preference setting has not been set
|
2019-11-19 10:27:18 +00:00
|
|
|
|
ui->waterTypeCombo->setVisible(false);
|
2019-11-20 18:40:23 +00:00
|
|
|
|
ui->waterTypeText->setVisible(true); // show water type as text label
|
2019-11-19 10:27:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
dive *currentDive = parent.currentDive;
|
|
|
|
|
ui->maxcnsText->setText(QString("%L1\%").arg(currentDive->maxcns));
|
|
|
|
|
ui->otuText->setText(QString("%L1").arg(currentDive->otu));
|
|
|
|
|
ui->maximumDepthText->setText(get_depth_string(currentDive->maxdepth, true));
|
|
|
|
|
ui->averageDepthText->setText(get_depth_string(currentDive->meandepth, true));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2024-05-01 21:16:00 +00:00
|
|
|
|
std::vector<volume_t> gases = get_gas_used(currentDive);
|
2017-04-04 17:21:30 +00:00
|
|
|
|
QString volumes;
|
2022-09-17 14:21:17 +00:00
|
|
|
|
std::vector<int> mean(currentDive->cylinders.nr), duration(currentDive->cylinders.nr);
|
|
|
|
|
struct divecomputer *currentdc = parent.getCurrentDC();
|
|
|
|
|
if (currentdc && currentDive->cylinders.nr >= 0)
|
|
|
|
|
per_cylinder_mean_depth(currentDive, currentdc, mean.data(), duration.data());
|
2017-04-04 17:21:30 +00:00
|
|
|
|
volume_t sac;
|
|
|
|
|
QString gaslist, SACs, separator;
|
|
|
|
|
|
2022-09-17 14:21:17 +00:00
|
|
|
|
for (int i = 0; i < currentDive->cylinders.nr; i++) {
|
|
|
|
|
if (!is_cylinder_used(currentDive, i))
|
2017-04-04 17:21:30 +00:00
|
|
|
|
continue;
|
|
|
|
|
gaslist.append(separator); volumes.append(separator); SACs.append(separator);
|
|
|
|
|
separator = "\n";
|
|
|
|
|
|
2022-09-17 14:21:17 +00:00
|
|
|
|
gaslist.append(gasname(get_cylinder(currentDive, 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]) {
|
2022-09-17 14:21:17 +00:00
|
|
|
|
sac.mliter = lrint(gases[i].mliter / (depth_to_atm(mean[i], currentDive) * 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);
|
|
|
|
|
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->diveTimeText->setText(get_dive_duration_string(currentDive->duration.seconds, tr("h"), tr("min"), tr("sec"),
|
|
|
|
|
" ", currentDive->dc.divemode == FREEDIVE));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2024-01-16 16:39:19 +00:00
|
|
|
|
ui->sacText->setText(currentDive->cylinders.nr > 0 && mean[0] && currentDive->dc.divemode != CCR ? std::move(SACs) : QString());
|
2019-04-30 10:42:33 +00:00
|
|
|
|
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (currentDive->surface_pressure.mbar == 0) {
|
2019-04-30 10:42:33 +00:00
|
|
|
|
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);
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->atmPressVal->setText(QString::number(currentDive->surface_pressure.mbar)); // else display atm pressure
|
2019-04-30 10:42:33 +00:00
|
|
|
|
}
|
2019-04-26 08:03:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update fields that depend on start of dive
|
|
|
|
|
void TabDiveInformation::updateWhen()
|
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
timestamp_t surface_interval = get_surface_interval(parent.currentDive->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-11-19 10:27:18 +00:00
|
|
|
|
// Provide an index for the combobox that corresponds to the salinity value
|
|
|
|
|
int TabDiveInformation::updateSalinityComboIndex(int salinity)
|
2019-10-12 22:01:44 +00:00
|
|
|
|
{
|
2019-11-19 10:27:18 +00:00
|
|
|
|
if (salinity == 0)
|
2020-01-05 00:06:28 +00:00
|
|
|
|
return -1; // we don't know
|
2019-11-19 10:27:18 +00:00
|
|
|
|
else if (salinity < 10050)
|
|
|
|
|
return FRESHWATER;
|
|
|
|
|
else if (salinity < 10190)
|
2020-05-04 23:07:56 +00:00
|
|
|
|
return BRACKISHWATER;
|
2019-11-19 10:27:18 +00:00
|
|
|
|
else if (salinity < 10210)
|
|
|
|
|
return EN13319WATER;
|
|
|
|
|
else
|
|
|
|
|
return SALTWATER;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 15:49:55 +00:00
|
|
|
|
// If dive->user_salinity != dive->salinity then show the salinity-overwrite indicator
|
2019-11-19 10:27:18 +00:00
|
|
|
|
void TabDiveInformation::checkDcSalinityOverWritten()
|
|
|
|
|
{
|
2023-03-29 15:49:55 +00:00
|
|
|
|
dive *currentDive = parent.currentDive;
|
|
|
|
|
int dc_value = currentDive->salinity;
|
|
|
|
|
int user_value = currentDive->user_salinity;
|
2019-11-19 17:16:45 +00:00
|
|
|
|
bool show_indicator = false;
|
2023-03-29 15:49:55 +00:00
|
|
|
|
if (dc_value != 0 && user_value != 0 && user_value != dc_value)
|
2020-01-05 00:12:59 +00:00
|
|
|
|
show_indicator = true;
|
2019-11-19 17:16:45 +00:00
|
|
|
|
ui->salinityOverWrittenIcon->setVisible(show_indicator);
|
2019-10-12 22:01:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 10:35:39 +00:00
|
|
|
|
void TabDiveInformation::showCurrentWidget(bool show, int position)
|
|
|
|
|
{
|
2019-11-19 17:16:45 +00:00
|
|
|
|
ui->groupBox_wavesize->setVisible(show);
|
|
|
|
|
ui->groupBox_surge->setVisible(show);
|
|
|
|
|
ui->groupBox_chill->setVisible(show);
|
|
|
|
|
int layoutPosition = ui->diveInfoScrollAreaLayout->indexOf(ui->groupBox_current);
|
|
|
|
|
ui->diveInfoScrollAreaLayout->takeAt(layoutPosition);
|
|
|
|
|
ui->diveInfoScrollAreaLayout->addWidget(ui->groupBox_current, 6, position, 1, 1);
|
2019-11-28 10:35:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 09:04:01 +00:00
|
|
|
|
void TabDiveInformation::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
2019-04-26 08:03:32 +00:00
|
|
|
|
{
|
2019-11-19 10:27:18 +00:00
|
|
|
|
int salinity_value;
|
|
|
|
|
updateWaterTypeWidget();
|
2019-04-26 08:03:32 +00:00
|
|
|
|
updateProfile();
|
|
|
|
|
updateWhen();
|
2022-09-04 09:04:01 +00:00
|
|
|
|
ui->watertemp->setText(get_temperature_string(currentDive->watertemp, true));
|
|
|
|
|
ui->airtemp->setText(get_temperature_string(currentDive->airtemp, true));
|
2019-04-30 10:42:33 +00:00
|
|
|
|
ui->atmPressType->setItemText(1, get_depth_unit()); // Check for changes in depth unit (imperial/metric)
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->atmPressType, 0); // Set the atmospheric pressure combo box to mbar
|
2022-09-04 09:04:01 +00:00
|
|
|
|
salinity_value = get_dive_salinity(currentDive);
|
2019-11-19 10:27:18 +00:00
|
|
|
|
if (salinity_value) { // Set water type indicator (EN13319 = 1.020 g/l)
|
2023-03-29 15:49:55 +00:00
|
|
|
|
if (ui->waterTypeCombo->isVisible()) { // If water salinity is editable then set correct water type in combobox:
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->waterTypeCombo, updateSalinityComboIndex(salinity_value));
|
2019-11-19 10:27:18 +00:00
|
|
|
|
} else { // If water salinity is not editable: show water type as a text label
|
2020-11-02 20:10:33 +00:00
|
|
|
|
ui->waterTypeText->setText(get_water_type_string(salinity_value));
|
2019-11-19 10:27:18 +00:00
|
|
|
|
}
|
2020-05-04 13:54:58 +00:00
|
|
|
|
ui->salinityText->setText(get_salinity_string(salinity_value));
|
2019-11-19 10:27:18 +00:00
|
|
|
|
} else {
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->waterTypeCombo, -1);
|
2020-01-05 00:06:28 +00:00
|
|
|
|
ui->waterTypeText->setText(tr("unknown"));
|
2019-11-19 10:27:18 +00:00
|
|
|
|
ui->salinityText->clear();
|
|
|
|
|
}
|
2020-01-05 00:12:59 +00:00
|
|
|
|
checkDcSalinityOverWritten(); // If exclamation is needed (i.e. salinity overwrite by user), then show it
|
|
|
|
|
|
2022-09-17 14:21:17 +00:00
|
|
|
|
updateMode();
|
2022-09-04 09:04:01 +00:00
|
|
|
|
ui->visibility->setCurrentStars(currentDive->visibility);
|
|
|
|
|
ui->wavesize->setCurrentStars(currentDive->wavesize);
|
|
|
|
|
ui->current->setCurrentStars(currentDive->current);
|
|
|
|
|
ui->surge->setCurrentStars(currentDive->surge);
|
|
|
|
|
ui->chill->setCurrentStars(currentDive->chill);
|
2019-11-28 10:35:39 +00:00
|
|
|
|
if (prefs.extraEnvironmentalDefault)
|
|
|
|
|
showCurrentWidget(true, 2); // Show current star widget at 3rd position
|
|
|
|
|
else
|
|
|
|
|
showCurrentWidget(false, 0); // Show current star widget at lefthand side
|
2019-04-26 08:03:32 +00:00
|
|
|
|
}
|
2017-04-04 17:21:30 +00:00
|
|
|
|
|
2020-11-04 21:09:44 +00:00
|
|
|
|
void TabDiveInformation::updateUi(QString titleColor)
|
2020-11-02 20:10:33 +00:00
|
|
|
|
{
|
2020-11-02 20:36:29 +00:00
|
|
|
|
QString CSSSetSmallLabel = "QLabel:enabled { color: ";
|
2020-11-04 21:09:44 +00:00
|
|
|
|
CSSSetSmallLabel.append(titleColor + "; font-size: ");
|
2020-11-02 20:10:33 +00:00
|
|
|
|
CSSSetSmallLabel.append(QString::number((int)(0.5 + ui->diveHeadingLabel->geometry().height() * 0.66)) + "px;}");
|
2020-11-02 20:36:29 +00:00
|
|
|
|
ui->groupBox_visibility->setStyleSheet(ui->groupBox_visibility->styleSheet() + CSSSetSmallLabel);
|
|
|
|
|
ui->groupBox_current->setStyleSheet(ui->groupBox_current->styleSheet() + CSSSetSmallLabel);
|
|
|
|
|
ui->groupBox_wavesize->setStyleSheet(ui->groupBox_wavesize->styleSheet() + CSSSetSmallLabel);
|
|
|
|
|
ui->groupBox_surge->setStyleSheet(ui->groupBox_surge->styleSheet() + CSSSetSmallLabel);
|
|
|
|
|
ui->groupBox_chill->setStyleSheet(ui->groupBox_chill->styleSheet() + CSSSetSmallLabel);
|
2023-03-29 15:49:55 +00:00
|
|
|
|
ui->salinityOverWrittenIcon->setStyleSheet(ui->salinityOverWrittenIcon->styleSheet() + CSSSetSmallLabel);
|
2020-11-02 20:10:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-19 17:16:45 +00:00
|
|
|
|
// From the index of the water type combo box, set the dive->salinity to an appropriate value
|
2020-05-24 09:59:35 +00:00
|
|
|
|
void TabDiveInformation::on_waterTypeCombo_activated(int index)
|
|
|
|
|
{
|
2020-01-05 00:05:31 +00:00
|
|
|
|
Q_UNUSED(index)
|
2019-11-19 10:27:18 +00:00
|
|
|
|
int combobox_salinity = 0;
|
2023-03-29 15:49:55 +00:00
|
|
|
|
int dc_salinity = parent.currentDive->salinity;
|
2019-11-19 10:27:18 +00:00
|
|
|
|
switch(ui->waterTypeCombo->currentIndex()) {
|
|
|
|
|
case FRESHWATER:
|
|
|
|
|
combobox_salinity = FRESHWATER_SALINITY;
|
|
|
|
|
break;
|
2020-05-04 23:07:56 +00:00
|
|
|
|
case BRACKISHWATER:
|
|
|
|
|
combobox_salinity = BRACKISH_SALINITY;
|
2019-11-19 10:27:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case EN13319WATER:
|
|
|
|
|
combobox_salinity = EN13319_SALINITY;
|
|
|
|
|
break;
|
|
|
|
|
case SALTWATER:
|
|
|
|
|
combobox_salinity = SEAWATER_SALINITY;
|
|
|
|
|
break;
|
2020-01-05 00:06:28 +00:00
|
|
|
|
case DC_WATERTYPE:
|
2019-11-19 10:27:18 +00:00
|
|
|
|
combobox_salinity = dc_salinity;
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->waterTypeCombo, updateSalinityComboIndex(combobox_salinity));
|
2019-11-19 10:27:18 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-01-05 00:06:28 +00:00
|
|
|
|
// the index was set to -1 to indicate an unknown water type
|
|
|
|
|
combobox_salinity = 0;
|
2019-11-19 10:27:18 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Save and display the new salinity value
|
2020-01-05 00:06:28 +00:00
|
|
|
|
if (combobox_salinity)
|
2020-05-04 13:54:58 +00:00
|
|
|
|
ui->salinityText->setText(get_salinity_string(combobox_salinity));
|
2020-01-05 00:06:28 +00:00
|
|
|
|
else
|
|
|
|
|
ui->salinityText->clear();
|
2019-11-19 17:16:45 +00:00
|
|
|
|
divesEdited(Command::editWaterTypeUser(combobox_salinity, false));
|
2023-03-29 15:49:55 +00:00
|
|
|
|
// If choosed salinity differs from dive->salinity (if it has one), show warning
|
|
|
|
|
if (dc_salinity == 0 || dc_salinity == combobox_salinity)
|
2019-11-19 10:27:18 +00:00
|
|
|
|
ui->salinityOverWrittenIcon->setVisible(false);
|
|
|
|
|
else
|
|
|
|
|
ui->salinityOverWrittenIcon->setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 09:51:20 +00:00
|
|
|
|
void TabDiveInformation::cylinderChanged(dive *d)
|
|
|
|
|
{
|
|
|
|
|
// If this isn't the current dive, do nothing
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (parent.currentDive != d)
|
2020-05-05 09:51:20 +00:00
|
|
|
|
return;
|
|
|
|
|
updateProfile();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2019-11-19 10:27:18 +00:00
|
|
|
|
int salinity_value;
|
|
|
|
|
|
2019-04-26 08:03:32 +00:00
|
|
|
|
// If the current dive is not in list of changed dives, do nothing
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (!parent.includesCurrentDive(dives))
|
2019-04-26 08:03:32 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2022-09-17 14:21:17 +00:00
|
|
|
|
dive *currentDive = parent.currentDive;
|
2019-11-10 21:09:19 +00:00
|
|
|
|
if (field.visibility)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->visibility->setCurrentStars(currentDive->visibility);
|
2019-11-28 19:04:52 +00:00
|
|
|
|
if (field.wavesize)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->wavesize->setCurrentStars(currentDive->wavesize);
|
2019-11-28 19:04:52 +00:00
|
|
|
|
if (field.current)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->current->setCurrentStars(currentDive->current);
|
2019-11-28 19:04:52 +00:00
|
|
|
|
if (field.surge)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->surge->setCurrentStars(currentDive->surge);
|
2019-11-28 19:04:52 +00:00
|
|
|
|
if (field.chill)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->chill->setCurrentStars(currentDive->chill);
|
2021-01-27 22:41:51 +00:00
|
|
|
|
if (field.mode)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
updateMode();
|
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)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->airtemp->setText(get_temperature_string(currentDive->airtemp, true));
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.water_temp)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->watertemp->setText(get_temperature_string(currentDive->watertemp, true));
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.atm_press)
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->atmPressVal->setText(QString::number(currentDive->surface_pressure.mbar));
|
2019-10-13 10:44:39 +00:00
|
|
|
|
if (field.salinity)
|
2019-11-19 10:27:18 +00:00
|
|
|
|
checkDcSalinityOverWritten();
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (currentDive->user_salinity)
|
|
|
|
|
salinity_value = currentDive->user_salinity;
|
2019-11-19 10:27:18 +00:00
|
|
|
|
else
|
2022-09-17 14:21:17 +00:00
|
|
|
|
salinity_value = currentDive->salinity;
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->waterTypeCombo, updateSalinityComboIndex(salinity_value));
|
2020-05-24 09:52:01 +00:00
|
|
|
|
ui->salinityText->setText(QString("%L1g/ℓ").arg(salinity_value / 10.0));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
}
|
2019-04-30 10:42:33 +00:00
|
|
|
|
|
2019-11-10 21:09:19 +00:00
|
|
|
|
void TabDiveInformation::on_visibility_valueChanged(int value)
|
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (parent.currentDive)
|
2019-11-10 21:09:19 +00:00
|
|
|
|
divesEdited(Command::editVisibility(value, false));
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 19:04:52 +00:00
|
|
|
|
void TabDiveInformation::on_wavesize_valueChanged(int value)
|
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (parent.currentDive)
|
2019-11-28 19:04:52 +00:00
|
|
|
|
divesEdited(Command::editWaveSize(value, false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::on_current_valueChanged(int value)
|
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (parent.currentDive)
|
2019-11-28 19:04:52 +00:00
|
|
|
|
divesEdited(Command::editCurrent(value, false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::on_surge_valueChanged(int value)
|
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (parent.currentDive)
|
2019-11-28 19:04:52 +00:00
|
|
|
|
divesEdited(Command::editSurge(value, false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::on_chill_valueChanged(int value)
|
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (parent.currentDive)
|
2019-11-28 19:04:52 +00:00
|
|
|
|
divesEdited(Command::editChill(value, false));
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 14:21:17 +00:00
|
|
|
|
void TabDiveInformation::updateMode()
|
2019-11-10 21:09:19 +00:00
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
divecomputer *currentDC = parent.getCurrentDC();
|
|
|
|
|
if (currentDC)
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->diveType, currentDC->divemode);
|
2019-11-10 21:09:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::diveModeChanged(int index)
|
|
|
|
|
{
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (parent.currentDive)
|
|
|
|
|
divesEdited(Command::editMode(parent.currentDC, (enum divemode_t)index, false));
|
2019-11-10 21:09:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 09:47:12 +00:00
|
|
|
|
void TabDiveInformation::on_airtemp_editingFinished()
|
|
|
|
|
{
|
|
|
|
|
// If the field wasn't modified by the user, don't post a new undo command.
|
|
|
|
|
// Owing to rounding errors, this might lead to undo commands that have
|
|
|
|
|
// no user visible effects. These can be very confusing.
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (ui->airtemp->isModified() && parent.currentDive)
|
2019-11-11 09:47:12 +00:00
|
|
|
|
divesEdited(Command::editAirTemp(parseTemperatureToMkelvin(ui->airtemp->text()), false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabDiveInformation::on_watertemp_editingFinished()
|
|
|
|
|
{
|
|
|
|
|
// If the field wasn't modified by the user, don't post a new undo command.
|
|
|
|
|
// Owing to rounding errors, this might lead to undo commands that have
|
|
|
|
|
// no user visible effects. These can be very confusing.
|
2022-09-17 14:21:17 +00:00
|
|
|
|
if (ui->watertemp->isModified() && parent.currentDive)
|
2019-11-11 09:47:12 +00:00
|
|
|
|
divesEdited(Command::editWaterTemp(parseTemperatureToMkelvin(ui->watertemp->text()), false));
|
|
|
|
|
}
|
2020-01-05 00:05:31 +00:00
|
|
|
|
|
2020-05-24 09:59:35 +00:00
|
|
|
|
void TabDiveInformation::on_atmPressType_currentIndexChanged(int index)
|
|
|
|
|
{
|
2020-01-05 00:05:31 +00:00
|
|
|
|
Q_UNUSED(index)
|
|
|
|
|
updateTextBox(COMBO_CHANGED);
|
|
|
|
|
}
|
2019-04-30 10:42:33 +00:00
|
|
|
|
|
2020-05-24 09:59:35 +00:00
|
|
|
|
void TabDiveInformation::on_atmPressVal_editingFinished()
|
|
|
|
|
{
|
|
|
|
|
updateTextBox(TEXT_EDITED);
|
|
|
|
|
}
|
2019-04-30 10:42:33 +00:00
|
|
|
|
|
|
|
|
|
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.
|
2022-09-17 14:21:17 +00:00
|
|
|
|
dive *currentDive = parent.currentDive;
|
|
|
|
|
if (currentDive) {
|
2019-04-30 10:42:33 +00:00
|
|
|
|
switch (ui->atmPressType->currentIndex()) {
|
2019-11-11 06:19:05 +00:00
|
|
|
|
case 0: // If atm pressure in mbar has been selected:
|
2019-04-30 10:42:33 +00:00
|
|
|
|
if (event == TEXT_EDITED) // this is only triggered by on_atmPressVal_editingFinished()
|
|
|
|
|
atmpress.mbar = ui->atmPressVal->text().toInt(); // use the specified mbar pressure
|
2019-11-11 06:19:05 +00:00
|
|
|
|
else // if no pressure has been typed, then show existing dive pressure
|
2022-09-17 14:21:17 +00:00
|
|
|
|
ui->atmPressVal->setText(QString::number(currentDive->surface_pressure.mbar));
|
2019-04-30 10:42:33 +00:00
|
|
|
|
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)
|
2020-01-05 00:04:36 +00:00
|
|
|
|
ui->atmPressVal->setText(QString::number(atmpress.mbar));
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->atmPressType, 0); // reset combobox to mbar
|
2019-04-30 10:42:33 +00:00
|
|
|
|
} else { // i.e. event == COMBO_CHANGED, that is, "m" or "ft" was selected from combobox
|
2019-11-11 06:19:05 +00:00
|
|
|
|
// 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);
|
|
|
|
|
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)));
|
|
|
|
|
}
|
2019-04-30 10:42:33 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2: // i.e. event = COMBO_CHANGED, that is, the option "Use dc" was selected from combobox
|
2022-09-17 14:21:17 +00:00
|
|
|
|
atmpress = calculate_surface_pressure(currentDive); // re-calculate air pressure from dc data
|
2019-04-30 10:42:33 +00:00
|
|
|
|
ui->atmPressVal->setText(QString::number(atmpress.mbar)); // display it in text box
|
2024-01-16 17:11:02 +00:00
|
|
|
|
setIndexNoSignal(ui->atmPressType, 0); // reset combobox to mbar
|
2019-04-30 10:42:33 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
atmpress.mbar = 1013; // This line should never execute
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (atmpress.mbar)
|
2019-11-10 21:09:19 +00:00
|
|
|
|
divesEdited(Command::editAtmPress(atmpress.mbar, false)); // and save the pressure for undo
|
2019-04-30 10:42:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|