From a8888eaf26c9355f3f2d20c24526489e17d3404a Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 20 Sep 2013 16:41:42 -0700 Subject: Allow editing of date & time and air & water temperatures Add two more rows to the widget - this is getting quite busy. There still is some weirdness where the focus isn't returned where it should be and a few other details, but overall getting there. Added helper functions to parse a temperature and to deal with the timezone offset - with that latter one I also fixed the time offset bug in the planner. Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 3 ++- qt-ui/maintab.cpp | 60 +++++++++++++++++++++++++++++++++++++---- qt-ui/maintab.h | 6 +++++ qt-ui/maintab.ui | 74 ++++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 121 insertions(+), 22 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 87edbbc8a..c5649e19e 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -11,6 +11,7 @@ #include "../dive.h" #include "../divelist.h" #include "../planner.h" +#include "helpers.h" #include #include @@ -1056,7 +1057,7 @@ void DivePlannerPointsModel::setLastStop6m(bool value) void DivePlannerPointsModel::setStartTime(const QTime& t) { - diveplan.when = (t.msec() + QDateTime::currentMSecsSinceEpoch()) / 1000 - Qt::OffsetFromUTC * 3600; + diveplan.when = (t.msec() + QDateTime::currentMSecsSinceEpoch()) / 1000 - gettimezoneoffset(); emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1)); } diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 779a9fc75..b9a539fef 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -56,6 +56,9 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), 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); QList statisticsTabWidgets = ui->statisticsTab->children(); Q_FOREACH(QObject* obj, statisticsTabWidgets) { @@ -142,6 +145,9 @@ void MainTab::enableEdition() notesBackup[mydive].latitude = mydive->latitude; notesBackup[mydive].longitude = mydive->longitude; notesBackup[mydive].coordinates = ui->coordinates->text(); + notesBackup[mydive].airtemp = get_temperature_string(mydive->airtemp, true); + notesBackup[mydive].watertemp = get_temperature_string(mydive->watertemp, true); + notesBackup[mydive].datetime = QDateTime::fromTime_t(mydive->when - gettimezoneoffset()).toString(QString("M/d/yy h:mm")); } editMode = DIVE; } @@ -149,7 +155,12 @@ void MainTab::enableEdition() bool MainTab::eventFilter(QObject* object, QEvent* event) { - if (isEnabled() && event->type() == QEvent::FocusIn && (object == ui->rating || object == ui->visibility)){ + if (isEnabled() && event->type() == QEvent::KeyPress && object == ui->dateTimeEdit) { + tabBar()->setTabIcon(currentIndex(), QIcon(":warning")); + enableEdition(); + } + + if (isEnabled() && event->type() == QEvent::FocusIn && (object == ui->rating || object == ui->visibility)) { tabBar()->setTabIcon(currentIndex(), QIcon(":warning")); enableEdition(); } @@ -197,6 +208,13 @@ void MainTab::clearStats() else \ ui->field->setText(d->field) +#define UPDATE_TEMP(d, field) \ + if (!d || d->field.mkelvin == 0) \ + ui->field->setText(""); \ + else \ + ui->field->setText(get_temperature_string(d->field, TRUE)); + + void MainTab::updateDiveInfo(int dive) { if(!isEnabled()) @@ -221,7 +239,9 @@ void MainTab::updateDiveInfo(int dive) UPDATE_TEXT(d, suit); UPDATE_TEXT(d, divemaster); UPDATE_TEXT(d, buddy); - + UPDATE_TEMP(d, airtemp); + UPDATE_TEMP(d, watertemp); + ui->dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when - gettimezoneoffset())); if (d) { char buffer[256]; print_gps_coordinates(buffer, sizeof buffer, d->latitude.udeg, d->longitude.udeg); @@ -385,10 +405,13 @@ void MainTab::acceptChanges() 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()) - + notesBackup[curr].rating != ui->visibility->currentStars() || + notesBackup[curr].airtemp != ui->airtemp->text() || + notesBackup[curr].watertemp != ui->watertemp->text() || + notesBackup[curr].datetime != ui->dateTimeEdit->dateTime().toString(QString("M/d/yy h:mm")) || + 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(); @@ -414,6 +437,9 @@ void MainTab::acceptChanges() ui->coordinates->setPalette(p); ui->divemaster->setPalette(p); ui->suit->setPalette(p); + ui->airtemp->setPalette(p); + ui->watertemp->setPalette(p); + ui->dateTimeEdit->setPalette(p); } #define EDIT_TEXT2(what, text) \ @@ -445,6 +471,9 @@ void MainTab::rejectChanges() 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); + ui->dateTimeEdit->setDateTime(QDateTime::fromString(notesBackup[curr].datetime, QString("M/d/y h:mm"))); struct dive *mydive; for (int i = 0; i < dive_table.nr; i++) { @@ -480,6 +509,9 @@ void MainTab::rejectChanges() ui->coordinates->setPalette(p); ui->divemaster->setPalette(p); ui->suit->setPalette(p); + ui->airtemp->setPalette(p); + ui->watertemp->setPalette(p); + ui->dateTimeEdit->setPalette(p); if (editMode == ADD) { // clean up delete_single_dive(selected_dive); @@ -525,6 +557,24 @@ void MainTab::on_divemaster_textChanged(const QString& text) markChangedWidget(ui->divemaster); } +void MainTab::on_airtemp_textChanged(const QString& text) +{ + EDIT_SELECTED_DIVES( mydive->airtemp.mkelvin = parseTemperatureToMkelvin(text) ); + markChangedWidget(ui->airtemp); +} + +void MainTab::on_watertemp_textChanged(const QString& text) +{ + EDIT_SELECTED_DIVES( mydive->watertemp.mkelvin = parseTemperatureToMkelvin(text) ); + markChangedWidget(ui->watertemp); +} + +void MainTab::on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime) +{ + EDIT_SELECTED_DIVES( mydive->when = datetime.toTime_t() + gettimezoneoffset() ); + markChangedWidget(ui->dateTimeEdit); +} + void MainTab::on_location_textChanged(const QString& text) { if (editMode == NONE) diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 041611b26..1970bad1f 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -21,6 +21,9 @@ namespace Ui } struct NotesBackup{ + QString airtemp; + QString watertemp; + QString datetime; QString location; QString coordinates; degrees_t latitude; @@ -64,6 +67,9 @@ public slots: void on_buddy_textChanged(const QString& text); void on_suit_textChanged(const QString& text); void on_notes_textChanged(); + void on_airtemp_textChanged(const QString& text); + void on_watertemp_textChanged(const QString& text); + void on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime); void on_rating_valueChanged(int value); void on_visibility_valueChanged(int value); void editCylinderWidget(const QModelIndex& index); diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index bf648dd5b..789ac3d7b 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -7,7 +7,7 @@ 0 0 505 - 459 + 610 @@ -21,70 +21,70 @@ Dive Notes - + false - + false - + Location - + false - + false - + false - + false - + Divemaster - + Buddy - + @@ -102,21 +102,21 @@ - + Suit - + Notes - + @@ -126,23 +126,65 @@ - + Coordinates + + + + Starttime + + + - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + M/d/yy h:mm + + + true + + + + + + + + + false + + + + + + + false + + + + + + + + + air / water Temperatures + + + -- cgit v1.2.3-70-g09d2