diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-07-06 12:36:25 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-07-06 12:50:30 -0700 |
commit | cd5b2a372f70198823a7ca82a51fa38a977f1a80 (patch) | |
tree | eaa8461ae3efa9c7056e89652411e4373854bd93 | |
parent | d97c49ba39833275cf15a2753cb084efdfd5c923 (diff) | |
download | subsurface-cd5b2a372f70198823a7ca82a51fa38a977f1a80.tar.gz |
UI restructure: cleanup the code when canceling an edit
This was way too complicated because we used to edit a "live" dive that
was on the dive list. All we really need to do is systematically make
sure that all the widgets are in the correct state.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/diveplanner.cpp | 7 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 67 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 2 |
3 files changed, 15 insertions, 61 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 15cdc5409..2a7bd8d40 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -908,13 +908,6 @@ void DivePlannerPointsModel::cancelPlan() setPlanMode(NOTHING); diveplan.dp = NULL; - - - - // somewhere, somehow we need to make sure that the current_dive is displayed again - - - emit planCanceled(); } diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 0f8d885a8..5dd5a53f4 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -839,64 +839,25 @@ void MainTab::rejectChanges() editMode = NONE; tabBar()->setTabIcon(0, QIcon()); // Notes tabBar()->setTabIcon(1, QIcon()); // Equipment - - if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() != 1) { - if (lastMode == ADD) { - // clean up - DivePlannerPointsModel::instance()->cancelPlan(); - hideMessage(); - resetPallete(); - return; - } else if (lastMode == MANUALLY_ADDED_DIVE) { - // 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(); - } - if (selected_dive >= 0) { - copy_dive(current_dive, &displayed_dive); - cylindersModel->updateDive(); - weightModel->updateDive(); - } else { - cylindersModel->clear(); - weightModel->clear(); - setEnabled(false); - } - } -#if 0 // this makes no sense anymore - but let's make sure I think this through - // now let's avoid memory leaks - if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { - if (displayed_dive.location != current_dive->divetrip->location) - free(displayed_dive.location); - if (displayed_dive.notes != current_dive->divetrip->notes) - free(displayed_dive.notes); - } else { - struct dive *cd = current_dive; - FREE_IF_DIFFERENT(tag_list); - FREE_IF_DIFFERENT(location); - FREE_IF_DIFFERENT(buddy); - FREE_IF_DIFFERENT(divemaster); - FREE_IF_DIFFERENT(notes); - FREE_IF_DIFFERENT(suit); - } -#endif hideMessage(); - MainWindow::instance()->dive_list()->setEnabled(true); - ui.dateEdit->setEnabled(true); resetPallete(); - MainWindow::instance()->globe()->reload(); - if (lastMode == MANUALLY_ADDED_DIVE) { - // more clean up - updateDiveInfo(); - MainWindow::instance()->showProfile(); - // we already reloaded the divelist above, so don't recreate it or we'll lose the selection - MainWindow::instance()->refreshDisplay(false); - } - MainWindow::instance()->dive_list()->setFocus(); + // no harm done to call cancelPlan even if we were not in ADD or PLAN mode... + DivePlannerPointsModel::instance()->cancelPlan(); + + // now make sure that the correct dive is displayed + if (selected_dive >= 0) + copy_dive(current_dive, &displayed_dive); + else + clear_dive(&displayed_dive); + updateDiveInfo(selected_dive < 0); // the user could have edited the location and then canceled the edit // let's get the correct location back in view MainWindow::instance()->globe()->centerOnCurrentDive(); - DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); - updateDiveInfo(); + MainWindow::instance()->globe()->reload(); + // show the profile and dive info + MainWindow::instance()->graphics()->replot(); + cylindersModel->updateDive(); + weightModel->updateDive(); } #undef EDIT_TEXT2 diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 9efeafa12..6a212ae6a 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -394,7 +394,7 @@ bool MainWindow::plannerStateClean() void MainWindow::planCanceled() { showProfile(); - refreshDisplay(); + refreshDisplay(false); } void MainWindow::planCreated() |