summaryrefslogtreecommitdiffstats
path: root/qt-ui/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-27 11:32:18 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-27 15:09:47 -0700
commit12b9c756764cff2695a134d64d3ab78f32847e9f (patch)
tree64547d6b37561d832fb69651bf538d266d0c2474 /qt-ui/mainwindow.cpp
parent4e3793c05310009878a407d107b4ef330710c5f3 (diff)
downloadsubsurface-12b9c756764cff2695a134d64d3ab78f32847e9f.tar.gz
Planner: clean up the logic for starting up the planner
The existing code had no chance of every working - on so many levels. First unselect all dives, then extract data from a selected dive? Set up the cylinder data (which didn't work), and then clear the data again? What the heck. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r--qt-ui/mainwindow.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 8a452b320..4417ab673 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -377,9 +377,11 @@ void MainWindow::createFakeDiveForAddAndPlan()
dive->latitude.udeg = 0;
dive->longitude.udeg = 0;
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));
+ // select this new dive (but remember the old selection
+ ui.ListWidget->reload(DiveTripModel::CURRENT);
+ ui.ListWidget->rememberSelection();
+ ui.ListWidget->unselectDives();
+ ui.ListWidget->selectDives(QList<int>() << dive_table.nr - 1);
ui.InfoWidget->updateDiveInfo(selected_dive);
}
@@ -388,31 +390,23 @@ void MainWindow::on_actionDivePlanner_triggered()
if(!plannerStateClean())
return;
- dive_list()->rememberSelection();
- dive_list()->unselectDives();
-
+ // put us in PLAN mode
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
- DivePlannerPointsModel::instance()->clear();
- CylindersModel::instance()->clear();
- int i;
- struct dive *dive;
- for_each_dive (i, dive) {
- if (dive->selected) {
- DivePlannerPointsModel::instance()->copyCylindersFrom(dive);
- CylindersModel::instance()->copyFromDive(dive);
- break;
- }
- }
- createFakeDiveForAddAndPlan();
-
- ui.InfoWidget->setCurrentIndex(0);
- ui.infoPane->setCurrentIndex(MAINTAB);
-
ui.newProfile->setPlanState();
ui.infoPane->setCurrentIndex(PLANNERWIDGET);
+
+ // set up the staging dive and clean up the widgets
DivePlannerPointsModel::instance()->clear();
+
+ // setup the staging dive cylinders from the selected dive
+ if (current_dive) {
+ DivePlannerPointsModel::instance()->copyCylindersFrom(current_dive);
+ CylindersModel::instance()->copyFromDive(current_dive);
+ }
+
+ // create a simple starting dive, using the first gas from the just copied cylidners
+ createFakeDiveForAddAndPlan();
DivePlannerPointsModel::instance()->createSimpleDive(true);
- ui.ListWidget->reload(DiveTripModel::CURRENT);
}
void MainWindow::on_actionAddDive_triggered()