2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* maintab.cpp
|
|
|
|
*
|
|
|
|
* classes for the "notebook" area of the main window of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2013-04-07 22:20:43 +00:00
|
|
|
#include "maintab.h"
|
|
|
|
#include "ui_maintab.h"
|
2013-05-19 03:09:36 +00:00
|
|
|
#include "mainwindow.h"
|
2013-05-07 03:36:37 +00:00
|
|
|
#include "../helpers.h"
|
|
|
|
#include "../statistics.h"
|
2013-09-17 19:50:15 +00:00
|
|
|
#include "../info.h"
|
2013-05-19 03:09:36 +00:00
|
|
|
#include "divelistview.h"
|
2013-05-22 17:11:49 +00:00
|
|
|
#include "modeldelegates.h"
|
2013-06-05 02:39:40 +00:00
|
|
|
#include "globe.h"
|
2013-08-13 13:49:59 +00:00
|
|
|
#include "completionmodels.h"
|
2013-09-19 04:33:39 +00:00
|
|
|
#include "diveplanner.h"
|
2013-04-13 13:17:59 +00:00
|
|
|
|
|
|
|
#include <QLabel>
|
2013-08-13 13:49:59 +00:00
|
|
|
#include <QCompleter>
|
2013-05-18 23:42:59 +00:00
|
|
|
#include <QDebug>
|
2013-06-14 16:17:46 +00:00
|
|
|
#include <QSet>
|
2013-09-02 19:21:08 +00:00
|
|
|
#include <QTableView>
|
2013-06-16 17:36:23 +00:00
|
|
|
#include <QSettings>
|
2013-08-16 18:38:18 +00:00
|
|
|
#include <QPalette>
|
2013-04-07 22:20:43 +00:00
|
|
|
|
|
|
|
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
2013-04-13 13:17:59 +00:00
|
|
|
ui(new Ui::MainTab()),
|
|
|
|
weightModel(new WeightModel()),
|
2013-05-18 23:42:59 +00:00
|
|
|
cylindersModel(new CylindersModel()),
|
2013-06-14 16:17:46 +00:00
|
|
|
editMode(NONE)
|
2013-04-07 22:20:43 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2013-04-13 13:17:59 +00:00
|
|
|
ui->cylinders->setModel(cylindersModel);
|
|
|
|
ui->weights->setModel(weightModel);
|
2013-05-18 23:42:59 +00:00
|
|
|
ui->diveNotesMessage->hide();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->diveEquipmentMessage->hide();
|
2013-09-19 00:56:53 +00:00
|
|
|
ui->notesButtonBox->hide();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->equipmentButtonBox->hide();
|
2013-05-18 23:42:59 +00:00
|
|
|
ui->diveNotesMessage->setCloseButtonVisible(false);
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->diveEquipmentMessage->setCloseButtonVisible(false);
|
2013-06-07 10:23:48 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
setDocumentMode(false);
|
|
|
|
#else
|
|
|
|
setDocumentMode(true);
|
|
|
|
#endif
|
2013-05-20 00:38:20 +00:00
|
|
|
// we start out with the fields read-only; once things are
|
|
|
|
// filled from a dive, they are made writeable
|
2013-09-19 00:56:53 +00:00
|
|
|
setEnabled(false);
|
2013-05-19 14:45:01 +00:00
|
|
|
|
|
|
|
ui->location->installEventFilter(this);
|
2013-09-17 19:50:15 +00:00
|
|
|
ui->coordinates->installEventFilter(this);
|
2013-05-19 14:45:01 +00:00
|
|
|
ui->divemaster->installEventFilter(this);
|
|
|
|
ui->buddy->installEventFilter(this);
|
|
|
|
ui->suit->installEventFilter(this);
|
2013-08-13 11:34:04 +00:00
|
|
|
ui->notes->viewport()->installEventFilter(this);
|
2013-05-19 14:45:01 +00:00
|
|
|
ui->rating->installEventFilter(this);
|
2013-05-20 13:25:16 +00:00
|
|
|
ui->visibility->installEventFilter(this);
|
2013-05-09 07:32:27 +00:00
|
|
|
|
2013-05-10 22:56:05 +00:00
|
|
|
QList<QObject *> statisticsTabWidgets = ui->statisticsTab->children();
|
2013-05-19 16:00:57 +00:00
|
|
|
Q_FOREACH(QObject* obj, statisticsTabWidgets) {
|
2013-05-10 22:56:05 +00:00
|
|
|
QLabel* label = qobject_cast<QLabel *>(obj);
|
|
|
|
if (label)
|
|
|
|
label->setAlignment(Qt::AlignHCenter);
|
|
|
|
}
|
2013-09-02 19:21:08 +00:00
|
|
|
ui->cylinders->setTitle(tr("Cylinders"));
|
|
|
|
ui->cylinders->setBtnToolTip(tr("Add Cylinder"));
|
|
|
|
connect(ui->cylinders, SIGNAL(addButtonClicked()), this, SLOT(addCylinder_clicked()));
|
2013-05-22 12:17:18 +00:00
|
|
|
|
2013-09-02 19:21:08 +00:00
|
|
|
ui->weights->setTitle(tr("Weights"));
|
|
|
|
ui->weights->setBtnToolTip(tr("Add Weight System"));
|
|
|
|
connect(ui->weights, SIGNAL(addButtonClicked()), this, SLOT(addWeight_clicked()));
|
|
|
|
|
|
|
|
connect(ui->cylinders->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex)));
|
|
|
|
connect(ui->weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeigthWidget(QModelIndex)));
|
2013-09-19 00:56:53 +00:00
|
|
|
connect(ui->notesButtonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
|
|
|
|
connect(ui->notesButtonBox, SIGNAL(rejected()), this, SLOT(rejectChanges()));
|
2013-09-19 02:23:04 +00:00
|
|
|
connect(ui->equipmentButtonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
|
|
|
|
connect(ui->equipmentButtonBox, SIGNAL(rejected()), this, SLOT(rejectChanges()));
|
|
|
|
|
2013-09-02 19:21:08 +00:00
|
|
|
ui->cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
|
|
|
|
ui->weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
|
2013-08-13 13:49:59 +00:00
|
|
|
|
|
|
|
completers.buddy = new QCompleter(BuddyCompletionModel::instance(), ui->buddy);
|
|
|
|
completers.divemaster = new QCompleter(DiveMasterCompletionModel::instance(), ui->divemaster);
|
|
|
|
completers.location = new QCompleter(LocationCompletionModel::instance(), ui->location);
|
|
|
|
completers.suit = new QCompleter(SuitCompletionModel::instance(), ui->suit);
|
|
|
|
ui->buddy->setCompleter(completers.buddy);
|
|
|
|
ui->divemaster->setCompleter(completers.divemaster);
|
|
|
|
ui->location->setCompleter(completers.location);
|
|
|
|
ui->suit->setCompleter(completers.suit);
|
2013-06-27 12:33:43 +00:00
|
|
|
}
|
2013-05-22 12:17:18 +00:00
|
|
|
|
2013-09-19 04:33:39 +00:00
|
|
|
void MainTab::addDiveStarted()
|
|
|
|
{
|
|
|
|
enableEdition();
|
|
|
|
editMode = ADD;
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:34:04 +00:00
|
|
|
void MainTab::enableEdition()
|
|
|
|
{
|
2013-09-19 04:33:39 +00:00
|
|
|
if (selected_dive < 0 || editMode != NONE)
|
2013-08-13 11:34:04 +00:00
|
|
|
return;
|
|
|
|
|
2013-09-19 02:23:04 +00:00
|
|
|
mainWindow()->dive_list()->setEnabled(false);
|
2013-09-19 00:56:53 +00:00
|
|
|
// We may be editing one or more dives here. backup everything.
|
|
|
|
notesBackup.clear();
|
|
|
|
ui->notesButtonBox->show();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->equipmentButtonBox->show();
|
2013-09-19 00:56:53 +00:00
|
|
|
|
|
|
|
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
|
|
|
// we are editing trip location and notes
|
|
|
|
ui->diveNotesMessage->setText(tr("This trip is being edited. Select Save or Undo when ready."));
|
|
|
|
ui->diveNotesMessage->animatedShow();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->diveEquipmentMessage->setText(tr("This trip is being edited. Select Save or Undo when ready."));
|
|
|
|
ui->diveEquipmentMessage->animatedShow();
|
2013-09-19 00:56:53 +00:00
|
|
|
notesBackup[NULL].notes = ui->notes->toPlainText();
|
|
|
|
notesBackup[NULL].location = ui->location->text();
|
|
|
|
editMode = TRIP;
|
|
|
|
} else {
|
|
|
|
ui->diveNotesMessage->setText(tr("This dive is being edited. Select Save or Undo when ready."));
|
|
|
|
ui->diveNotesMessage->animatedShow();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->diveEquipmentMessage->setText(tr("This dive is being edited. Select Save or Undo when ready."));
|
|
|
|
ui->diveEquipmentMessage->animatedShow();
|
2013-09-19 00:56:53 +00:00
|
|
|
|
|
|
|
// We may be editing one or more dives here. backup everything.
|
|
|
|
struct dive *mydive;
|
|
|
|
for (int i = 0; i < dive_table.nr; i++) {
|
|
|
|
mydive = get_dive(i);
|
|
|
|
if (!mydive)
|
|
|
|
continue;
|
|
|
|
if (!mydive->selected)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
notesBackup[mydive].buddy = QString(mydive->buddy);
|
|
|
|
notesBackup[mydive].suit = QString(mydive->suit);
|
|
|
|
notesBackup[mydive].notes = QString(mydive->notes);
|
|
|
|
notesBackup[mydive].divemaster = QString(mydive->divemaster);
|
|
|
|
notesBackup[mydive].location = QString(mydive->location);
|
|
|
|
notesBackup[mydive].rating = mydive->rating;
|
|
|
|
notesBackup[mydive].visibility = mydive->visibility;
|
|
|
|
notesBackup[mydive].latitude = mydive->latitude;
|
|
|
|
notesBackup[mydive].longitude = mydive->longitude;
|
2013-09-19 16:37:44 +00:00
|
|
|
notesBackup[mydive].coordinates = ui->coordinates->text();
|
2013-09-19 00:56:53 +00:00
|
|
|
}
|
|
|
|
editMode = DIVE;
|
|
|
|
}
|
2013-08-13 11:34:04 +00:00
|
|
|
}
|
|
|
|
|
2013-05-19 14:45:01 +00:00
|
|
|
bool MainTab::eventFilter(QObject* object, QEvent* event)
|
|
|
|
{
|
2013-09-19 00:56:53 +00:00
|
|
|
if (isEnabled() && event->type() == QEvent::FocusIn && (object == ui->rating || object == ui->visibility)){
|
2013-09-19 01:38:38 +00:00
|
|
|
tabBar()->setTabIcon(currentIndex(), QIcon(":warning"));
|
2013-08-13 11:34:04 +00:00
|
|
|
enableEdition();
|
|
|
|
}
|
|
|
|
|
2013-09-19 00:56:53 +00:00
|
|
|
if (isEnabled() && event->type() == QEvent::MouseButtonPress ) {
|
2013-09-19 01:38:38 +00:00
|
|
|
tabBar()->setTabIcon(currentIndex(), QIcon(":warning"));
|
2013-08-13 11:34:04 +00:00
|
|
|
enableEdition();
|
2013-05-19 14:45:01 +00:00
|
|
|
}
|
2013-08-13 11:34:04 +00:00
|
|
|
return false; // don't "eat" the event.
|
2013-05-19 14:45:01 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
void MainTab::clearEquipment()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::clearInfo()
|
|
|
|
{
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->sacText->clear();
|
|
|
|
ui->otuText->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();
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::clearStats()
|
|
|
|
{
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->depthLimits->clear();
|
|
|
|
ui->sacLimits->clear();
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->divesAllText->clear();
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->tempLimits->clear();
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->totalTimeAllText->clear();
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->timeLimits->clear();
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 19:21:08 +00:00
|
|
|
#define UPDATE_TEXT(d, field) \
|
2013-05-06 17:16:16 +00:00
|
|
|
if (!d || !d->field) \
|
|
|
|
ui->field->setText(""); \
|
2013-09-02 19:21:08 +00:00
|
|
|
else \
|
2013-05-06 17:16:16 +00:00
|
|
|
ui->field->setText(d->field)
|
|
|
|
|
2013-05-06 16:23:14 +00:00
|
|
|
void MainTab::updateDiveInfo(int dive)
|
|
|
|
{
|
2013-09-19 00:56:53 +00:00
|
|
|
if(!isEnabled())
|
|
|
|
setEnabled(true);
|
|
|
|
|
2013-08-16 16:31:52 +00:00
|
|
|
editMode = NONE;
|
2013-06-14 16:17:46 +00:00
|
|
|
// This method updates ALL tabs whenever a new dive or trip is
|
|
|
|
// selected.
|
|
|
|
// If exactly one trip has been selected, we show the location / notes
|
|
|
|
// for the trip in the Info tab, otherwise we show the info of the
|
|
|
|
// selected_dive
|
2013-05-07 03:36:37 +00:00
|
|
|
volume_t sacVal;
|
2013-05-20 05:42:24 +00:00
|
|
|
temperature_t temp;
|
2013-05-19 15:08:29 +00:00
|
|
|
struct dive *prevd;
|
2013-05-06 16:23:14 +00:00
|
|
|
struct dive *d = get_dive(dive);
|
2013-05-19 15:08:29 +00:00
|
|
|
|
2013-05-20 05:42:24 +00:00
|
|
|
process_selected_dives();
|
2013-05-19 15:08:29 +00:00
|
|
|
process_all_dives(d, &prevd);
|
2013-08-16 16:31:52 +00:00
|
|
|
|
2013-05-06 17:16:16 +00:00
|
|
|
UPDATE_TEXT(d, notes);
|
|
|
|
UPDATE_TEXT(d, location);
|
|
|
|
UPDATE_TEXT(d, suit);
|
|
|
|
UPDATE_TEXT(d, divemaster);
|
|
|
|
UPDATE_TEXT(d, buddy);
|
2013-09-17 19:50:15 +00:00
|
|
|
|
2013-05-08 19:08:00 +00:00
|
|
|
if (d) {
|
2013-09-17 19:50:15 +00:00
|
|
|
char buffer[256];
|
|
|
|
print_gps_coordinates(buffer, sizeof buffer, d->latitude.udeg, d->longitude.udeg);
|
|
|
|
ui->coordinates->setText(buffer);
|
2013-06-14 16:17:46 +00:00
|
|
|
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
|
|
|
// only use trip relevant fields
|
2013-09-17 19:50:15 +00:00
|
|
|
ui->coordinates->setVisible(false);
|
2013-06-14 16:17:46 +00:00
|
|
|
ui->divemaster->setVisible(false);
|
|
|
|
ui->DivemasterLabel->setVisible(false);
|
|
|
|
ui->buddy->setVisible(false);
|
|
|
|
ui->BuddyLabel->setVisible(false);
|
|
|
|
ui->suit->setVisible(false);
|
|
|
|
ui->SuitLabel->setVisible(false);
|
|
|
|
ui->rating->setVisible(false);
|
|
|
|
ui->RatingLabel->setVisible(false);
|
|
|
|
ui->visibility->setVisible(false);
|
|
|
|
ui->visibilityLabel->setVisible(false);
|
|
|
|
// rename the remaining fields and fill data from selected trip
|
|
|
|
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
|
|
|
|
ui->LocationLabel->setText(tr("Trip Location"));
|
|
|
|
ui->location->setText(currentTrip->location);
|
|
|
|
ui->NotesLabel->setText(tr("Trip Notes"));
|
|
|
|
ui->notes->setText(currentTrip->notes);
|
|
|
|
} else {
|
|
|
|
// make all the fields visible writeable
|
2013-09-17 19:50:15 +00:00
|
|
|
ui->coordinates->setVisible(true);
|
2013-06-14 16:17:46 +00:00
|
|
|
ui->divemaster->setVisible(true);
|
|
|
|
ui->buddy->setVisible(true);
|
|
|
|
ui->suit->setVisible(true);
|
2013-09-17 19:50:15 +00:00
|
|
|
ui->SuitLabel->setVisible(true);
|
2013-06-14 16:17:46 +00:00
|
|
|
ui->rating->setVisible(true);
|
2013-09-17 19:50:15 +00:00
|
|
|
ui->RatingLabel->setVisible(true);
|
2013-06-14 16:17:46 +00:00
|
|
|
ui->visibility->setVisible(true);
|
2013-09-17 19:50:15 +00:00
|
|
|
ui->visibilityLabel->setVisible(true);
|
2013-08-13 11:58:52 +00:00
|
|
|
ui->BuddyLabel->setVisible(true);
|
|
|
|
ui->DivemasterLabel->setVisible(true);
|
2013-06-14 16:17:46 +00:00
|
|
|
/* and fill them from the dive */
|
|
|
|
ui->rating->setCurrentStars(d->rating);
|
|
|
|
ui->visibility->setCurrentStars(d->visibility);
|
|
|
|
// reset labels in case we last displayed trip notes
|
|
|
|
ui->LocationLabel->setText(tr("Location"));
|
|
|
|
ui->NotesLabel->setText(tr("Notes"));
|
|
|
|
}
|
2013-05-08 19:08:00 +00: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-07 03:36:37 +00:00
|
|
|
ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE));
|
2013-05-19 15:08:29 +00:00
|
|
|
ui->oxygenHeliumText->setText(get_gaslist(d));
|
2013-05-31 07:59:01 +00:00
|
|
|
ui->dateText->setText(get_short_dive_date_string(d->when));
|
2013-05-19 15:08:29 +00:00
|
|
|
ui->diveTimeText->setText(QString::number((int)((d->duration.seconds + 30) / 60)));
|
|
|
|
if (prevd)
|
|
|
|
ui->surfaceIntervalText->setText(get_time_string(d->when - (prevd->when + prevd->duration.seconds), 4));
|
2013-05-08 19:08:00 +00:00
|
|
|
if ((sacVal.mliter = d->sac) > 0)
|
2013-05-20 05:42:24 +00:00
|
|
|
ui->sacText->setText(get_volume_string(sacVal, TRUE).append(tr("/min")));
|
2013-05-08 19:08:00 +00:00
|
|
|
else
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->sacText->clear();
|
2013-05-08 19:08:00 +00:00
|
|
|
if (d->surface_pressure.mbar)
|
|
|
|
/* this is ALWAYS displayed in mbar */
|
|
|
|
ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar));
|
|
|
|
else
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->airPressureText->clear();
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE));
|
|
|
|
ui->depthLimits->setMinimum(get_depth_string(stats_selection.min_depth, TRUE));
|
|
|
|
ui->depthLimits->setAverage(get_depth_string(stats_selection.avg_depth, TRUE));
|
|
|
|
ui->sacLimits->setMaximum(get_volume_string(stats_selection.max_sac, TRUE).append(tr("/min")));
|
|
|
|
ui->sacLimits->setMinimum(get_volume_string(stats_selection.min_sac, TRUE).append(tr("/min")));
|
|
|
|
ui->sacLimits->setAverage(get_volume_string(stats_selection.avg_sac, TRUE).append(tr("/min")));
|
2013-05-20 05:42:24 +00:00
|
|
|
ui->divesAllText->setText(QString::number(stats_selection.selection_size));
|
|
|
|
temp.mkelvin = stats_selection.max_temp;
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->tempLimits->setMaximum(get_temperature_string(temp, TRUE));
|
2013-05-20 05:42:24 +00:00
|
|
|
temp.mkelvin = stats_selection.min_temp;
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->tempLimits->setMinimum(get_temperature_string(temp, TRUE));
|
2013-05-20 05:42:24 +00:00
|
|
|
if (stats_selection.combined_temp && stats_selection.combined_count) {
|
|
|
|
const char *unit;
|
|
|
|
get_temp_units(0, &unit);
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->tempLimits->setAverage(QString("%1%2").arg(stats_selection.combined_temp / stats_selection.combined_count, 0, 'f', 1).arg(unit));
|
2013-05-20 05:42:24 +00:00
|
|
|
}
|
|
|
|
ui->totalTimeAllText->setText(get_time_string(stats_selection.total_time.seconds, 0));
|
|
|
|
int seconds = stats_selection.total_time.seconds;
|
|
|
|
if (stats_selection.selection_size)
|
|
|
|
seconds /= stats_selection.selection_size;
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->timeLimits->setAverage(get_time_string(seconds, 0));
|
|
|
|
ui->timeLimits->setMaximum(get_time_string(stats_selection.longest_time.seconds, 0));
|
|
|
|
ui->timeLimits->setMinimum(get_time_string(stats_selection.shortest_time.seconds, 0));
|
2013-05-21 12:33:55 +00:00
|
|
|
cylindersModel->setDive(d);
|
2013-05-21 12:59:41 +00:00
|
|
|
weightModel->setDive(d);
|
2013-05-08 19:08:00 +00:00
|
|
|
} else {
|
2013-05-20 00:38:20 +00:00
|
|
|
/* clear the fields */
|
2013-05-08 19:08:00 +00:00
|
|
|
ui->rating->setCurrentStars(0);
|
2013-09-19 04:08:39 +00:00
|
|
|
ui->coordinates->clear();
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->sacText->clear();
|
|
|
|
ui->otuText->clear();
|
|
|
|
ui->oxygenHeliumText->clear();
|
|
|
|
ui->dateText->clear();
|
|
|
|
ui->diveTimeText->clear();
|
|
|
|
ui->surfaceIntervalText->clear();
|
|
|
|
ui->maximumDepthText->clear();
|
|
|
|
ui->averageDepthText->clear();
|
2013-05-20 04:44:21 +00:00
|
|
|
ui->visibility->setCurrentStars(0);
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->waterTemperatureText->clear();
|
|
|
|
ui->airTemperatureText->clear();
|
|
|
|
ui->gasUsedText->clear();
|
|
|
|
ui->airPressureText->clear();
|
2013-05-21 12:33:55 +00:00
|
|
|
cylindersModel->clear();
|
2013-05-21 12:59:41 +00:00
|
|
|
weightModel->clear();
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->depthLimits->clear();
|
|
|
|
ui->sacLimits->clear();
|
2013-05-31 12:05:33 +00:00
|
|
|
ui->divesAllText->clear();
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->tempLimits->clear();
|
2013-05-31 12:05:33 +00:00
|
|
|
ui->totalTimeAllText->clear();
|
2013-06-04 21:51:27 +00:00
|
|
|
ui->timeLimits->clear();
|
2013-05-08 19:08:00 +00:00
|
|
|
}
|
2013-05-06 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:40:26 +00:00
|
|
|
void MainTab::addCylinder_clicked()
|
2013-04-13 13:17:59 +00:00
|
|
|
{
|
2013-05-22 17:52:38 +00:00
|
|
|
cylindersModel->add();
|
2013-06-27 12:33:44 +00:00
|
|
|
mark_divelist_changed(TRUE);
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:40:26 +00:00
|
|
|
void MainTab::addWeight_clicked()
|
2013-05-01 21:30:34 +00:00
|
|
|
{
|
2013-05-22 17:52:38 +00:00
|
|
|
weightModel->add();
|
2013-06-27 12:33:44 +00:00
|
|
|
mark_divelist_changed(TRUE);
|
2013-05-01 21:30:34 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
void MainTab::reload()
|
|
|
|
{
|
2013-08-13 13:49:59 +00:00
|
|
|
SuitCompletionModel::instance()->updateModel();
|
|
|
|
BuddyCompletionModel::instance()->updateModel();
|
|
|
|
LocationCompletionModel::instance()->updateModel();
|
|
|
|
DiveMasterCompletionModel::instance()->updateModel();
|
2013-04-07 22:20:43 +00:00
|
|
|
}
|
2013-05-18 23:42:59 +00:00
|
|
|
|
2013-09-19 00:56:53 +00:00
|
|
|
void MainTab::acceptChanges()
|
2013-05-18 23:42:59 +00:00
|
|
|
{
|
2013-09-19 00:56:53 +00:00
|
|
|
mainWindow()->dive_list()->setEnabled(true);
|
2013-09-19 01:38:38 +00:00
|
|
|
tabBar()->setTabIcon(0, QIcon()); // Notes
|
|
|
|
tabBar()->setTabIcon(1, QIcon()); // Equipment
|
2013-09-19 00:56:53 +00:00
|
|
|
ui->diveNotesMessage->animatedHide();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->diveEquipmentMessage->animatedHide();
|
2013-09-19 00:56:53 +00:00
|
|
|
ui->notesButtonBox->hide();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->equipmentButtonBox->hide();
|
2013-09-19 00:56:53 +00:00
|
|
|
/* now figure out if things have changed */
|
|
|
|
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
|
|
|
if (notesBackup[NULL].notes != ui->notes->toPlainText() ||
|
|
|
|
notesBackup[NULL].location != ui->location->text())
|
|
|
|
mark_divelist_changed(TRUE);
|
2013-05-19 16:00:57 +00:00
|
|
|
} else {
|
2013-09-19 00:56:53 +00:00
|
|
|
struct dive *curr = current_dive;
|
2013-09-19 16:37:44 +00:00
|
|
|
//Reset coordinates field, in case it contains garbage.
|
|
|
|
char buffer[256];
|
|
|
|
print_gps_coordinates(buffer, sizeof buffer
|
|
|
|
, current_dive->latitude.udeg, current_dive->longitude.udeg);
|
|
|
|
ui->coordinates->setText(buffer);
|
2013-09-19 00:56:53 +00:00
|
|
|
if (notesBackup[curr].buddy != ui->buddy->text() ||
|
|
|
|
notesBackup[curr].suit != ui->suit->text() ||
|
|
|
|
notesBackup[curr].notes != ui->notes->toPlainText() ||
|
|
|
|
notesBackup[curr].divemaster != ui->divemaster->text() ||
|
|
|
|
notesBackup[curr].location != ui->location->text() ||
|
|
|
|
notesBackup[curr].coordinates != ui->coordinates->text() ||
|
|
|
|
notesBackup[curr].rating != ui->visibility->currentStars() ||
|
|
|
|
notesBackup[curr].visibility != ui->rating->currentStars())
|
|
|
|
|
|
|
|
mark_divelist_changed(TRUE);
|
|
|
|
if (notesBackup[curr].location != ui->location->text() ||
|
|
|
|
notesBackup[curr].coordinates != ui->coordinates->text()) {
|
|
|
|
mainWindow()->globe()->reload();
|
|
|
|
mainWindow()->globe()->centerOn(current_dive);
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-05-19 14:45:01 +00:00
|
|
|
}
|
2013-09-19 04:33:39 +00:00
|
|
|
if (editMode == ADD) {
|
|
|
|
// clean up the dive data (get duration, depth information from samples)
|
|
|
|
fixup_dive(current_dive);
|
|
|
|
DivePlannerPointsModel::instance()->cancelPlan();
|
|
|
|
mainWindow()->showProfile();
|
|
|
|
mainWindow()->refreshDisplay();
|
|
|
|
}
|
2013-09-19 00:56:53 +00:00
|
|
|
editMode = NONE;
|
|
|
|
|
2013-08-16 18:38:18 +00:00
|
|
|
QPalette p;
|
|
|
|
ui->buddy->setPalette(p);
|
|
|
|
ui->notes->setPalette(p);
|
|
|
|
ui->location->setPalette(p);
|
2013-09-19 16:37:44 +00:00
|
|
|
ui->coordinates->setPalette(p);
|
2013-08-16 18:38:18 +00:00
|
|
|
ui->divemaster->setPalette(p);
|
|
|
|
ui->suit->setPalette(p);
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 16:31:52 +00:00
|
|
|
#define EDIT_TEXT2(what, text) \
|
|
|
|
textByteArray = text.toLocal8Bit(); \
|
|
|
|
free(what);\
|
|
|
|
what = strdup(textByteArray.data());
|
|
|
|
|
|
|
|
#define EDIT_TEXT(what, text) \
|
|
|
|
QByteArray textByteArray = text.toLocal8Bit(); \
|
|
|
|
free(what);\
|
|
|
|
what = strdup(textByteArray.data());
|
|
|
|
|
2013-09-19 00:56:53 +00:00
|
|
|
void MainTab::rejectChanges()
|
2013-05-18 23:42:59 +00:00
|
|
|
{
|
2013-09-19 01:38:38 +00:00
|
|
|
tabBar()->setTabIcon(0, QIcon()); // Notes
|
|
|
|
tabBar()->setTabIcon(1, QIcon()); // Equipment
|
2013-09-19 02:23:04 +00:00
|
|
|
|
2013-09-19 00:56:53 +00:00
|
|
|
mainWindow()->dive_list()->setEnabled(true);
|
2013-08-16 16:31:52 +00:00
|
|
|
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1){
|
|
|
|
ui->notes->setText(notesBackup[NULL].notes );
|
|
|
|
ui->location->setText(notesBackup[NULL].location);
|
|
|
|
}else{
|
|
|
|
struct dive *curr = current_dive;
|
|
|
|
ui->notes->setText(notesBackup[curr].notes );
|
|
|
|
ui->location->setText(notesBackup[curr].location);
|
2013-09-17 19:50:15 +00:00
|
|
|
ui->coordinates->setText(notesBackup[curr].coordinates);
|
2013-08-16 16:31:52 +00:00
|
|
|
ui->buddy->setText(notesBackup[curr].buddy);
|
|
|
|
ui->suit->setText(notesBackup[curr].suit);
|
|
|
|
ui->divemaster->setText(notesBackup[curr].divemaster);
|
|
|
|
ui->rating->setCurrentStars(notesBackup[curr].rating);
|
|
|
|
ui->visibility->setCurrentStars(notesBackup[curr].visibility);
|
|
|
|
|
|
|
|
struct dive *mydive;
|
|
|
|
for (int i = 0; i < dive_table.nr; i++) {
|
|
|
|
mydive = get_dive(i);
|
|
|
|
if (!mydive)
|
|
|
|
continue;
|
|
|
|
if (!mydive->selected)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QByteArray textByteArray;
|
|
|
|
EDIT_TEXT2(mydive->buddy, notesBackup[mydive].buddy);
|
|
|
|
EDIT_TEXT2(mydive->suit, notesBackup[mydive].suit);
|
|
|
|
EDIT_TEXT2(mydive->notes, notesBackup[mydive].notes);
|
|
|
|
EDIT_TEXT2(mydive->divemaster, notesBackup[mydive].divemaster);
|
|
|
|
EDIT_TEXT2(mydive->location, notesBackup[mydive].location);
|
2013-09-17 19:50:15 +00:00
|
|
|
mydive->latitude = notesBackup[mydive].latitude;
|
|
|
|
mydive->longitude = notesBackup[mydive].longitude;
|
2013-08-16 16:31:52 +00:00
|
|
|
mydive->rating = notesBackup[mydive].rating;
|
|
|
|
mydive->visibility = notesBackup[mydive].visibility;
|
|
|
|
}
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-09-19 02:23:04 +00:00
|
|
|
|
2013-05-18 23:42:59 +00:00
|
|
|
ui->diveNotesMessage->animatedHide();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->diveEquipmentMessage->animatedHide();
|
2013-05-19 03:09:36 +00:00
|
|
|
mainWindow()->dive_list()->setEnabled(true);
|
2013-09-19 00:56:53 +00:00
|
|
|
ui->notesButtonBox->hide();
|
2013-09-19 02:23:04 +00:00
|
|
|
ui->equipmentButtonBox->hide();
|
2013-08-16 16:31:52 +00:00
|
|
|
notesBackup.clear();
|
2013-08-16 18:38:18 +00:00
|
|
|
QPalette p;
|
|
|
|
ui->buddy->setPalette(p);
|
|
|
|
ui->notes->setPalette(p);
|
|
|
|
ui->location->setPalette(p);
|
2013-09-19 16:37:44 +00:00
|
|
|
ui->coordinates->setPalette(p);
|
2013-08-16 18:38:18 +00:00
|
|
|
ui->divemaster->setPalette(p);
|
|
|
|
ui->suit->setPalette(p);
|
2013-09-20 03:58:53 +00:00
|
|
|
if (editMode == ADD) {
|
|
|
|
// clean up
|
|
|
|
delete_single_dive(selected_dive);
|
|
|
|
selected_dive = -1;
|
|
|
|
DivePlannerPointsModel::instance()->cancelPlan();
|
|
|
|
mainWindow()->showProfile();
|
|
|
|
mainWindow()->refreshDisplay();
|
|
|
|
}
|
2013-06-14 16:17:46 +00:00
|
|
|
editMode = NONE;
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
2013-08-16 16:31:52 +00:00
|
|
|
#undef EDIT_TEXT2
|
2013-08-16 18:52:40 +00:00
|
|
|
|
2013-09-19 16:37:44 +00:00
|
|
|
#define EDIT_SELECTED_DIVES( WHAT ) do { \
|
2013-08-16 18:52:40 +00:00
|
|
|
if (editMode == NONE) \
|
|
|
|
return; \
|
|
|
|
\
|
|
|
|
for (int i = 0; i < dive_table.nr; i++) { \
|
2013-09-17 19:50:15 +00:00
|
|
|
struct dive *mydive = get_dive(i); \
|
2013-08-16 18:52:40 +00:00
|
|
|
if (!mydive) \
|
|
|
|
continue; \
|
|
|
|
if (!mydive->selected) \
|
|
|
|
continue; \
|
|
|
|
\
|
|
|
|
WHAT; \
|
2013-09-19 16:37:44 +00:00
|
|
|
} \
|
|
|
|
} while(0)
|
2013-05-18 23:42:59 +00:00
|
|
|
|
2013-08-16 18:52:40 +00:00
|
|
|
void markChangedWidget(QWidget *w){
|
2013-08-16 18:38:18 +00:00
|
|
|
QPalette p;
|
|
|
|
p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter());
|
2013-08-16 18:52:40 +00:00
|
|
|
w->setPalette(p);
|
|
|
|
}
|
2013-05-18 23:42:59 +00:00
|
|
|
|
|
|
|
void MainTab::on_buddy_textChanged(const QString& text)
|
|
|
|
{
|
2013-08-16 18:52:40 +00:00
|
|
|
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->buddy, text) );
|
|
|
|
markChangedWidget(ui->buddy);
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_divemaster_textChanged(const QString& text)
|
|
|
|
{
|
2013-08-16 18:52:40 +00:00
|
|
|
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->divemaster, text) );
|
|
|
|
markChangedWidget(ui->divemaster);
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_location_textChanged(const QString& text)
|
|
|
|
{
|
2013-08-16 16:31:52 +00:00
|
|
|
if (editMode == NONE)
|
|
|
|
return;
|
2013-06-14 16:17:46 +00:00
|
|
|
if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
|
|
|
// we are editing a trip
|
|
|
|
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
|
|
|
|
EDIT_TEXT(currentTrip->location, text);
|
2013-09-19 04:33:39 +00:00
|
|
|
} else if (editMode == DIVE || editMode == ADD){
|
2013-09-19 16:37:44 +00:00
|
|
|
if (!ui->coordinates->isModified() ||
|
|
|
|
ui->coordinates->text().trimmed().isEmpty()) {
|
|
|
|
struct dive* dive;
|
|
|
|
int i = 0;
|
|
|
|
for_each_dive(i, dive){
|
|
|
|
QString location(dive->location);
|
|
|
|
if (location == text &&
|
|
|
|
(dive->latitude.udeg || dive->longitude.udeg)) {
|
|
|
|
EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude );
|
|
|
|
EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude );
|
|
|
|
char buffer[256];
|
|
|
|
print_gps_coordinates(buffer, sizeof buffer
|
|
|
|
, dive->latitude.udeg, dive->longitude.udeg);
|
|
|
|
ui->coordinates->setText(buffer);
|
|
|
|
markChangedWidget(ui->coordinates);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-17 19:50:15 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-19 16:37:44 +00:00
|
|
|
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) );
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-08-16 18:38:18 +00:00
|
|
|
|
2013-08-16 18:52:40 +00:00
|
|
|
markChangedWidget(ui->location);
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_suit_textChanged(const QString& text)
|
|
|
|
{
|
2013-08-16 18:52:40 +00:00
|
|
|
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->suit, text) );
|
|
|
|
markChangedWidget(ui->suit);
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_notes_textChanged()
|
|
|
|
{
|
2013-08-16 16:31:52 +00:00
|
|
|
if (editMode == NONE)
|
|
|
|
return;
|
2013-06-14 16:17:46 +00:00
|
|
|
if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
|
|
|
// we are editing a trip
|
|
|
|
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
|
|
|
|
EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText());
|
2013-09-19 04:33:39 +00:00
|
|
|
} else if (editMode == DIVE || editMode == ADD) {
|
2013-08-16 18:52:40 +00:00
|
|
|
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui->notes->toPlainText()) );
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-08-16 18:52:40 +00:00
|
|
|
markChangedWidget(ui->notes);
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 16:17:46 +00:00
|
|
|
#undef EDIT_TEXT
|
2013-05-18 23:42:59 +00:00
|
|
|
|
2013-09-17 19:50:15 +00:00
|
|
|
void MainTab::on_coordinates_textChanged(const QString& text)
|
|
|
|
{
|
|
|
|
QByteArray textByteArray = text.toLocal8Bit();
|
2013-09-19 16:37:44 +00:00
|
|
|
gboolean gpsChanged = FALSE;
|
|
|
|
EDIT_SELECTED_DIVES(gpsChanged |= gps_changed(mydive, NULL, textByteArray.data()));
|
|
|
|
if (gpsChanged) {
|
|
|
|
markChangedWidget(ui->coordinates);
|
|
|
|
} else {
|
|
|
|
QPalette p;
|
|
|
|
p.setBrush(QPalette::Base, QColor(Qt::red).lighter());
|
|
|
|
ui->coordinates->setPalette(p);
|
|
|
|
}
|
2013-09-17 19:50:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 23:42:59 +00:00
|
|
|
void MainTab::on_rating_valueChanged(int value)
|
|
|
|
{
|
2013-08-16 18:52:40 +00:00
|
|
|
EDIT_SELECTED_DIVES(mydive->rating = value );
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
2013-05-20 13:25:16 +00:00
|
|
|
|
|
|
|
void MainTab::on_visibility_valueChanged(int value)
|
|
|
|
{
|
2013-08-16 18:52:40 +00:00
|
|
|
EDIT_SELECTED_DIVES( mydive->visibility = value );
|
2013-05-20 13:25:16 +00:00
|
|
|
}
|
2013-06-16 17:36:23 +00:00
|
|
|
|
2013-07-17 15:13:04 +00:00
|
|
|
void MainTab::editCylinderWidget(const QModelIndex& index)
|
|
|
|
{
|
2013-09-02 19:21:08 +00:00
|
|
|
if (index.isValid() && index.column() != CylindersModel::REMOVE)
|
2013-07-17 15:13:04 +00:00
|
|
|
ui->cylinders->edit(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::editWeigthWidget(const QModelIndex& index)
|
|
|
|
{
|
2013-09-02 19:21:08 +00:00
|
|
|
if (index.isValid() && index.column() != WeightModel::REMOVE)
|
2013-07-17 15:13:04 +00:00
|
|
|
ui->weights->edit(index);
|
2013-06-16 17:36:23 +00:00
|
|
|
}
|