diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-19 22:35:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 12df9faaa2037b5155ebb84a7f6f6102491a0091 (patch) | |
tree | 33dcf0e400f669d088f1b20652e9c0c6f69aae2b /desktop-widgets/tab-widgets | |
parent | 61467ea0d59b04f141a68452ee16c70760421d72 (diff) | |
download | subsurface-12df9faaa2037b5155ebb84a7f6f6102491a0091.tar.gz |
Undo: implement undo of manual dive-creation
Play manual addition of dives via an UndoCommand. Since this does in
large parts the same thing as undo/redo of dive deletion (just the
other way round and only a single instead of multiple dive), factor
out the functions that add/delete dives and take care of trips.
The UI-interaction is just mindless copy&paste and will have to
be adapted.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 766d32414..e5974a834 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -26,6 +26,7 @@ #include "core/subsurface-string.h" #include "core/gettextfromc.h" #include "desktop-widgets/locationinformation.h" +#include "desktop-widgets/undocommands.h" #include "TabDiveExtraInfo.h" #include "TabDiveInformation.h" @@ -788,23 +789,30 @@ void MainTab::acceptChanges() hideMessage(); ui.equipmentTab->setEnabled(true); if (editMode == ADD) { - // We need to add the dive we just created to the dive list and select it. - // Easy, right? - struct dive *added_dive = clone_dive(&displayed_dive); - record_dive(added_dive); - addedId = added_dive->id; // make sure that the dive site is handled as well - updateDiveSite(ui.location->currDiveSiteUuid(), added_dive); + updateDiveSite(ui.location->currDiveSiteUuid(), &displayed_dive); - // unselect everything as far as the UI is concerned and select the new - // dive - we'll have to undo/redo this later after we resort the dive_table - // but we need the dive selected for the middle part of this function - this - // way we can reuse the code used for editing dives - MainWindow::instance()->dive_list()->unselectDives(); - selected_dive = get_divenr(added_dive); - amount_selected = 1; - // finally, make sure we get the tags - saveTags(); + UndoAddDive *undoCommand = new UndoAddDive(&displayed_dive); + MainWindow::instance()->undoStack->push(undoCommand); + + editMode = NONE; + MainWindow::instance()->exitEditState(); + cylindersModel->changed = false; + weightModel->changed = false; + MainWindow::instance()->setEnabledToolbar(true); + acceptingEdit = false; + ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); + emit addDiveFinished(); + MainWindow::instance()->dive_list()->reload(DiveTripModel::CURRENT, true); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); + int scrolledBy = MainWindow::instance()->dive_list()->verticalScrollBar()->sliderPosition(); + MainWindow::instance()->dive_list()->verticalScrollBar()->setSliderPosition(scrolledBy); + MainWindow::instance()->dive_list()->setFocus(); + resetPallete(); + saveTags(QVector<dive *>{ &displayed_dive }); + displayed_dive.divetrip = nullptr; // Should not be necessary, just in case! + Command::addDive(&displayed_dive, autogroup, true); + return; } else if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { /* now figure out if things have changed */ if (displayedTrip.notes && !same_string(displayedTrip.notes, currentTrip->notes)) { @@ -957,7 +965,7 @@ void MainTab::acceptChanges() current_dive->divetrip->when = current_dive->when; find_new_trip_start_time(current_dive->divetrip); } - if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { + if (editMode == MANUALLY_ADDED_DIVE) { // we just added or edited the dive, let fixup_dive() make // sure we get the max. depth right current_dive->maxdepth.mm = current_dc->maxdepth.mm = 0; @@ -969,7 +977,7 @@ void MainTab::acceptChanges() } int scrolledBy = MainWindow::instance()->dive_list()->verticalScrollBar()->sliderPosition(); resetPallete(); - if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { + if (editMode == MANUALLY_ADDED_DIVE) { // since a newly added dive could be in the middle of the dive_table we need // to resort the dive list and make sure the newly added dive gets selected again sort_table(&dive_table); @@ -980,7 +988,6 @@ void MainTab::acceptChanges() editMode = NONE; MainWindow::instance()->refreshDisplay(); MainWindow::instance()->graphics()->replot(); - emit addDiveFinished(); } else { editMode = NONE; if (do_replot) |