summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/diveplanner.cpp13
-rw-r--r--qt-ui/maintab.cpp10
-rw-r--r--qt-ui/mainwindow.cpp8
3 files changed, 20 insertions, 11 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 27c80fd03..76ea82e75 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1251,8 +1251,9 @@ void DivePlannerPointsModel::cancelPlan()
}
clear();
emit planCanceled();
+ if (mode != ADD)
+ free(stagingDive);
setPlanMode(NOTHING);
- free(stagingDive);
stagingDive = NULL;
CylindersModel::instance()->setDive(current_dive);
CylindersModel::instance()->update();
@@ -1265,9 +1266,13 @@ DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
void DivePlannerPointsModel::clear()
{
- if (!stagingDive)
- stagingDive = alloc_dive();
- memset(stagingDive->cylinder, 0, MAX_CYLINDERS * sizeof(cylinder_t));
+ if (mode == ADD) {
+ stagingDive = current_dive;
+ } else {
+ if (!stagingDive)
+ stagingDive = alloc_dive();
+ memset(stagingDive->cylinder, 0, MAX_CYLINDERS * sizeof(cylinder_t));
+ }
CylindersModel::instance()->setDive(stagingDive);
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
divepoints.clear();
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index aa9dc6295..d5199d447 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -497,9 +497,15 @@ void MainTab::acceptChanges()
fixup_dive(current_dive);
if (dive_table.nr == 1)
current_dive->number = 1;
- else if (current_dive == get_dive(dive_table.nr - 1) && get_dive(dive_table.nr - 2)->number)
+ else if (selected_dive == dive_table.nr - 1 && get_dive(dive_table.nr - 2)->number)
current_dive->number = get_dive(dive_table.nr - 2)->number + 1;
DivePlannerPointsModel::instance()->cancelPlan();
+ // now make sure the selection logic is in a sane state
+ // it's ok to hold on to the dive pointer for this short stretch of code
+ // unselectDives() doesn't mess with the dive_table at all
+ struct dive *addedDive = current_dive;
+ mainWindow()->dive_list()->unselectDives();
+ mainWindow()->dive_list()->selectDive(addedDive, true, true);
mainWindow()->showProfile();
mainWindow()->refreshDisplay();
mark_divelist_changed(TRUE);
@@ -548,8 +554,8 @@ void MainTab::rejectChanges()
} else {
if (editMode == ADD) {
// clean up
- delete_single_dive(selected_dive);
DivePlannerPointsModel::instance()->cancelPlan();
+ delete_single_dive(selected_dive);
} else if (editMode == MANUALLY_ADDED_DIVE ) {
DivePlannerPointsModel::instance()->undoEdition(); // that's BOGUS... just copy the original dive back and be done with it...
}
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 348d08c44..a0bbcf04b 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -283,11 +283,7 @@ void MainWindow::on_actionAddDive_triggered()
}
// clear the selection
- for (int i = 0; i < dive_table.nr; i++) {
- struct dive *d = get_dive(i);
- if (d && d->selected)
- deselect_dive(i);
- }
+ dive_list()->unselectDives();
disableDcShortcuts();
DivePlannerPointsModel::instance()->clear();
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
@@ -296,6 +292,8 @@ void MainWindow::on_actionAddDive_triggered()
dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset();
dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file
record_dive(dive);
+ // this isn't in the UI yet, so let's call the C helper function - we'll fix this up when
+ // accepting the dive
select_dive(get_divenr(dive));
ui.InfoWidget->updateDiveInfo(selected_dive);
ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner.