| 
									
										
										
										
											2017-04-27 20:26:05 +02:00
										 |  |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | #include "TabDiveInformation.h"
 | 
					
						
							|  |  |  |  | #include "ui_TabDiveInformation.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | #include "desktop-widgets/mainwindow.h" // TODO: Only used temporarilly for edit mode changes
 | 
					
						
							|  |  |  |  | #include "profile-widget/profilewidget2.h"
 | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | #include "../tagwidget.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-13 15:08:40 +01:00
										 |  |  |  | #include "commands/command.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | #include "core/units.h"
 | 
					
						
							|  |  |  |  | #include "core/dive.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-07 14:00:16 +02:00
										 |  |  |  | #include "core/qthelper.h"
 | 
					
						
							|  |  |  |  | #include "core/statistics.h"
 | 
					
						
							|  |  |  |  | #include "core/display.h"
 | 
					
						
							| 
									
										
										
										
											2019-07-15 23:44:39 +02:00
										 |  |  |  | #include "core/divelist.h"
 | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | #define COMBO_CHANGED 0
 | 
					
						
							|  |  |  |  | #define TEXT_EDITED 1
 | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | #define CSS_SET_HEADING_BLUE "QLabel { color: mediumblue;} "
 | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation()) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2019-04-26 10:03:32 +02:00
										 |  |  |  | 	connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveInformation::divesChanged); | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | 	QStringList atmPressTypes { "mbar", get_depth_unit() ,"use dc"}; | 
					
						
							|  |  |  |  | 	ui->atmPressType->insertItems(0, atmPressTypes); | 
					
						
							|  |  |  |  | 	pressTypeIndex = 0; | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08: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))); | 
					
						
							|  |  |  |  | 	QString CSSSetSmallLabel = "QLabel { color: mediumblue; font-size: " +                        /* // Using label height ... */ | 
					
						
							|  |  |  |  | 		QString::number((int)(0.5 + ui->diveHeadingLabel->geometry().height() * 0.66)) + "px;}"; // .. set CSS font size of star widget subscripts
 | 
					
						
							|  |  |  |  | 	ui->scrollAreaWidgetContents_3->setStyleSheet("QGroupBox::title { color: mediumblue;} "); | 
					
						
							|  |  |  |  | 	ui->diveHeadingLabel->setStyleSheet(CSS_SET_HEADING_BLUE); | 
					
						
							|  |  |  |  | 	ui->gasHeadingLabel->setStyleSheet(CSS_SET_HEADING_BLUE); | 
					
						
							|  |  |  |  | 	ui->environmentHeadingLabel->setStyleSheet(CSS_SET_HEADING_BLUE); | 
					
						
							|  |  |  |  | 	ui->groupBox_visibility->setStyleSheet(CSSSetSmallLabel); | 
					
						
							| 
									
										
										
										
											2019-11-28 12:35:39 +02:00
										 |  |  |  | 	ui->groupBox_current->setStyleSheet(CSSSetSmallLabel); | 
					
						
							|  |  |  |  | 	ui->groupBox_wavesize->setStyleSheet(CSSSetSmallLabel); | 
					
						
							|  |  |  |  | 	ui->groupBox_surge->setStyleSheet(CSSSetSmallLabel); | 
					
						
							|  |  |  |  | 	ui->groupBox_chill->setStyleSheet(CSSSetSmallLabel); | 
					
						
							|  |  |  |  | 	if (!prefs.extraEnvironmentalDefault) // if extraEnvironmental preference is turned off
 | 
					
						
							|  |  |  |  | 		showCurrentWidget(false, 0);  // Show current star widget at lefthand side
 | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08: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(); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02: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 11:47:12 +02:00
										 |  |  |  | 	ui->watertemp->clear(); | 
					
						
							|  |  |  |  | 	ui->airtemp->clear(); | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | 	ui->atmPressVal->clear(); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 	ui->salinityText->clear(); | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 	ui->waterTypeText->clear(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 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 19:21:30 +02:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-26 10:03:32 +02:00
										 |  |  |  | // Update fields that depend on the dive profile
 | 
					
						
							|  |  |  |  | void TabDiveInformation::updateProfile() | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-26 09:46:36 +02: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 19:21:30 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-04 18:44:57 +02:00
										 |  |  |  | 	volume_t *gases = get_gas_used(current_dive); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 	QString volumes; | 
					
						
							| 
									
										
										
										
											2019-08-04 18:44:57 +02:00
										 |  |  |  | 	std::vector<int> mean(current_dive->cylinders.nr), duration(current_dive->cylinders.nr); | 
					
						
							| 
									
										
										
										
											2019-06-27 07:52:15 +02:00
										 |  |  |  | 	per_cylinder_mean_depth(current_dive, select_dc(current_dive), &mean[0], &duration[0]); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 	volume_t sac; | 
					
						
							|  |  |  |  | 	QString gaslist, SACs, separator; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-04 18:44:57 +02:00
										 |  |  |  | 	for (int i = 0; i < current_dive->cylinders.nr; i++) { | 
					
						
							| 
									
										
										
										
											2019-04-26 09:46:36 +02:00
										 |  |  |  | 		if (!is_cylinder_used(current_dive, i)) | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 			continue; | 
					
						
							|  |  |  |  | 		gaslist.append(separator); volumes.append(separator); SACs.append(separator); | 
					
						
							|  |  |  |  | 		separator = "\n"; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-04 22:13:49 +02:00
										 |  |  |  | 		gaslist.append(gasname(get_cylinder(current_dive, i)->gasmix)); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 		if (!gases[i].mliter) | 
					
						
							|  |  |  |  | 			continue; | 
					
						
							|  |  |  |  | 		volumes.append(get_volume_string(gases[i], true)); | 
					
						
							|  |  |  |  | 		if (duration[i]) { | 
					
						
							| 
									
										
										
										
											2019-04-26 09:46:36 +02:00
										 |  |  |  | 			sac.mliter = lrint(gases[i].mliter / (depth_to_atm(mean[i], current_dive) * duration[i] / 60)); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 			SACs.append(get_volume_string(sac, true).append(tr("/min"))); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-06-27 07:42:09 +02:00
										 |  |  |  | 	free(gases); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 	ui->gasUsedText->setText(volumes); | 
					
						
							|  |  |  |  | 	ui->oxygenHeliumText->setText(gaslist); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-26 09:46:36 +02: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 19:21:30 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-04 19:49:43 +02:00
										 |  |  |  | 	ui->sacText->setText(current_dive->cylinders.nr > 0 && mean[0] ? SACs : QString()); | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (current_dive->surface_pressure.mbar == 0) { | 
					
						
							|  |  |  |  | 		ui->atmPressVal->clear();			// If no atm pressure for dive then clear text box
 | 
					
						
							| 
									
										
										
										
											2019-05-15 07:42:14 -07:00
										 |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02: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 10:03:32 +02:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // Update fields that depend on start of dive
 | 
					
						
							|  |  |  |  | void TabDiveInformation::updateWhen() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-26 09:46:36 +02:00
										 |  |  |  | 	timestamp_t surface_interval = get_surface_interval(current_dive->when); | 
					
						
							| 
									
										
										
										
											2018-10-06 09:21:27 +02:00
										 |  |  |  | 	if (surface_interval >= 0) | 
					
						
							|  |  |  |  | 		ui->surfaceIntervalText->setText(get_dive_surfint_string(surface_interval, tr("d"), tr("h"), tr("min"))); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 	else | 
					
						
							|  |  |  |  | 		ui->surfaceIntervalText->clear(); | 
					
						
							| 
									
										
										
										
											2019-04-26 10:03:32 +02:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-13 00:01:44 +02:00
										 |  |  |  | void TabDiveInformation::updateSalinity() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 	if (current_dive->salinity) {                 // Set up the salinity string:
 | 
					
						
							| 
									
										
										
										
											2019-10-13 00:01:44 +02:00
										 |  |  |  | 		ui->salinityText->setText(QString("%1g/ℓ").arg(current_dive->salinity / 10.0)); | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 		if (current_dive->salinity < 10050)   // Set water type indicator:
 | 
					
						
							|  |  |  |  | 			ui->waterTypeText->setText(tr("Fresh")); | 
					
						
							|  |  |  |  | 		else if (current_dive->salinity < 10190) | 
					
						
							|  |  |  |  | 			ui->waterTypeText->setText(tr("Salty")); | 
					
						
							|  |  |  |  | 		else if (current_dive->salinity < 10210) // (EN13319 = 1.019 - 1.021 g/l)
 | 
					
						
							|  |  |  |  | 			ui->waterTypeText->setText(tr("EN13319")); | 
					
						
							|  |  |  |  | 		else ui->waterTypeText->setText(tr("Salt")); | 
					
						
							|  |  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2019-10-13 00:01:44 +02:00
										 |  |  |  | 		ui->salinityText->clear(); | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 		ui->waterTypeText->clear(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-13 00:01:44 +02:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-28 12:35:39 +02:00
										 |  |  |  | void TabDiveInformation::showCurrentWidget(bool show, int position) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 		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-04-26 10:03:32 +02:00
										 |  |  |  | void TabDiveInformation::updateData() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (!current_dive) { | 
					
						
							|  |  |  |  | 		clear(); | 
					
						
							|  |  |  |  | 		return; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	updateProfile(); | 
					
						
							|  |  |  |  | 	updateWhen(); | 
					
						
							| 
									
										
										
										
											2019-11-11 11:47:12 +02:00
										 |  |  |  | 	ui->watertemp->setText(get_temperature_string(current_dive->watertemp, true)); | 
					
						
							|  |  |  |  | 	ui->airtemp->setText(get_temperature_string(current_dive->airtemp, true)); | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | 	ui->atmPressType->setItemText(1, get_depth_unit());  // Check for changes in depth unit (imperial/metric)
 | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 	ui->atmPressType->setCurrentIndex(0);                // Set the atmospheric pressure combo box to mbar
 | 
					
						
							|  |  |  |  | 	updateMode(current_dive); | 
					
						
							|  |  |  |  | 	updateSalinity(); | 
					
						
							|  |  |  |  | 	ui->visibility->setCurrentStars(current_dive->visibility); | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  |  | 	ui->wavesize->setCurrentStars(current_dive->wavesize); | 
					
						
							|  |  |  |  | 	ui->current->setCurrentStars(current_dive->current); | 
					
						
							|  |  |  |  | 	ui->surge->setCurrentStars(current_dive->surge); | 
					
						
							|  |  |  |  | 	ui->chill->setCurrentStars(current_dive->chill); | 
					
						
							| 
									
										
										
										
											2019-11-28 12:35:39 +02: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 10:03:32 +02:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-26 10:03:32 +02:00
										 |  |  |  | // This function gets called if a field gets updated by an undo command.
 | 
					
						
							|  |  |  |  | // Refresh the corresponding UI field.
 | 
					
						
							| 
									
										
										
										
											2019-06-23 09:22:26 +02:00
										 |  |  |  | void TabDiveInformation::divesChanged(const QVector<dive *> &dives, DiveField field) | 
					
						
							| 
									
										
										
										
											2019-04-26 10:03:32 +02:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	// If the current dive is not in list of changed dives, do nothing
 | 
					
						
							|  |  |  |  | 	if (!current_dive || !dives.contains(current_dive)) | 
					
						
							|  |  |  |  | 		return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 	if (field.visibility) | 
					
						
							|  |  |  |  | 		ui->visibility->setCurrentStars(current_dive->visibility); | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  |  | 	if (field.wavesize) | 
					
						
							|  |  |  |  | 		ui->wavesize->setCurrentStars(current_dive->wavesize); | 
					
						
							|  |  |  |  | 	if (field.current) | 
					
						
							|  |  |  |  | 		ui->current->setCurrentStars(current_dive->current); | 
					
						
							|  |  |  |  | 	if (field.surge) | 
					
						
							|  |  |  |  | 		ui->surge->setCurrentStars(current_dive->surge); | 
					
						
							|  |  |  |  | 	if (field.chill) | 
					
						
							|  |  |  |  | 		ui->chill->setCurrentStars(current_dive->chill); | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 	if (field.mode) | 
					
						
							|  |  |  |  | 		updateMode(current_dive); | 
					
						
							| 
									
										
										
										
											2019-10-13 12:44:39 +02:00
										 |  |  |  | 	if (field.duration || field.depth || field.mode) | 
					
						
							| 
									
										
										
										
											2019-04-26 10:03:32 +02:00
										 |  |  |  | 		updateProfile(); | 
					
						
							| 
									
										
										
										
											2019-10-13 12:44:39 +02:00
										 |  |  |  | 	if (field.air_temp) | 
					
						
							| 
									
										
										
										
											2019-11-11 11:47:12 +02:00
										 |  |  |  | 		ui->airtemp->setText(get_temperature_string(current_dive->airtemp, true)); | 
					
						
							| 
									
										
										
										
											2019-10-13 12:44:39 +02:00
										 |  |  |  | 	if (field.water_temp) | 
					
						
							| 
									
										
										
										
											2019-11-11 11:47:12 +02:00
										 |  |  |  | 		ui->watertemp->setText(get_temperature_string(current_dive->watertemp, true)); | 
					
						
							| 
									
										
										
										
											2019-10-13 12:44:39 +02:00
										 |  |  |  | 	if (field.atm_press) | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | 		ui->atmPressVal->setText(ui->atmPressVal->text().sprintf("%d",current_dive->surface_pressure.mbar)); | 
					
						
							| 
									
										
										
										
											2019-10-13 12:44:39 +02:00
										 |  |  |  | 	if (field.salinity) | 
					
						
							| 
									
										
										
										
											2019-10-13 00:01:44 +02:00
										 |  |  |  | 		updateSalinity(); | 
					
						
							| 
									
										
										
										
											2017-04-04 19:21:30 +02:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void TabDiveInformation::on_visibility_valueChanged(int value) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (current_dive) | 
					
						
							|  |  |  |  | 		divesEdited(Command::editVisibility(value, false)); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  |  | void TabDiveInformation::on_wavesize_valueChanged(int value) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (current_dive) | 
					
						
							|  |  |  |  | 		divesEdited(Command::editWaveSize(value, false)); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TabDiveInformation::on_current_valueChanged(int value) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (current_dive) | 
					
						
							|  |  |  |  | 		divesEdited(Command::editCurrent(value, false)); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TabDiveInformation::on_surge_valueChanged(int value) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (current_dive) | 
					
						
							|  |  |  |  | 		divesEdited(Command::editSurge(value, false)); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TabDiveInformation::on_chill_valueChanged(int value) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (current_dive) | 
					
						
							|  |  |  |  | 		divesEdited(Command::editChill(value, false)); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | void TabDiveInformation::updateMode(struct dive *d) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	ui->diveType->setCurrentIndex(get_dive_dc(d, dc_number)->divemode); | 
					
						
							|  |  |  |  | 	MainWindow::instance()->graphics->replot(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TabDiveInformation::diveModeChanged(int index) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (current_dive) | 
					
						
							|  |  |  |  | 		divesEdited(Command::editMode(dc_number, (enum divemode_t)index, false)); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-11 11:47:12 +02: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.
 | 
					
						
							|  |  |  |  | 	if (ui->airtemp->isModified() && current_dive) | 
					
						
							|  |  |  |  | 		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.
 | 
					
						
							|  |  |  |  | 	if (ui->watertemp->isModified() && current_dive) | 
					
						
							|  |  |  |  | 		divesEdited(Command::editWaterTemp(parseTemperatureToMkelvin(ui->watertemp->text()), false)); | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02: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()) { | 
					
						
							| 
									
										
										
										
											2019-11-11 08:19:05 +02:00
										 |  |  |  | 		case 0:		// If atm pressure in mbar has been selected:
 | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02: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 08:19:05 +02:00
										 |  |  |  | 			else                              // if no pressure has been typed, then show existing dive pressure
 | 
					
						
							|  |  |  |  | 				ui->atmPressVal->setText(QString::number(current_dive->surface_pressure.mbar)); | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02: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)
 | 
					
						
							|  |  |  |  | 				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
 | 
					
						
							| 
									
										
										
										
											2019-11-11 08:19:05 +02: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 12:42:33 +02:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 			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) | 
					
						
							| 
									
										
										
										
											2019-11-10 13:09:19 -08:00
										 |  |  |  | 			divesEdited(Command::editAtmPress(atmpress.mbar, false));      // and save the pressure for undo
 | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 |