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>
This commit is contained in:
Dirk Hohndel 2014-07-06 12:36:25 -07:00
parent d97c49ba39
commit cd5b2a372f
3 changed files with 15 additions and 61 deletions

View file

@ -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();
}

View file

@ -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

View file

@ -394,7 +394,7 @@ bool MainWindow::plannerStateClean()
void MainWindow::planCanceled()
{
showProfile();
refreshDisplay();
refreshDisplay(false);
}
void MainWindow::planCreated()