summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-08-18 14:12:05 -0500
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-08-18 14:12:05 -0500
commit0f1381f1609af6b9e7a09b3423741a4e713fbff4 (patch)
treeb5bf9b406bc52bf4469c527a1a2196bbc4a18795
parent88fe28636e775ab9dfbb7caa769d63045dc4d7ca (diff)
downloadsubsurface-0f1381f1609af6b9e7a09b3423741a4e713fbff4.tar.gz
Planner: assign a dive number if the right number seems obvious
Use the same logic as we do for newly added dives. As a side effect this patch appears to fix the issues with getting the newly planned dive selected. Fixes #692 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divelist.c8
-rw-r--r--divelist.h1
-rw-r--r--qt-ui/maintab.cpp5
-rw-r--r--qt-ui/mainwindow.cpp6
4 files changed, 16 insertions, 4 deletions
diff --git a/divelist.c b/divelist.c
index 9fe3240d5..cccd3a0a6 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1040,3 +1040,11 @@ void process_dives(bool is_imported, bool prefer_imported)
mark_divelist_changed(true);
}
}
+
+void set_dive_nr_for_current_dive()
+{
+ if (dive_table.nr == 1)
+ current_dive->number = 1;
+ 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;
+}
diff --git a/divelist.h b/divelist.h
index 96722e819..a24deea17 100644
--- a/divelist.h
+++ b/divelist.h
@@ -37,6 +37,7 @@ extern void find_new_trip_start_time(dive_trip_t *trip);
extern struct dive *first_selected_dive();
extern struct dive *last_selected_dive();
extern bool is_trip_before_after(struct dive *dive, bool before);
+extern void set_dive_nr_for_current_dive();
#ifdef DEBUG_TRIP
extern void dump_selection(void);
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 5002a2880..6bb6f14f8 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -771,10 +771,7 @@ void MainTab::acceptChanges()
}
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
fixup_dive(current_dive);
- if (dive_table.nr == 1)
- current_dive->number = 1;
- 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;
+ set_dive_nr_for_current_dive();
MainWindow::instance()->showProfile();
mark_divelist_changed(true);
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 9912d60bd..b27f2b606 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -402,6 +402,12 @@ void MainWindow::planCanceled()
void MainWindow::planCreated()
{
+ // get the new dive selected and assign a number if reasonable
+ dive_list()->unselectDives();
+ select_dive(dive_table.nr - 1);
+ dive_list()->selectDive(selected_dive);
+ set_dive_nr_for_current_dive();
+
showProfile();
refreshDisplay();
}