diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-03-19 22:05:52 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | 4cb1ceefff96121331f63e1455d233b32b3d7680 (patch) | |
tree | 8ff4e229f4f4a19a5d420d415a254727eb9d2443 | |
parent | de579c1a1ad823fbc42d7e3122b77b03626283c3 (diff) | |
download | subsurface-4cb1ceefff96121331f63e1455d233b32b3d7680.tar.gz |
Undo: implement undo of dive date- and time-editing
This is different from the other editing commands, because
date and time editing may change the order of the dive list.
Therefore, this uses an already implemented dive list command.
The command is extended to send a divesEdited() signal.
This signal and the divesChanged() signal, which is used by
the dive list, will be unified in a later commit.
Update of the graphics is now not done via signals, a direct
call is performed in MainTab::divesEdited(). This simplifies
things.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 1 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 56 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.h | 2 |
3 files changed, 36 insertions, 23 deletions
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 8da0fab46..a901822f9 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -746,6 +746,7 @@ void ShiftTime::redoit() sort_dive_table(&trip->dives); // Keep the trip-table in order emit diveListNotifier.divesTimeChanged(trip, timeChanged, divesInTrip); }); + emit diveListNotifier.divesEdited(diveList, DiveField::DATETIME); // Negate the time-shift so that the next call does the reverse timeChanged = -timeChanged; diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 202c75071..7b0a06465 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -363,6 +363,11 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field) case DiveField::MODE: updateMode(current_dive); break; + case DiveField::DATETIME: + updateDateTime(current_dive); + MainWindow::instance()->graphics->dateTimeChanged(); + DivePlannerPointsModel::instance()->getDiveplan().when = current_dive->when; + break; default: break; } @@ -423,6 +428,16 @@ void MainTab::updateMode(struct dive *d) MainWindow::instance()->graphics->recalcCeiling(); } +void MainTab::updateDateTime(struct dive *d) +{ + // Subsurface always uses "local time" as in "whatever was the local time at the location" + // so all time stamps have no time zone information and are in UTC + QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*d->when, Qt::UTC); + localTime.setTimeSpec(Qt::UTC); + ui.dateEdit->setDate(localTime.date()); + ui.timeEdit->setTime(localTime.time()); +} + void MainTab::updateDiveInfo(bool clear) { ui.location->refreshDiveSiteCache(); @@ -464,12 +479,7 @@ void MainTab::updateDiveInfo(bool clear) ui.locationTags->clear(); } - // Subsurface always uses "local time" as in "whatever was the local time at the location" - // so all time stamps have no time zone information and are in UTC - QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC); - localTime.setTimeSpec(Qt::UTC); - ui.dateEdit->setDate(localTime.date()); - ui.timeEdit->setTime(localTime.time()); + updateDateTime(&displayed_dive); if (MainWindow::instance() && MainWindow::instance()->diveList->selectedTrips().count() == 1) { // Remember the tab selected for last dive if (lastSelectedDive) @@ -599,7 +609,6 @@ void MainTab::updateDiveInfo(bool clear) /* unset the special value text for date and time, just in case someone dove at midnight */ ui.dateEdit->setSpecialValueText(QString("")); ui.timeEdit->setSpecialValueText(QString("")); - } else { /* clear the fields */ clearTabs(); @@ -746,7 +755,7 @@ void MainTab::acceptChanges() struct dive *d; bool do_replot = false; - if(ui.location->hasFocus()) { + if (ui.location->hasFocus()) { this->setFocus(); } @@ -898,10 +907,6 @@ void MainTab::acceptChanges() invalidate_dive_cache(d); } } - - timestamp_t offset = displayed_dive.when - cd->when; - if (offset) - Command::shiftTime(selectedDives, (int)offset); } if (editMode == MANUALLY_ADDED_DIVE) { // we just added or edited the dive, let fixup_dive() make @@ -1117,28 +1122,35 @@ void MainTab::on_watertemp_editingFinished() current_dive->watertemp.mkelvin); } +// Editing of the dive time is different. If multiple dives are edited, +// all dives are shifted by an offset. +static void shiftTime(QDateTime &dateTime) +{ + timestamp_t when = dateTime.toTime_t(); + if (current_dive && current_dive->when != when) { + timestamp_t offset = current_dive->when - when; + Command::shiftTime(getSelectedDivesCurrentLast(), (int)offset); + } +} + void MainTab::on_dateEdit_dateChanged(const QDate &date) { - if (editMode == IGNORE || acceptingEdit == true) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - markChangedWidget(ui.dateEdit); - QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC); + QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*current_dive->when, Qt::UTC); dateTime.setTimeSpec(Qt::UTC); dateTime.setDate(date); - DivePlannerPointsModel::instance()->getDiveplan().when = displayed_dive.when = dateTime.toTime_t(); - emit dateTimeChanged(); + shiftTime(dateTime); } void MainTab::on_timeEdit_timeChanged(const QTime &time) { - if (editMode == IGNORE || acceptingEdit == true) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - markChangedWidget(ui.timeEdit); - QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC); + QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*current_dive->when, Qt::UTC); dateTime.setTimeSpec(Qt::UTC); dateTime.setTime(time); - DivePlannerPointsModel::instance()->getDiveplan().when = displayed_dive.when = dateTime.toTime_t(); - emit dateTimeChanged(); + shiftTime(dateTime); } void MainTab::copyTagsToDisplayedDive() diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 36f9a64a9..805618857 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -59,7 +59,6 @@ public: signals: void addDiveFinished(); - void dateTimeChanged(); void diveSiteChanged(); public slots: @@ -69,6 +68,7 @@ slots: void updateDiveInfo(bool clear = false); void updateNotes(const struct dive *d); void updateMode(struct dive *d); + void updateDateTime(struct dive *d); void updateDepthDuration(); void acceptChanges(); void rejectChanges(); |