From 3c4439ee27bfb794c69de801caed50353e6719b7 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 4 Jul 2014 07:14:16 -0700 Subject: UI restructure: simplify setup of add and plan mode Recreate the helper function (which now does something fairly different) to share the common code between the two modes. Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 33 +++++++++++++++------------------ qt-ui/mainwindow.h | 2 +- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 5be757d47..9efeafa12 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -426,6 +426,18 @@ void MainWindow::printPlan() #endif } +void MainWindow::setupForAddAndPlan(const char *model) +{ + // clean out the dive and give it an id and the correct dc model + clear_dive(&displayed_dive); + displayed_dive.id = dive_getUniqID(&displayed_dive); + displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600; + displayed_dive.dc.model = model; // don't translate! this is stored in the XML file + // setup the dive cylinders + DivePlannerPointsModel::instance()->clear(); + DivePlannerPointsModel::instance()->setupCylinders(); +} + void MainWindow::on_actionDivePlanner_triggered() { if(!plannerStateClean()) @@ -435,19 +447,11 @@ void MainWindow::on_actionDivePlanner_triggered() // put us in PLAN mode DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); - // clean out the dive and give it an id and the correct dc model - clear_dive(&displayed_dive); - displayed_dive.id = dive_getUniqID(&displayed_dive); - displayed_dive.dc.model = "planned dive"; // don't translate! this is stored in the XML file - ui.newProfile->setPlanState(); ui.infoPane->setCurrentIndex(PLANNERWIDGET); - // setup the staging dive cylinders from the selected dive - DivePlannerPointsModel::instance()->clear(); - DivePlannerPointsModel::instance()->setupCylinders(); - // create a simple starting dive, using the first gas from the just copied cylidners + setupForAddAndPlan("planned dive"); // don't translate, stored in XML file DivePlannerPointsModel::instance()->setupStartTime(); DivePlannerPointsModel::instance()->createSimpleDive(); @@ -466,15 +470,8 @@ void MainWindow::on_actionAddDive_triggered() ui.ListWidget->endSearch(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); - clear_dive(&displayed_dive); - // but wait - we need a valid id... and a start time and an appropriatae dc model - displayed_dive.id = dive_getUniqID(&displayed_dive); - displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600; - displayed_dive.dc.model = "manually added dive"; // don't translate! this is stored in the XML file - - // setup the dive cylinders - DivePlannerPointsModel::instance()->clear(); - DivePlannerPointsModel::instance()->setupCylinders(); + // setup things so we can later create our starting dive + setupForAddAndPlan("manually added dive"); // don't translate, stored in the XML file // now show the mostly empty main tab ui.InfoWidget->updateDiveInfo(); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index d0406ff15..014fbb488 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -183,7 +183,7 @@ private: UpdateManager *updateManager; bool plannerStateClean(); - void createFakeDiveForAddAndPlan(); + void setupForAddAndPlan(const char *model); QDialog *survey; }; -- cgit v1.2.3-70-g09d2