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"
|
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-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-11-19 22:16:33 +00:00
|
|
|
#include "divelist.h"
|
2013-10-05 16:48:26 +00:00
|
|
|
#include "qthelper.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-11-28 11:17:30 +00:00
|
|
|
#include <QSettings>
|
2013-09-02 19:21:08 +00:00
|
|
|
#include <QTableView>
|
2013-08-16 18:38:18 +00:00
|
|
|
#include <QPalette>
|
2013-12-12 01:08:56 +00:00
|
|
|
#include <QScrollBar>
|
2013-04-07 22:20:43 +00:00
|
|
|
|
|
|
|
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
2013-04-13 13:17:59 +00:00
|
|
|
weightModel(new WeightModel()),
|
2013-11-09 22:06:26 +00:00
|
|
|
cylindersModel(CylindersModel::instance()),
|
2013-06-14 16:17:46 +00:00
|
|
|
editMode(NONE)
|
2013-04-07 22:20:43 +00:00
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.setupUi(this);
|
2013-12-19 22:20:37 +00:00
|
|
|
ui.tagWidget->setFocusPolicy(Qt::StrongFocus); // Don't get focus by 'Wheel'
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.cylinders->setModel(cylindersModel);
|
|
|
|
ui.weights->setModel(weightModel);
|
2013-12-03 20:44:48 +00:00
|
|
|
closeMessage();
|
2013-09-26 20:02:27 +00:00
|
|
|
|
2013-12-02 17:33:00 +00:00
|
|
|
QAction *action = new QAction(tr("Save"), this);
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges()));
|
2013-12-03 20:44:48 +00:00
|
|
|
addMessageAction(action);
|
2013-12-02 17:33:00 +00:00
|
|
|
|
|
|
|
action = new QAction(tr("Cancel"), this);
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(rejectChanges()));
|
2013-12-03 20:44:48 +00:00
|
|
|
addMessageAction(action);
|
2013-12-02 17:33:00 +00:00
|
|
|
|
2013-09-26 20:02:27 +00:00
|
|
|
if (qApp->style()->objectName() == "oxygen")
|
2013-09-26 19:51:11 +00:00
|
|
|
setDocumentMode(true);
|
2013-09-26 20:02:27 +00:00
|
|
|
else
|
|
|
|
setDocumentMode(false);
|
|
|
|
|
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
|
|
|
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.location->installEventFilter(this);
|
|
|
|
ui.coordinates->installEventFilter(this);
|
|
|
|
ui.divemaster->installEventFilter(this);
|
|
|
|
ui.buddy->installEventFilter(this);
|
|
|
|
ui.suit->installEventFilter(this);
|
|
|
|
ui.notes->viewport()->installEventFilter(this);
|
|
|
|
ui.rating->installEventFilter(this);
|
|
|
|
ui.visibility->installEventFilter(this);
|
|
|
|
ui.airtemp->installEventFilter(this);
|
|
|
|
ui.watertemp->installEventFilter(this);
|
|
|
|
ui.dateTimeEdit->installEventFilter(this);
|
2013-11-02 01:20:02 +00:00
|
|
|
ui.tagWidget->installEventFilter(this);
|
2013-10-03 18:54:25 +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-10-03 18:54:25 +00:00
|
|
|
ui.cylinders->setTitle(tr("Cylinders"));
|
|
|
|
ui.cylinders->setBtnToolTip(tr("Add Cylinder"));
|
|
|
|
connect(ui.cylinders, SIGNAL(addButtonClicked()), this, SLOT(addCylinder_clicked()));
|
|
|
|
|
|
|
|
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)));
|
2013-10-03 23:04:51 +00:00
|
|
|
connect(ui.weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeightWidget(QModelIndex)));
|
2013-10-03 18:54:25 +00:00
|
|
|
|
|
|
|
ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
|
|
|
|
ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
|
2013-11-12 02:12:43 +00:00
|
|
|
ui.cylinders->view()->setColumnHidden(CylindersModel::DEPTH, true);
|
2013-10-03 18:54:25 +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);
|
2013-11-02 01:20:02 +00:00
|
|
|
completers.tags = new QCompleter(TagCompletionModel::instance(), ui.tagWidget);
|
2013-11-15 00:39:02 +00:00
|
|
|
completers.tags->setCaseSensitivity(Qt::CaseInsensitive);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.buddy->setCompleter(completers.buddy);
|
|
|
|
ui.divemaster->setCompleter(completers.divemaster);
|
|
|
|
ui.location->setCompleter(completers.location);
|
|
|
|
ui.suit->setCompleter(completers.suit);
|
2013-11-02 01:20:02 +00:00
|
|
|
ui.tagWidget->setCompleter(completers.tags);
|
2013-09-26 21:14:09 +00:00
|
|
|
|
|
|
|
setMinimumHeight(0);
|
|
|
|
setMinimumWidth(0);
|
2013-09-27 15:52:01 +00:00
|
|
|
|
|
|
|
// Current display of things on Gnome3 looks like shit, so
|
|
|
|
// let`s fix that.
|
|
|
|
if (isGnome3Session()) {
|
|
|
|
QPalette p;
|
|
|
|
p.setColor(QPalette::Window, QColor(Qt::white));
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.scrollArea->viewport()->setPalette(p);
|
|
|
|
ui.scrollArea_2->viewport()->setPalette(p);
|
|
|
|
ui.scrollArea_3->viewport()->setPalette(p);
|
|
|
|
ui.scrollArea_4->viewport()->setPalette(p);
|
2013-12-04 20:24:37 +00:00
|
|
|
|
|
|
|
// GroupBoxes in Gnome3 looks like I'v drawn them...
|
|
|
|
static const QString gnomeCss(
|
|
|
|
"QGroupBox {"
|
|
|
|
" background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
|
|
|
" stop: 0 #E0E0E0, stop: 1 #FFFFFF);"
|
|
|
|
" border: 2px solid gray;"
|
|
|
|
" border-radius: 5px;"
|
|
|
|
" margin-top: 1ex;"
|
|
|
|
"}"
|
|
|
|
"QGroupBox::title {"
|
|
|
|
" subcontrol-origin: margin;"
|
|
|
|
" subcontrol-position: top center;"
|
|
|
|
" padding: 0 3px;"
|
|
|
|
" background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
2013-12-07 16:13:55 +00:00
|
|
|
" stop: 0 #E0E0E0, stop: 1 #FFFFFF);"
|
2013-12-04 20:24:37 +00:00
|
|
|
"}");
|
|
|
|
Q_FOREACH(QGroupBox *box, findChildren<QGroupBox*>()){
|
|
|
|
box->setStyleSheet(gnomeCss);
|
|
|
|
}
|
|
|
|
|
2013-09-27 15:52:01 +00:00
|
|
|
}
|
2013-11-28 11:17:30 +00:00
|
|
|
ui.cylinders->view()->horizontalHeader()->setContextMenuPolicy(Qt::ActionsContextMenu);
|
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("cylinders_dialog");
|
|
|
|
for(int i = 0; i < CylindersModel::COLUMNS; i++){
|
|
|
|
if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE))
|
|
|
|
continue;
|
|
|
|
bool checked = s.value(QString("column%1_hidden").arg(i)).toBool();
|
|
|
|
QAction *action = new QAction(cylindersModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(), ui.cylinders->view());
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setData(i);
|
|
|
|
action->setChecked(!checked);
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(toggleTriggeredColumn()));
|
|
|
|
ui.cylinders->view()->setColumnHidden(i, checked);
|
|
|
|
ui.cylinders->view()->horizontalHeader()->addAction(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MainTab::~MainTab()
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("cylinders_dialog");
|
|
|
|
for(int i = 0; i < CylindersModel::COLUMNS; i++){
|
|
|
|
if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE))
|
|
|
|
continue;
|
|
|
|
s.setValue(QString("column%1_hidden").arg(i), ui.cylinders->view()->isColumnHidden(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::toggleTriggeredColumn()
|
|
|
|
{
|
|
|
|
QAction *action = qobject_cast<QAction*>(sender());
|
|
|
|
int col = action->data().toInt();
|
|
|
|
QTableView *view = ui.cylinders->view();
|
|
|
|
|
|
|
|
if(action->isChecked()){
|
|
|
|
view->showColumn(col);
|
|
|
|
if(view->columnWidth(col) <= 15)
|
|
|
|
view->setColumnWidth(col, 80);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
view->hideColumn(col);
|
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()
|
|
|
|
{
|
2013-12-27 16:18:53 +00:00
|
|
|
enableEdition(ADD);
|
2013-09-19 04:33:39 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 20:44:48 +00:00
|
|
|
void MainTab::addMessageAction(QAction* action)
|
|
|
|
{
|
|
|
|
ui.diveEquipmentMessage->addAction(action);
|
|
|
|
ui.diveNotesMessage->addAction(action);
|
|
|
|
ui.diveInfoMessage->addAction(action);
|
|
|
|
ui.diveStatisticsMessage->addAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::hideMessage()
|
|
|
|
{
|
|
|
|
ui.diveNotesMessage->animatedHide();
|
|
|
|
ui.diveEquipmentMessage->animatedHide();
|
|
|
|
ui.diveInfoMessage->animatedHide();
|
|
|
|
ui.diveStatisticsMessage->animatedHide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::closeMessage()
|
|
|
|
{
|
|
|
|
hideMessage();
|
|
|
|
ui.diveNotesMessage->setCloseButtonVisible(false);
|
|
|
|
ui.diveEquipmentMessage->setCloseButtonVisible(false);
|
|
|
|
ui.diveInfoMessage->setCloseButtonVisible(false);
|
|
|
|
ui.diveStatisticsMessage->setCloseButtonVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::displayMessage(QString str)
|
|
|
|
{
|
|
|
|
ui.diveNotesMessage->setText(str);
|
|
|
|
ui.diveNotesMessage->animatedShow();
|
|
|
|
ui.diveEquipmentMessage->setText(str);
|
|
|
|
ui.diveEquipmentMessage->animatedShow();
|
|
|
|
ui.diveInfoMessage->setText(str);
|
|
|
|
ui.diveInfoMessage->animatedShow();
|
|
|
|
ui.diveStatisticsMessage->setText(str);
|
|
|
|
ui.diveStatisticsMessage->animatedShow();
|
|
|
|
}
|
|
|
|
|
2013-11-01 15:48:34 +00:00
|
|
|
void MainTab::enableEdition(EditMode newEditMode)
|
2013-08-13 11:34:04 +00:00
|
|
|
{
|
2013-12-27 16:18:53 +00:00
|
|
|
if (current_dive == NULL || editMode != NONE)
|
2013-08-13 11:34:04 +00:00
|
|
|
return;
|
2013-12-27 16:18:53 +00:00
|
|
|
if ((newEditMode == DIVE || newEditMode == NONE) &&
|
2014-01-03 12:49:17 +00:00
|
|
|
current_dive->dc.model &&
|
2013-12-27 16:18:53 +00:00
|
|
|
strcmp(current_dive->dc.model, "manually added dive") == 0) {
|
|
|
|
// editCurrentDive will call enableEdition with newEditMode == MANUALLY_ADDED_DIVE
|
|
|
|
// so exit this function here after editCurrentDive() returns
|
|
|
|
mainWindow()->editCurrentDive();
|
|
|
|
return;
|
|
|
|
}
|
2013-09-19 02:23:04 +00:00
|
|
|
mainWindow()->dive_list()->setEnabled(false);
|
2013-12-02 17:06:19 +00:00
|
|
|
mainWindow()->globe()->prepareForGetDiveCoordinates();
|
2013-09-19 00:56:53 +00:00
|
|
|
// We may be editing one or more dives here. backup everything.
|
|
|
|
notesBackup.clear();
|
2013-11-26 17:44:18 +00:00
|
|
|
if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
|
2013-09-19 00:56:53 +00:00
|
|
|
// we are editing trip location and notes
|
2013-12-03 20:44:48 +00:00
|
|
|
displayMessage(tr("This trip is being edited."));
|
2013-10-03 18:54:25 +00:00
|
|
|
notesBackup[NULL].notes = ui.notes->toPlainText();
|
|
|
|
notesBackup[NULL].location = ui.location->text();
|
2013-09-19 00:56:53 +00:00
|
|
|
editMode = TRIP;
|
|
|
|
} else {
|
2013-11-05 06:57:24 +00:00
|
|
|
if (amount_selected > 1) {
|
2013-12-03 20:44:48 +00:00
|
|
|
displayMessage(tr("Multiple dives are being edited."));
|
2013-11-05 06:57:24 +00:00
|
|
|
} else {
|
2013-12-03 20:44:48 +00:00
|
|
|
displayMessage(tr("This dive is being edited."));
|
2013-11-05 06:57:24 +00:00
|
|
|
}
|
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-10-03 18:54:25 +00:00
|
|
|
notesBackup[mydive].coordinates = ui.coordinates->text();
|
2013-09-20 23:41:42 +00:00
|
|
|
notesBackup[mydive].airtemp = get_temperature_string(mydive->airtemp, true);
|
|
|
|
notesBackup[mydive].watertemp = get_temperature_string(mydive->watertemp, true);
|
2013-11-30 07:35:15 +00:00
|
|
|
notesBackup[mydive].datetime = QDateTime::fromTime_t(mydive->when).toUTC().toString();
|
2013-11-02 01:20:02 +00:00
|
|
|
char buf[1024];
|
|
|
|
taglist_get_tagstring(mydive->tag_list, buf, 1024);
|
|
|
|
notesBackup[mydive].tags = QString(buf);
|
2013-09-25 17:10:15 +00:00
|
|
|
|
|
|
|
// maybe this is a place for memset?
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
notesBackup[mydive].cylinders[i] = mydive->cylinder[i];
|
|
|
|
}
|
|
|
|
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
2013-10-03 23:04:51 +00:00
|
|
|
notesBackup[mydive].weightsystem[i] = mydive->weightsystem[i];
|
2013-09-25 17:10:15 +00:00
|
|
|
}
|
2013-09-19 00:56:53 +00:00
|
|
|
}
|
2013-11-01 15:48:34 +00:00
|
|
|
|
|
|
|
editMode = newEditMode != NONE ? newEditMode : DIVE;
|
2013-09-19 00:56:53 +00:00
|
|
|
}
|
2013-08-13 11:34:04 +00:00
|
|
|
}
|
|
|
|
|
2013-05-19 14:45:01 +00:00
|
|
|
bool MainTab::eventFilter(QObject* object, QEvent* event)
|
|
|
|
{
|
2013-12-19 21:45:54 +00:00
|
|
|
if (!isEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (editMode != NONE)
|
|
|
|
return false;
|
2013-12-14 05:15:07 +00:00
|
|
|
// for the dateTimeEdit widget we need to ignore Wheel events as well (as long as we aren't editing)
|
2013-12-19 21:45:54 +00:00
|
|
|
if (object->objectName() == "dateTimeEdit" &&
|
2013-12-14 05:15:07 +00:00
|
|
|
(event->type() == QEvent::FocusIn || event->type() == QEvent::Wheel))
|
|
|
|
return true;
|
|
|
|
// MouseButtonPress in any widget (not all will ever get this), KeyPress in the dateTimeEdit,
|
|
|
|
// FocusIn for the starWidgets or RequestSoftwareInputPanel for tagWidget start the editing
|
2013-12-19 21:45:54 +00:00
|
|
|
if ((event->type() == QEvent::MouseButtonPress) ||
|
2013-12-14 05:15:07 +00:00
|
|
|
(event->type() == QEvent::KeyPress && object == ui.dateTimeEdit) ||
|
|
|
|
(event->type() == QEvent::FocusIn && (object == ui.rating || object == ui.visibility)) ||
|
2013-12-19 21:45:54 +00:00
|
|
|
(event->type() == QEvent::RequestSoftwareInputPanel && object == ui.tagWidget)) {
|
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()
|
|
|
|
{
|
2013-10-10 08:16:32 +00:00
|
|
|
cylindersModel->clear();
|
|
|
|
weightModel->clear();
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::clearInfo()
|
|
|
|
{
|
2013-10-03 18:54:25 +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-10-10 08:16:32 +00:00
|
|
|
ui.salinityText->clear();
|
2013-11-02 01:20:02 +00:00
|
|
|
ui.tagWidget->clear();
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::clearStats()
|
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.depthLimits->clear();
|
|
|
|
ui.sacLimits->clear();
|
|
|
|
ui.divesAllText->clear();
|
|
|
|
ui.tempLimits->clear();
|
|
|
|
ui.totalTimeAllText->clear();
|
|
|
|
ui.timeLimits->clear();
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 15:19:05 +00:00
|
|
|
#define UPDATE_TEXT(d, field) \
|
2013-05-06 17:16:16 +00:00
|
|
|
if (!d || !d->field) \
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.field->setText(""); \
|
2013-09-22 15:19:05 +00:00
|
|
|
else \
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.field->setText(d->field)
|
2013-05-06 17:16:16 +00:00
|
|
|
|
2013-09-22 15:19:05 +00:00
|
|
|
#define UPDATE_TEMP(d, field) \
|
|
|
|
if (!d || d->field.mkelvin == 0) \
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.field->setText(""); \
|
2013-09-22 15:19:05 +00:00
|
|
|
else \
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.field->setText(get_temperature_string(d->field, TRUE))
|
2013-09-20 23:41:42 +00:00
|
|
|
|
2013-11-10 21:23:18 +00:00
|
|
|
bool MainTab::isEditing()
|
|
|
|
{
|
|
|
|
return editMode != NONE;
|
|
|
|
}
|
|
|
|
|
2013-05-06 16:23:14 +00:00
|
|
|
void MainTab::updateDiveInfo(int dive)
|
|
|
|
{
|
2013-11-12 07:33:27 +00:00
|
|
|
// don't execute this while adding a dive
|
2013-12-25 21:02:38 +00:00
|
|
|
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE)
|
2013-11-12 07:33:27 +00:00
|
|
|
return;
|
2013-09-22 15:19:05 +00:00
|
|
|
if (!isEnabled() && dive != -1)
|
2013-09-19 00:56:53 +00:00
|
|
|
setEnabled(true);
|
2013-09-22 15:19:05 +00:00
|
|
|
if (isEnabled() && dive == -1)
|
|
|
|
setEnabled(false);
|
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-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-12-28 01:26:22 +00:00
|
|
|
char buf[1024];
|
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-20 23:41:42 +00:00
|
|
|
UPDATE_TEMP(d, airtemp);
|
|
|
|
UPDATE_TEMP(d, watertemp);
|
2013-05-08 19:08:00 +00:00
|
|
|
if (d) {
|
2013-11-11 23:21:45 +00:00
|
|
|
updateGpsCoordinates(d);
|
2013-11-30 07:35:15 +00:00
|
|
|
ui.dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when).toUTC());
|
2013-11-26 17:44:18 +00:00
|
|
|
if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
|
2013-11-25 19:05:09 +00:00
|
|
|
setTabText(0, tr("Trip Notes"));
|
2013-06-14 16:17:46 +00:00
|
|
|
// only use trip relevant fields
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.coordinates->setVisible(false);
|
2013-11-04 19:28:03 +00:00
|
|
|
ui.CoordinatedLabel->setVisible(false);
|
2013-10-03 18:54:25 +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);
|
2013-11-04 19:28:03 +00:00
|
|
|
ui.tagWidget->setVisible(false);
|
|
|
|
ui.TagLabel->setVisible(false);
|
2013-11-30 10:13:40 +00:00
|
|
|
ui.airTempLabel->setVisible(false);
|
2013-11-07 03:38:35 +00:00
|
|
|
ui.airtemp->setVisible(false);
|
2013-11-30 10:13:40 +00:00
|
|
|
ui.waterTempLabel->setVisible(false);
|
2013-11-07 03:38:35 +00:00
|
|
|
ui.watertemp->setVisible(false);
|
2013-06-14 16:17:46 +00:00
|
|
|
// rename the remaining fields and fill data from selected trip
|
2013-11-26 17:44:18 +00:00
|
|
|
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin();
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.LocationLabel->setText(tr("Trip Location"));
|
|
|
|
ui.location->setText(currentTrip->location);
|
|
|
|
ui.NotesLabel->setText(tr("Trip Notes"));
|
|
|
|
ui.notes->setText(currentTrip->notes);
|
2013-12-28 01:26:22 +00:00
|
|
|
clearEquipment();
|
|
|
|
ui.equipmentTab->setEnabled(false);
|
2013-06-14 16:17:46 +00:00
|
|
|
} else {
|
2013-11-25 19:05:09 +00:00
|
|
|
setTabText(0, tr("Dive Notes"));
|
2013-06-14 16:17:46 +00:00
|
|
|
// make all the fields visible writeable
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.coordinates->setVisible(true);
|
2013-11-04 19:28:03 +00:00
|
|
|
ui.CoordinatedLabel->setVisible(true);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.divemaster->setVisible(true);
|
|
|
|
ui.buddy->setVisible(true);
|
|
|
|
ui.suit->setVisible(true);
|
|
|
|
ui.SuitLabel->setVisible(true);
|
|
|
|
ui.rating->setVisible(true);
|
|
|
|
ui.RatingLabel->setVisible(true);
|
|
|
|
ui.visibility->setVisible(true);
|
|
|
|
ui.visibilityLabel->setVisible(true);
|
|
|
|
ui.BuddyLabel->setVisible(true);
|
|
|
|
ui.DivemasterLabel->setVisible(true);
|
2013-11-04 19:28:03 +00:00
|
|
|
ui.TagLabel->setVisible(true);
|
|
|
|
ui.tagWidget->setVisible(true);
|
2013-11-30 10:13:40 +00:00
|
|
|
ui.airTempLabel->setVisible(true);
|
2013-11-07 03:38:35 +00:00
|
|
|
ui.airtemp->setVisible(true);
|
2013-11-30 10:13:40 +00:00
|
|
|
ui.waterTempLabel->setVisible(true);
|
2013-11-07 03:38:35 +00:00
|
|
|
ui.watertemp->setVisible(true);
|
2013-06-14 16:17:46 +00:00
|
|
|
/* and fill them from the dive */
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.rating->setCurrentStars(d->rating);
|
|
|
|
ui.visibility->setCurrentStars(d->visibility);
|
2013-06-14 16:17:46 +00:00
|
|
|
// reset labels in case we last displayed trip notes
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.LocationLabel->setText(tr("Location"));
|
|
|
|
ui.NotesLabel->setText(tr("Notes"));
|
2013-12-28 01:26:22 +00:00
|
|
|
ui.equipmentTab->setEnabled(true);
|
|
|
|
multiEditEquipmentPlaceholder = *d;
|
|
|
|
cylindersModel->setDive(&multiEditEquipmentPlaceholder);
|
|
|
|
weightModel->setDive(&multiEditEquipmentPlaceholder);
|
|
|
|
taglist_get_tagstring(d->tag_list, buf, 1024);
|
|
|
|
ui.tagWidget->setText(QString(buf));
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-10-03 18:54:25 +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-12-09 21:37:49 +00:00
|
|
|
volume_t gases[MAX_CYLINDERS] = {};
|
2013-11-19 23:29:32 +00:00
|
|
|
get_gas_used(d, gases);
|
|
|
|
QString volumes = get_volume_string(gases[0], TRUE);
|
2013-11-20 06:50:02 +00:00
|
|
|
int mean[MAX_CYLINDERS], duration[MAX_CYLINDERS];
|
|
|
|
per_cylinder_mean_depth(d, select_dc(&d->dc), mean, duration);
|
|
|
|
volume_t sac;
|
|
|
|
QString SACs;
|
|
|
|
if (mean[0] && duration[0]) {
|
|
|
|
sac.mliter = gases[0].mliter * 1000.0 / (depth_to_mbar(mean[0], d) * duration[0] / 60.0);
|
|
|
|
SACs = get_volume_string(sac, TRUE).append(tr("/min"));
|
|
|
|
} else {
|
|
|
|
SACs = QString(tr("unknown"));
|
|
|
|
}
|
|
|
|
for(int i=1; i < MAX_CYLINDERS && gases[i].mliter != 0; i++) {
|
2013-11-19 23:29:32 +00:00
|
|
|
volumes.append("\n" + get_volume_string(gases[i], TRUE));
|
2013-11-20 06:50:02 +00:00
|
|
|
if (duration[i]) {
|
|
|
|
sac.mliter = gases[i].mliter * 1000.0 / (depth_to_mbar(mean[i], d) * duration[i] / 60);
|
|
|
|
SACs.append("\n" + get_volume_string(sac, TRUE).append(tr("/min")));
|
|
|
|
} else {
|
|
|
|
SACs.append("\n");
|
|
|
|
}
|
|
|
|
}
|
2013-11-19 23:29:32 +00:00
|
|
|
ui.gasUsedText->setText(volumes);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.oxygenHeliumText->setText(get_gaslist(d));
|
|
|
|
ui.dateText->setText(get_short_dive_date_string(d->when));
|
|
|
|
ui.diveTimeText->setText(QString::number((int)((d->duration.seconds + 30) / 60)));
|
2013-05-19 15:08:29 +00:00
|
|
|
if (prevd)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.surfaceIntervalText->setText(get_time_string(d->when - (prevd->when + prevd->duration.seconds), 4));
|
2013-11-14 10:36:41 +00:00
|
|
|
else
|
|
|
|
ui.surfaceIntervalText->clear();
|
2013-11-20 06:50:02 +00:00
|
|
|
if (mean[0])
|
|
|
|
ui.sacText->setText(SACs);
|
2013-05-08 19:08:00 +00:00
|
|
|
else
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.sacText->clear();
|
2013-05-08 19:08:00 +00:00
|
|
|
if (d->surface_pressure.mbar)
|
|
|
|
/* this is ALWAYS displayed in mbar */
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar));
|
2013-05-08 19:08:00 +00:00
|
|
|
else
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.airPressureText->clear();
|
2013-10-10 08:16:32 +00:00
|
|
|
if (d->salinity)
|
|
|
|
ui.salinityText->setText(QString("%1g/l").arg(d->salinity/10.0));
|
|
|
|
else
|
|
|
|
ui.salinityText->clear();
|
2013-10-07 18:48:14 +00:00
|
|
|
ui.depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE));
|
2013-10-03 18:54:25 +00:00
|
|
|
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")));
|
|
|
|
ui.divesAllText->setText(QString::number(stats_selection.selection_size));
|
2013-05-20 05:42:24 +00:00
|
|
|
temp.mkelvin = stats_selection.max_temp;
|
2013-10-03 18:54:25 +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-10-03 18:54:25 +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-10-03 18:54:25 +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
|
|
|
}
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.totalTimeAllText->setText(get_time_string(stats_selection.total_time.seconds, 0));
|
2013-05-20 05:42:24 +00:00
|
|
|
int seconds = stats_selection.total_time.seconds;
|
|
|
|
if (stats_selection.selection_size)
|
|
|
|
seconds /= stats_selection.selection_size;
|
2013-10-03 18:54:25 +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-08 19:08:00 +00:00
|
|
|
} else {
|
2013-05-20 00:38:20 +00:00
|
|
|
/* clear the fields */
|
2013-10-10 08:16:32 +00:00
|
|
|
clearInfo();
|
|
|
|
clearStats();
|
|
|
|
clearEquipment();
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.rating->setCurrentStars(0);
|
|
|
|
ui.coordinates->clear();
|
|
|
|
ui.visibility->setCurrentStars(0);
|
2013-09-22 14:33:09 +00:00
|
|
|
/* turns out this is non-trivial for a dateTimeEdit... this is a partial hack */
|
2013-10-03 18:54:25 +00:00
|
|
|
QLineEdit *le = ui.dateTimeEdit->findChild<QLineEdit*>();
|
2013-09-22 14:33:09 +00:00
|
|
|
le->setText("");
|
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-09-25 18:05:48 +00:00
|
|
|
if(editMode == NONE)
|
|
|
|
enableEdition();
|
2013-05-22 17:52:38 +00:00
|
|
|
cylindersModel->add();
|
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-09-25 18:05:48 +00:00
|
|
|
if(editMode == NONE)
|
|
|
|
enableEdition();
|
2013-05-22 17:52:38 +00:00
|
|
|
weightModel->add();
|
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-11-02 01:20:02 +00:00
|
|
|
TagCompletionModel::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-12-03 20:44:48 +00:00
|
|
|
hideMessage();
|
2013-12-28 01:26:22 +00:00
|
|
|
ui.equipmentTab->setEnabled(true);
|
2013-09-19 00:56:53 +00:00
|
|
|
/* now figure out if things have changed */
|
2013-11-26 17:44:18 +00:00
|
|
|
if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
|
2013-10-03 18:54:25 +00:00
|
|
|
if (notesBackup[NULL].notes != ui.notes->toPlainText() ||
|
|
|
|
notesBackup[NULL].location != ui.location->text())
|
2013-09-19 00:56:53 +00:00
|
|
|
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.
|
2013-11-11 23:21:45 +00:00
|
|
|
updateGpsCoordinates(curr);
|
2013-10-03 18:54:25 +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].airtemp != ui.airtemp->text() ||
|
|
|
|
notesBackup[curr].watertemp != ui.watertemp->text() ||
|
2013-11-17 11:31:09 +00:00
|
|
|
notesBackup[curr].datetime != ui.dateTimeEdit->dateTime().toString() ||
|
2013-11-02 01:20:02 +00:00
|
|
|
notesBackup[curr].visibility != ui.rating->currentStars() ||
|
|
|
|
notesBackup[curr].tags != ui.tagWidget->text()) {
|
2013-09-19 00:56:53 +00:00
|
|
|
mark_divelist_changed(TRUE);
|
2013-09-20 23:41:42 +00:00
|
|
|
}
|
2013-10-03 18:54:25 +00:00
|
|
|
if (notesBackup[curr].location != ui.location->text() ||
|
|
|
|
notesBackup[curr].coordinates != ui.coordinates->text()) {
|
2013-09-19 00:56:53 +00:00
|
|
|
mainWindow()->globe()->reload();
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-09-25 17:57:41 +00:00
|
|
|
|
2013-11-02 01:20:02 +00:00
|
|
|
if (notesBackup[curr].tags != ui.tagWidget->text())
|
|
|
|
saveTags();
|
2013-11-14 09:36:21 +00:00
|
|
|
if (editMode == MANUALLY_ADDED_DIVE) {
|
|
|
|
DivePlannerPointsModel::instance()->copyCylinders(curr);
|
|
|
|
} else if (editMode != ADD && cylindersModel->changed) {
|
2013-09-25 17:57:41 +00:00
|
|
|
mark_divelist_changed(TRUE);
|
2013-09-25 17:59:11 +00:00
|
|
|
Q_FOREACH (dive *d, notesBackup.keys()) {
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2013-12-14 17:20:37 +00:00
|
|
|
if (notesBackup.keys().count() > 1)
|
|
|
|
// only copy the cylinder type, none of the other values
|
|
|
|
d->cylinder[i].type = multiEditEquipmentPlaceholder.cylinder[i].type;
|
|
|
|
else
|
|
|
|
d->cylinder[i] = multiEditEquipmentPlaceholder.cylinder[i];
|
2013-09-25 17:57:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (weightModel->changed) {
|
2013-09-25 17:30:03 +00:00
|
|
|
mark_divelist_changed(TRUE);
|
2013-09-25 17:59:11 +00:00
|
|
|
Q_FOREACH (dive *d, notesBackup.keys()) {
|
2013-10-01 13:52:23 +00:00
|
|
|
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
|
|
|
d->weightsystem[i] = multiEditEquipmentPlaceholder.weightsystem[i];
|
2013-09-25 17:57:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-19 14:45:01 +00:00
|
|
|
}
|
2013-11-19 22:16:33 +00:00
|
|
|
if (current_dive->divetrip) {
|
|
|
|
current_dive->divetrip->when = current_dive->when;
|
|
|
|
find_new_trip_start_time(current_dive->divetrip);
|
|
|
|
}
|
2013-11-01 15:48:34 +00:00
|
|
|
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
2013-09-19 04:33:39 +00:00
|
|
|
// clean up the dive data (get duration, depth information from samples)
|
|
|
|
fixup_dive(current_dive);
|
2013-09-22 14:00:14 +00:00
|
|
|
if (dive_table.nr == 1)
|
|
|
|
current_dive->number = 1;
|
2013-11-12 05:21:50 +00:00
|
|
|
else if (selected_dive == dive_table.nr - 1 && get_dive(dive_table.nr - 2)->number)
|
2013-09-20 12:14:25 +00:00
|
|
|
current_dive->number = get_dive(dive_table.nr - 2)->number + 1;
|
2013-09-19 04:33:39 +00:00
|
|
|
DivePlannerPointsModel::instance()->cancelPlan();
|
|
|
|
mainWindow()->showProfile();
|
2013-09-20 12:53:06 +00:00
|
|
|
mark_divelist_changed(TRUE);
|
2013-11-09 00:09:46 +00:00
|
|
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
2013-09-19 04:33:39 +00:00
|
|
|
}
|
2013-12-02 04:17:17 +00:00
|
|
|
// each dive that was selected might have had the temperatures in its active divecomputer changed
|
|
|
|
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive
|
|
|
|
Q_FOREACH(dive *d, notesBackup.keys()) {
|
2013-12-03 23:17:38 +00:00
|
|
|
if (d)
|
|
|
|
fixup_dive(d);
|
2013-12-02 04:17:17 +00:00
|
|
|
}
|
2013-12-12 01:08:56 +00:00
|
|
|
int scrolledBy = mainWindow()->dive_list()->verticalScrollBar()->sliderPosition();
|
2013-09-25 17:36:59 +00:00
|
|
|
resetPallete();
|
2013-12-03 23:25:20 +00:00
|
|
|
if(editMode == ADD || editMode == MANUALLY_ADDED_DIVE){
|
2013-12-03 22:34:05 +00:00
|
|
|
mainWindow()->dive_list()->unselectDives();
|
|
|
|
struct dive *d = get_dive(dive_table.nr -1 );
|
2013-12-10 05:17:15 +00:00
|
|
|
// mark the dive as remembered (abusing the selected flag)
|
|
|
|
// and then clear that flag out on the other side of the sort_table()
|
2013-12-03 22:34:05 +00:00
|
|
|
d->selected = true;
|
|
|
|
sort_table(&dive_table);
|
|
|
|
int i = 0;
|
|
|
|
for_each_dive(i,d){
|
2013-12-10 05:17:15 +00:00
|
|
|
if (d->selected) {
|
|
|
|
d->selected = false;
|
|
|
|
break;
|
|
|
|
}
|
2013-12-03 22:34:05 +00:00
|
|
|
}
|
2013-12-03 23:25:20 +00:00
|
|
|
editMode = NONE;
|
|
|
|
mainWindow()->refreshDisplay();
|
2013-12-03 22:34:05 +00:00
|
|
|
mainWindow()->dive_list()->selectDive( i, true );
|
2013-12-10 05:17:15 +00:00
|
|
|
} else {
|
2013-12-03 23:25:20 +00:00
|
|
|
editMode = NONE;
|
2013-12-03 22:34:05 +00:00
|
|
|
mainWindow()->dive_list()->rememberSelection();
|
|
|
|
sort_table(&dive_table);
|
|
|
|
mainWindow()->refreshDisplay();
|
|
|
|
mainWindow()->dive_list()->restoreSelection();
|
|
|
|
}
|
2013-12-12 01:08:56 +00:00
|
|
|
mainWindow()->dive_list()->verticalScrollBar()->setSliderPosition(scrolledBy);
|
2013-12-19 22:23:40 +00:00
|
|
|
mainWindow()->dive_list()->setFocus();
|
2013-09-25 17:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::resetPallete()
|
|
|
|
{
|
2013-08-16 18:38:18 +00:00
|
|
|
QPalette p;
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.buddy->setPalette(p);
|
|
|
|
ui.notes->setPalette(p);
|
|
|
|
ui.location->setPalette(p);
|
|
|
|
ui.coordinates->setPalette(p);
|
|
|
|
ui.divemaster->setPalette(p);
|
|
|
|
ui.suit->setPalette(p);
|
|
|
|
ui.airtemp->setPalette(p);
|
|
|
|
ui.watertemp->setPalette(p);
|
|
|
|
ui.dateTimeEdit->setPalette(p);
|
2013-11-02 01:20:02 +00:00
|
|
|
ui.tagWidget->setPalette(p);
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 16:31:52 +00:00
|
|
|
#define EDIT_TEXT2(what, text) \
|
2013-12-16 22:50:42 +00:00
|
|
|
textByteArray = text.toUtf8(); \
|
2013-08-16 16:31:52 +00:00
|
|
|
free(what);\
|
|
|
|
what = strdup(textByteArray.data());
|
|
|
|
|
|
|
|
#define EDIT_TEXT(what, text) \
|
2013-12-16 22:50:42 +00:00
|
|
|
QByteArray textByteArray = text.toUtf8(); \
|
2013-08-16 16:31:52 +00:00
|
|
|
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-11-12 05:41:29 +00:00
|
|
|
EditMode lastMode = editMode;
|
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-11-26 17:44:18 +00:00
|
|
|
if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1){
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.notes->setText(notesBackup[NULL].notes );
|
|
|
|
ui.location->setText(notesBackup[NULL].location);
|
2013-11-08 09:15:04 +00:00
|
|
|
} else {
|
2013-11-12 05:41:29 +00:00
|
|
|
if (lastMode == ADD) {
|
2013-09-24 19:32:18 +00:00
|
|
|
// clean up
|
|
|
|
DivePlannerPointsModel::instance()->cancelPlan();
|
2013-11-12 05:41:29 +00:00
|
|
|
} else if (lastMode == MANUALLY_ADDED_DIVE ) {
|
2013-11-18 19:55:56 +00:00
|
|
|
// when we tried to edit a manually added dive, we destroyed
|
|
|
|
// the dive we edited, so let's just restore it from backup
|
|
|
|
DivePlannerPointsModel::instance()->restoreBackupDive();
|
2013-11-01 18:06:03 +00:00
|
|
|
}
|
2013-08-16 16:31:52 +00:00
|
|
|
struct dive *curr = current_dive;
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.notes->setText(notesBackup[curr].notes );
|
|
|
|
ui.location->setText(notesBackup[curr].location);
|
|
|
|
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);
|
|
|
|
ui.airtemp->setText(notesBackup[curr].airtemp);
|
|
|
|
ui.watertemp->setText(notesBackup[curr].watertemp);
|
2013-11-02 01:20:02 +00:00
|
|
|
ui.tagWidget->setText(notesBackup[curr].tags);
|
2013-11-13 13:23:59 +00:00
|
|
|
// it's a little harder to do the right thing for the date time widget
|
|
|
|
if (curr) {
|
2013-11-17 11:31:09 +00:00
|
|
|
ui.dateTimeEdit->setDateTime(QDateTime::fromString(notesBackup[curr].datetime));
|
2013-11-13 13:23:59 +00:00
|
|
|
} else {
|
|
|
|
QLineEdit *le = ui.dateTimeEdit->findChild<QLineEdit*>();
|
|
|
|
le->setText("");
|
|
|
|
}
|
2013-08-16 16:31:52 +00:00
|
|
|
|
|
|
|
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-09-25 17:10:15 +00:00
|
|
|
|
|
|
|
// maybe this is a place for memset?
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
mydive->cylinder[i] = notesBackup[mydive].cylinders[i];
|
|
|
|
}
|
|
|
|
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
2013-10-03 23:04:51 +00:00
|
|
|
mydive->weightsystem[i] = notesBackup[mydive].weightsystem[i];
|
2013-09-25 17:10:15 +00:00
|
|
|
}
|
2013-08-16 16:31:52 +00:00
|
|
|
}
|
2013-11-11 23:21:45 +00:00
|
|
|
updateGpsCoordinates(curr);
|
2013-11-14 08:52:03 +00:00
|
|
|
if (lastMode == ADD) {
|
|
|
|
delete_single_dive(selected_dive);
|
|
|
|
mainWindow()->dive_list()->reload(DiveTripModel::CURRENT);
|
|
|
|
mainWindow()->dive_list()->restoreSelection();
|
|
|
|
}
|
2013-11-06 01:15:19 +00:00
|
|
|
if (selected_dive >= 0) {
|
2013-10-09 06:24:44 +00:00
|
|
|
multiEditEquipmentPlaceholder = *get_dive(selected_dive);
|
|
|
|
cylindersModel->setDive(&multiEditEquipmentPlaceholder);
|
|
|
|
weightModel->setDive(&multiEditEquipmentPlaceholder);
|
|
|
|
} else {
|
|
|
|
cylindersModel->clear();
|
|
|
|
weightModel->clear();
|
2013-11-13 13:23:59 +00:00
|
|
|
setEnabled(false);
|
2013-10-09 06:24:44 +00:00
|
|
|
}
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-09-19 02:23:04 +00:00
|
|
|
|
2013-12-03 20:44:48 +00:00
|
|
|
hideMessage();
|
2013-05-19 03:09:36 +00:00
|
|
|
mainWindow()->dive_list()->setEnabled(true);
|
2013-08-16 16:31:52 +00:00
|
|
|
notesBackup.clear();
|
2013-09-25 17:36:59 +00:00
|
|
|
resetPallete();
|
2013-11-14 08:52:03 +00:00
|
|
|
editMode = NONE;
|
2013-11-29 21:11:17 +00:00
|
|
|
mainWindow()->globe()->reload();
|
2013-11-12 05:41:29 +00:00
|
|
|
if (lastMode == ADD || lastMode == MANUALLY_ADDED_DIVE) {
|
2013-09-24 19:32:18 +00:00
|
|
|
// more clean up
|
|
|
|
updateDiveInfo(selected_dive);
|
2013-09-20 03:58:53 +00:00
|
|
|
mainWindow()->showProfile();
|
2013-11-14 08:52:03 +00:00
|
|
|
// we already reloaded the divelist above, so don't recreate it or we'll lose the selection
|
|
|
|
mainWindow()->refreshDisplay(false);
|
2013-11-09 00:09:46 +00:00
|
|
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
2013-09-20 03:58:53 +00:00
|
|
|
}
|
2013-12-19 22:23:40 +00:00
|
|
|
mainWindow()->dive_list()->setFocus();
|
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;
|
2013-12-24 11:49:38 +00:00
|
|
|
qreal h, s, l, a;
|
|
|
|
qApp->palette().color(QPalette::Text).getHslF(&h, &s, &l, &a);
|
|
|
|
p.setBrush(QPalette::Base, ( l <= 0.3 ) ? QColor(Qt::yellow).lighter()
|
|
|
|
:( l <= 0.6 ) ? QColor(Qt::yellow).light()
|
|
|
|
:/* else */ QColor(Qt::yellow).darker(300)
|
|
|
|
);
|
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) );
|
2013-10-03 18:54:25 +00:00
|
|
|
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) );
|
2013-10-03 18:54:25 +00:00
|
|
|
markChangedWidget(ui.divemaster);
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 23:41:42 +00:00
|
|
|
void MainTab::on_airtemp_textChanged(const QString& text)
|
|
|
|
{
|
2013-11-29 20:05:21 +00:00
|
|
|
EDIT_SELECTED_DIVES( select_dc(&mydive->dc)->airtemp.mkelvin = parseTemperatureToMkelvin(text) );
|
2013-10-03 18:54:25 +00:00
|
|
|
markChangedWidget(ui.airtemp);
|
2013-09-20 23:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_watertemp_textChanged(const QString& text)
|
|
|
|
{
|
2013-11-29 20:05:21 +00:00
|
|
|
EDIT_SELECTED_DIVES( select_dc(&mydive->dc)->watertemp.mkelvin = parseTemperatureToMkelvin(text) );
|
2013-10-03 18:54:25 +00:00
|
|
|
markChangedWidget(ui.watertemp);
|
2013-09-20 23:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime)
|
|
|
|
{
|
2013-11-30 07:35:15 +00:00
|
|
|
QDateTime dateTimeUtc(datetime);
|
|
|
|
dateTimeUtc.setTimeSpec(Qt::UTC);
|
|
|
|
EDIT_SELECTED_DIVES( mydive->when = dateTimeUtc.toTime_t() );
|
2013-10-03 18:54:25 +00:00
|
|
|
markChangedWidget(ui.dateTimeEdit);
|
2013-09-20 23:41:42 +00:00
|
|
|
}
|
|
|
|
|
2013-11-02 01:20:02 +00:00
|
|
|
void MainTab::saveTags()
|
|
|
|
{
|
|
|
|
EDIT_SELECTED_DIVES(
|
|
|
|
QString tag;
|
|
|
|
taglist_clear(mydive->tag_list);
|
|
|
|
foreach (tag, ui.tagWidget->getBlockStringList())
|
|
|
|
taglist_add_tag(mydive->tag_list, tag.toAscii().data());
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_tagWidget_textChanged()
|
|
|
|
{
|
|
|
|
markChangedWidget(ui.tagWidget);
|
|
|
|
}
|
|
|
|
|
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-11-26 17:44:18 +00:00
|
|
|
if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
|
2013-06-14 16:17:46 +00:00
|
|
|
// we are editing a trip
|
2013-11-26 17:44:18 +00:00
|
|
|
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin();
|
2013-06-14 16:17:46 +00:00
|
|
|
EDIT_TEXT(currentTrip->location, text);
|
2013-09-19 04:33:39 +00:00
|
|
|
} else if (editMode == DIVE || editMode == ADD){
|
2013-10-03 18:54:25 +00:00
|
|
|
if (!ui.coordinates->isModified() ||
|
|
|
|
ui.coordinates->text().trimmed().isEmpty()) {
|
2013-09-19 16:37:44 +00:00
|
|
|
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 );
|
2013-11-11 23:21:45 +00:00
|
|
|
//Don't use updateGpsCoordinates() since we don't want to set modified state yet
|
2013-10-07 18:48:14 +00:00
|
|
|
ui.coordinates->setText(printGPSCoords(dive->latitude.udeg, dive->longitude.udeg));
|
2013-10-03 18:54:25 +00:00
|
|
|
markChangedWidget(ui.coordinates);
|
2013-09-19 16:37:44 +00:00
|
|
|
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-11-19 12:32:24 +00:00
|
|
|
mainWindow()->globe()->repopulateLabels();
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-10-03 18:54:25 +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) );
|
2013-10-03 18:54:25 +00:00
|
|
|
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-11-26 17:44:18 +00:00
|
|
|
if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
|
2013-06-14 16:17:46 +00:00
|
|
|
// we are editing a trip
|
2013-11-26 17:44:18 +00:00
|
|
|
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin();
|
2013-10-03 18:54:25 +00:00
|
|
|
EDIT_TEXT(currentTrip->notes, ui.notes->toPlainText());
|
2013-12-27 16:18:53 +00:00
|
|
|
} else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
2013-10-03 18:54:25 +00:00
|
|
|
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui.notes->toPlainText()) );
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-10-03 18:54:25 +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)
|
|
|
|
{
|
2013-12-23 22:56:40 +00:00
|
|
|
bool gpsChanged = false;
|
|
|
|
bool parsed = false;
|
|
|
|
EDIT_SELECTED_DIVES(gpsChanged |= gpsHasChanged(mydive, current_dive, text, &parsed));
|
2013-09-19 16:37:44 +00:00
|
|
|
if (gpsChanged) {
|
2013-10-03 18:54:25 +00:00
|
|
|
markChangedWidget(ui.coordinates);
|
2013-12-23 22:56:40 +00:00
|
|
|
} else if (!parsed) {
|
2013-09-19 16:37:44 +00:00
|
|
|
QPalette p;
|
|
|
|
p.setBrush(QPalette::Base, QColor(Qt::red).lighter());
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.coordinates->setPalette(p);
|
2013-09-19 16:37:44 +00:00
|
|
|
}
|
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-25 17:11:38 +00:00
|
|
|
if (editMode == NONE)
|
|
|
|
enableEdition();
|
|
|
|
|
2013-09-02 19:21:08 +00:00
|
|
|
if (index.isValid() && index.column() != CylindersModel::REMOVE)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.cylinders->edit(index);
|
2013-07-17 15:13:04 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 23:04:51 +00:00
|
|
|
void MainTab::editWeightWidget(const QModelIndex& index)
|
2013-07-17 15:13:04 +00:00
|
|
|
{
|
2013-09-25 17:11:38 +00:00
|
|
|
if (editMode == NONE)
|
|
|
|
enableEdition();
|
|
|
|
|
2013-09-02 19:21:08 +00:00
|
|
|
if (index.isValid() && index.column() != WeightModel::REMOVE)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.weights->edit(index);
|
2013-06-16 17:36:23 +00:00
|
|
|
}
|
2013-10-07 18:48:14 +00:00
|
|
|
|
|
|
|
QString MainTab::printGPSCoords(int lat, int lon)
|
|
|
|
{
|
|
|
|
unsigned int latdeg, londeg;
|
|
|
|
unsigned int ilatmin, ilonmin;
|
|
|
|
QString lath, lonh, result;
|
|
|
|
|
|
|
|
if (!lat && !lon)
|
|
|
|
return QString("");
|
|
|
|
|
|
|
|
lath = lat >= 0 ? tr("N") : tr("S");
|
|
|
|
lonh = lon >= 0 ? tr("E") : tr("W");
|
|
|
|
lat = abs(lat);
|
|
|
|
lon = abs(lon);
|
|
|
|
latdeg = lat / 1000000;
|
|
|
|
londeg = lon / 1000000;
|
|
|
|
ilatmin = (lat % 1000000) * 60;
|
|
|
|
ilonmin = (lon % 1000000) * 60;
|
|
|
|
result.sprintf("%s%u%s %2d.%05d\' , %s%u%s %2d.%05d\'",
|
2013-12-16 22:50:42 +00:00
|
|
|
lath.toUtf8().data(), latdeg, UTF8_DEGREE, ilatmin / 1000000, (ilatmin % 1000000) / 10,
|
|
|
|
lonh.toUtf8().data(), londeg, UTF8_DEGREE, ilonmin / 1000000, (ilonmin % 1000000) / 10);
|
2013-10-07 18:48:14 +00:00
|
|
|
return result;
|
|
|
|
}
|
2013-11-11 23:21:45 +00:00
|
|
|
|
2013-11-19 12:12:31 +00:00
|
|
|
void MainTab::updateCoordinatesText(qreal lat, qreal lon)
|
|
|
|
{
|
|
|
|
int ulat = rint(lat * 1000000);
|
|
|
|
int ulon = rint(lon * 1000000);
|
|
|
|
ui.coordinates->setText(printGPSCoords(ulat, ulon));
|
|
|
|
}
|
|
|
|
|
2013-11-11 23:21:45 +00:00
|
|
|
void MainTab::updateGpsCoordinates(const struct dive *dive)
|
|
|
|
{
|
2013-11-13 13:23:59 +00:00
|
|
|
if (dive) {
|
|
|
|
ui.coordinates->setText(printGPSCoords(dive->latitude.udeg, dive->longitude.udeg));
|
|
|
|
ui.coordinates->setModified(dive->latitude.udeg || dive->longitude.udeg);
|
|
|
|
} else {
|
|
|
|
ui.coordinates->clear();
|
|
|
|
}
|
2013-11-11 23:21:45 +00:00
|
|
|
}
|