mobile UI: set the correct location string when editing dives

In some situations we ended up with the wrong location name. One way to
reproduce the problem was to edit an existing dive location to be a substring
of an existing location name. Save the dive, then immediately edit it again.
The wrong location would be filled in.

The code here looks strange and unnecessary, but it seems to fix the issue.

The aliases don't seem to make the code any easier to understand. This replaces
them in the case of the location combo box with direct accesses to the data on
the DiveDetailsEdit page. It may be worth removing all of them. The
locationModel alias was unused.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-01-12 22:42:57 -08:00
parent 28bf078ff7
commit 65fe892cba

View file

@ -25,8 +25,6 @@ Kirigami.Page {
property alias depth: detailsEdit.depthText
property alias duration: detailsEdit.durationText
property alias location: detailsEdit.locationText
property alias locationModel: detailsEdit.locationModel
property alias locationIndex: detailsEdit.locationIndex
property alias gps: detailsEdit.gpsText
property alias notes: detailsEdit.notesText
property alias suitIndex: detailsEdit.suitIndex
@ -251,8 +249,14 @@ Kirigami.Page {
dive_id = modelData.id
number = modelData.number
date = modelData.dateTime
location = modelData.location !== undefined ? location : ""
locationIndex = manager.locationList.indexOf(modelData.location)
var locationText = modelData.location !== undefined ? modelData.location : ""
var locationIndex = manager.locationList.indexOf(modelData.location)
if (locationIndex >= 0) {
detailsEdit.locationIndex = locationIndex
detailsEdit.locationText = manager.locationList[locationIndex] // this shouldn't be necessary, but apparently it is
} else {
detailsEdit.locationText = locationText
}
gps = modelData.gps
gpsCheckbox = false
duration = modelData.duration