| 
									
										
										
										
											2013-04-13 20:44:02 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * maintab.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * classes for the "notebook" area of the main window of Subsurface | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-04-07 15:20:43 -07:00
										 |  |  | #include "maintab.h"
 | 
					
						
							|  |  |  | #include "ui_maintab.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | #include "addcylinderdialog.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-01 15:37:41 -07:00
										 |  |  | #include "addweightsystemdialog.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:36:37 -07:00
										 |  |  | #include "../helpers.h"
 | 
					
						
							|  |  |  | #include "../statistics.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QLabel>
 | 
					
						
							| 
									
										
										
										
											2013-04-07 15:20:43 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | MainTab::MainTab(QWidget *parent) : QTabWidget(parent), | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 				    ui(new Ui::MainTab()), | 
					
						
							|  |  |  | 				    weightModel(new WeightModel()), | 
					
						
							|  |  |  | 				    cylindersModel(new CylindersModel()) | 
					
						
							| 
									
										
										
										
											2013-04-07 15:20:43 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 	ui->cylinders->setModel(cylindersModel); | 
					
						
							|  |  |  | 	ui->weights->setModel(weightModel); | 
					
						
							| 
									
										
										
										
											2013-05-09 08:32:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* example of where code is more concise than Qt designer */ | 
					
						
							|  |  |  | 	QList<QObject *> infoTabWidgets = ui->infoTab->children(); | 
					
						
							|  |  |  | 	Q_FOREACH( QObject* obj, infoTabWidgets ){ | 
					
						
							|  |  |  | 		QLabel* label = qobject_cast<QLabel *>(obj); | 
					
						
							|  |  |  | 		if (label) | 
					
						
							|  |  |  | 			label->setAlignment(Qt::AlignHCenter); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-10 23:56:05 +01:00
										 |  |  | 	QList<QObject *> statisticsTabWidgets = ui->statisticsTab->children(); | 
					
						
							|  |  |  | 	Q_FOREACH( QObject* obj, statisticsTabWidgets ){ | 
					
						
							|  |  |  | 		QLabel* label = qobject_cast<QLabel *>(obj); | 
					
						
							|  |  |  | 		if (label) | 
					
						
							|  |  |  | 			label->setAlignment(Qt::AlignHCenter); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainTab::clearEquipment() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainTab::clearInfo() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-03 08:19:00 +01:00
										 |  |  | 	ui->sacText->setText(QString()); | 
					
						
							|  |  |  | 	ui->otuText->setText(QString()); | 
					
						
							|  |  |  | 	ui->oxygenHeliumText->setText(QString()); | 
					
						
							|  |  |  | 	ui->gasUsedText->setText(QString()); | 
					
						
							|  |  |  | 	ui->dateText->setText(QString()); | 
					
						
							|  |  |  | 	ui->diveTimeText->setText(QString()); | 
					
						
							|  |  |  | 	ui->surfaceIntervalText->setText(QString()); | 
					
						
							|  |  |  | 	ui->maximumDepthText->setText(QString()); | 
					
						
							|  |  |  | 	ui->averageDepthText->setText(QString()); | 
					
						
							|  |  |  | 	ui->visibilityText->setText(QString()); | 
					
						
							|  |  |  | 	ui->waterTemperatureText->setText(QString()); | 
					
						
							|  |  |  | 	ui->airTemperatureText->setText(QString()); | 
					
						
							|  |  |  | 	ui->airPressureText->setText(QString()); | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainTab::clearStats() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-06 08:30:40 +01:00
										 |  |  | 	ui->maximumDepthAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->minimumDepthAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->averageDepthAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->maximumSacAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->minimumSacAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->averageSacAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->divesAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->maximumTemperatureAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->minimumTemperatureAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->averageTemperatureAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->totalTimeAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->averageTimeAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->longestAllText->setText(QString()); | 
					
						
							|  |  |  | 	ui->shortestAllText->setText(QString()); | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 10:16:16 -07:00
										 |  |  | #define UPDATE_TEXT(d, field)				\
 | 
					
						
							|  |  |  | 	if (!d || !d->field)				\ | 
					
						
							|  |  |  | 		ui->field->setText("");			\ | 
					
						
							|  |  |  | 	else						\ | 
					
						
							|  |  |  | 		ui->field->setText(d->field) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:36:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 13:23:14 -03:00
										 |  |  | void MainTab::updateDiveInfo(int dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// So, this is what happens now:
 | 
					
						
							|  |  |  | 	// Every tab should be populated from this method,
 | 
					
						
							|  |  |  | 	// it will be called whenever a new dive is selected
 | 
					
						
							|  |  |  | 	// I'm already populating the 'notes' box
 | 
					
						
							|  |  |  | 	// to show how it can be done.
 | 
					
						
							|  |  |  | 	// If you are unsure what's the name of anything,
 | 
					
						
							|  |  |  | 	// open the file maintab.ui on the designer
 | 
					
						
							|  |  |  | 	// click on the item and check its objectName,
 | 
					
						
							|  |  |  | 	// the access is ui->objectName from here on.
 | 
					
						
							| 
									
										
										
										
											2013-05-06 20:36:37 -07:00
										 |  |  | 	volume_t sacVal; | 
					
						
							| 
									
										
										
										
											2013-05-06 13:23:14 -03:00
										 |  |  | 	struct dive *d = get_dive(dive); | 
					
						
							| 
									
										
										
										
											2013-05-06 10:16:16 -07:00
										 |  |  | 	UPDATE_TEXT(d, notes); | 
					
						
							|  |  |  | 	UPDATE_TEXT(d, location); | 
					
						
							|  |  |  | 	UPDATE_TEXT(d, suit); | 
					
						
							|  |  |  | 	UPDATE_TEXT(d, divemaster); | 
					
						
							|  |  |  | 	UPDATE_TEXT(d, buddy); | 
					
						
							| 
									
										
										
										
											2013-05-10 23:56:05 +01:00
										 |  |  | 	/* infoTab */ | 
					
						
							| 
									
										
										
										
											2013-05-08 12:08:00 -07:00
										 |  |  | 	if (d) { | 
					
						
							| 
									
										
										
										
											2013-05-06 10:16:16 -07:00
										 |  |  | 		ui->rating->setCurrentStars(d->rating); | 
					
						
							| 
									
										
										
										
											2013-05-08 12:08:00 -07:00
										 |  |  | 		ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE)); | 
					
						
							|  |  |  | 		ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE)); | 
					
						
							|  |  |  | 		ui->otuText->setText(QString("%1").arg(d->otu)); | 
					
						
							|  |  |  | 		ui->waterTemperatureText->setText(get_temperature_string(d->watertemp, TRUE)); | 
					
						
							|  |  |  | 		ui->airTemperatureText->setText(get_temperature_string(d->airtemp, TRUE)); | 
					
						
							| 
									
										
										
										
											2013-05-06 20:36:37 -07:00
										 |  |  | 		ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE)); | 
					
						
							| 
									
										
										
										
											2013-05-08 12:08:00 -07:00
										 |  |  | 		if ((sacVal.mliter = d->sac) > 0) | 
					
						
							|  |  |  | 			ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min")); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			ui->sacText->setText(QString()); | 
					
						
							|  |  |  | 		if (d->surface_pressure.mbar) | 
					
						
							|  |  |  | 			/* this is ALWAYS displayed in mbar */ | 
					
						
							|  |  |  | 			ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			ui->airPressureText->setText(QString()); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ui->rating->setCurrentStars(0); | 
					
						
							|  |  |  | 		ui->sacText->setText(QString()); | 
					
						
							|  |  |  | 		ui->otuText->setText(QString()); | 
					
						
							|  |  |  | 		ui->oxygenHeliumText->setText(QString()); | 
					
						
							|  |  |  | 		ui->dateText->setText(QString()); | 
					
						
							|  |  |  | 		ui->diveTimeText->setText(QString()); | 
					
						
							|  |  |  | 		ui->surfaceIntervalText->setText(QString()); | 
					
						
							|  |  |  | 		ui->maximumDepthText->setText(QString()); | 
					
						
							|  |  |  | 		ui->averageDepthText->setText(QString()); | 
					
						
							|  |  |  | 		ui->visibilityText->setText(QString()); | 
					
						
							|  |  |  | 		ui->waterTemperatureText->setText(QString()); | 
					
						
							|  |  |  | 		ui->airTemperatureText->setText(QString()); | 
					
						
							|  |  |  | 		ui->gasUsedText->setText(QString()); | 
					
						
							|  |  |  | 		ui->airPressureText->setText(QString()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-10 23:56:05 +01:00
										 |  |  | 	/* statisticsTab*/ | 
					
						
							|  |  |  | 	/* we can access the stats_selection struct but how to we ensure the relevant dives are selected
 | 
					
						
							|  |  |  | 	 * if we don't use the gtk widget to drive this? | 
					
						
							|  |  |  | 	 * Maybe call process_selected_dives? Or re-write to query our Qt list view. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-05-13 15:28:17 -03:00
										 |  |  | // 	qDebug("max temp %u",stats_selection.max_temp);
 | 
					
						
							|  |  |  | // 	qDebug("min temp %u",stats_selection.min_temp);
 | 
					
						
							| 
									
										
										
										
											2013-05-06 13:23:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | void MainTab::on_addCylinder_clicked() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-01 14:49:17 -07:00
										 |  |  | 	if (cylindersModel->rowCount() >= MAX_CYLINDERS) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 	AddCylinderDialog dialog(this); | 
					
						
							|  |  |  | 	cylinder_t *newCylinder = (cylinder_t*) malloc(sizeof(cylinder_t)); | 
					
						
							|  |  |  | 	newCylinder->type.description = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dialog.setCylinder(newCylinder); | 
					
						
							|  |  |  | 	int result = dialog.exec(); | 
					
						
							|  |  |  | 	if (result == QDialog::Rejected){ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dialog.updateCylinder(); | 
					
						
							|  |  |  | 	cylindersModel->add(newCylinder); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainTab::on_editCylinder_clicked() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainTab::on_delCylinder_clicked() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 14:30:34 -07:00
										 |  |  | void MainTab::on_addWeight_clicked() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-01 14:49:17 -07:00
										 |  |  | 	if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 15:37:41 -07:00
										 |  |  | 	AddWeightsystemDialog dialog(this); | 
					
						
							| 
									
										
										
										
											2013-05-01 16:23:20 -07:00
										 |  |  | 	weightsystem_t newWeightsystem; | 
					
						
							|  |  |  | 	newWeightsystem.description = ""; | 
					
						
							|  |  |  | 	newWeightsystem.weight.grams = 0; | 
					
						
							| 
									
										
										
										
											2013-05-01 15:37:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 16:23:20 -07:00
										 |  |  | 	dialog.setWeightsystem(&newWeightsystem); | 
					
						
							| 
									
										
										
										
											2013-05-01 15:37:41 -07:00
										 |  |  | 	int result = dialog.exec(); | 
					
						
							|  |  |  | 	if (result == QDialog::Rejected) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dialog.updateWeightsystem(); | 
					
						
							| 
									
										
										
										
											2013-05-01 16:23:20 -07:00
										 |  |  | 	weightModel->add(&newWeightsystem); | 
					
						
							| 
									
										
										
										
											2013-05-01 14:30:34 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainTab::on_editWeight_clicked() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainTab::on_delWeight_clicked() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | void MainTab::reload() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	cylindersModel->update(); | 
					
						
							| 
									
										
										
										
											2013-04-07 15:20:43 -07:00
										 |  |  | } |