aboutsummaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmanager.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2021-09-01 14:35:48 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-09-02 12:41:00 -0700
commitf19e10209cc334640d14dce67ee9c0da8e3485bc (patch)
treee0b80d6cc96127d85862203051b9589f10d71b97 /mobile-widgets/qmlmanager.cpp
parent33dc5478d8892ff34acf36f17561ae433c75ebb4 (diff)
downloadsubsurface-f19e10209cc334640d14dce67ee9c0da8e3485bc.tar.gz
mobile: fix broken cylinder name tracking in dive edit
Prior to this change, we had two different cylinder lists as models for drop down boxes - one that prepends the "no default cylinder" entry (which we need for setting up no default cylinder to be used in the app), and another one that only includes actual cylinders. The problem occured if a dive is created before the first time we edit an existing dive: in this case we are applying indices across the two models, but the indices are of course off by one; this results in actually picking the wrong cylinder. So each time we try to edit a dive, we end up with the previous cylinder in the list. This commit simplifies the code by having only one place where we create list of cylinder names (which is then used as the model for the combo box). It also uses more logical names for the two 'flavors' of this list to make it clear which one is supposed to be used (the regular list when editing or adding dives, the one with the "no default cylinder" entry prependet for the Settings page). Reported-by: Brian Fransen Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets/qmlmanager.cpp')
-rw-r--r--mobile-widgets/qmlmanager.cpp30
1 files changed, 10 insertions, 20 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 4f8cdbd52..ee70679d5 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -1867,27 +1867,17 @@ QStringList QMLManager::locationList() const
return locationModel.allSiteNames();
}
-QStringList QMLManager::cylinderInit() const
-{
- QStringList cylinders;
- struct dive *d;
- int i = 0;
- for_each_dive (i, d) {
- for (int j = 0; j < d->cylinders.nr; j++) {
- if (!empty_string(get_cylinder(d, j)->type.description))
- cylinders << get_cylinder(d, j)->type.description;
- }
- }
-
- for (int ti = 0; ti < tank_info_table.nr; ti++) {
- QString cyl = tank_info_table.infos[ti].name;
- if (cyl == "")
- continue;
- cylinders << cyl;
- }
+// this is the cylinder list used when editing a dive
+QStringList QMLManager::cylinderListInit() const
+{
+ return formatFullCylinderList();
+}
- cylinders.removeDuplicates();
- cylinders.sort();
+// this is the cylinder list used to pick your default cylinder
+// it starts with the (translated) "no default cylinder" in order to special-case this
+QStringList QMLManager::defaultCylinderListInit() const
+{
+ QStringList cylinders = cylinderListInit();
// now add fist one that indicates that the user wants no default cylinder
cylinders.prepend(tr("no default cylinder"));
return cylinders;