Changeset a7fca80 in subsurface


Ignore:
Timestamp:
Jun 21, 2017, 5:20:07 PM (5 weeks ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
28490d5
Parents:
7b7294d
git-author:
Dirk Hohndel <dirk@…> (06/21/17 16:30:10)
git-committer:
Dirk Hohndel <dirk@…> (06/21/17 17:20:07)
Message:

QML UI: don't access dive without modelData

Occasionally I see errors in the log where we would access modelData.dive
with modelData = null. This patch addresses a couple of the spaces where
this happens, but also simplifies the code by using the existing alias.

Signed-off-by: Dirk Hohndel <dirk@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mobile-widgets/qml/DiveDetails.qml

    r8525805 ra7fca80  
    4040        property int updateCurrentIdx: manager.updateSelectedDive
    4141
    42         title: diveDetailsListView.currentItem ? diveDetailsListView.currentItem.modelData.dive.location : qsTr("Dive details")
     42        title: currentItem && currentItem.modelData ? currentItem.modelData.dive.location : qsTr("Dive details")
    4343        state: "view"
    4444        leftPadding: 0
     
    5454                                actions {
    5555                                        right: deleteAction
    56                                         left: diveDetailsListView.currentItem ? (diveDetailsListView.currentItem.modelData.dive.gps !== "" ? mapAction : null) : null
     56                                        left: currentItem ? (currentItem.modelData && currentItem.modelData.dive.gps !== "" ? mapAction : null) : null
    5757                                }
    5858                        }
     
    7777                iconName: "trash-empty"
    7878                onTriggered: {
    79                         var deletedId = diveDetailsListView.currentItem.modelData.dive.id
     79                        var deletedId = currentItem.modelData.dive.id
    8080                        var deletedIndex = diveDetailsListView.currentIndex
    8181                        manager.deleteDive(deletedId)
     
    9292                iconName: "gps"
    9393                onTriggered: {
    94                         showMap(diveDetailsListView.currentItem.modelData.dive.gps_decimal)
     94                        showMap(currentItem.modelData.dive.gps_decimal)
    9595                }
    9696        }
     
    121121
    122122        onCurrentItemChanged: {
    123                 manager.selectedDiveTimestamp = diveDetailsListView.currentItem.modelData.dive.timestamp
     123                manager.selectedDiveTimestamp = currentItem.modelData.dive.timestamp
    124124        }
    125125
     
    139139
    140140        function startEditMode() {
     141                if (!currentItem.modelData) {
     142                        console.log("DiveDetails trying to access undefined currentItem.modelData")
     143                        return
     144                }
     145
    141146                // set things up for editing - so make sure that the detailsEdit has
    142147                // all the right data (using the property aliases set up above)
    143                 dive_id = diveDetailsListView.currentItem.modelData.dive.id
    144                 number = diveDetailsListView.currentItem.modelData.dive.number
    145                 date = diveDetailsListView.currentItem.modelData.dive.date + " " + diveDetailsListView.currentItem.modelData.dive.time
    146                 location = diveDetailsListView.currentItem.modelData.dive.location
    147                 gps = diveDetailsListView.currentItem.modelData.dive.gps
     148                dive_id = currentItem.modelData.dive.id
     149                number = currentItem.modelData.dive.number
     150                date = currentItem.modelData.dive.date + " " + currentItem.modelData.dive.time
     151                location = currentItem.modelData.dive.location
     152                gps = currentItem.modelData.dive.gps
    148153                gpsCheckbox = false
    149                 duration = diveDetailsListView.currentItem.modelData.dive.duration
    150                 depth = diveDetailsListView.currentItem.modelData.dive.depth
    151                 airtemp = diveDetailsListView.currentItem.modelData.dive.airTemp
    152                 watertemp = diveDetailsListView.currentItem.modelData.dive.waterTemp
    153                 suitIndex = diveDetailsListView.currentItem.modelData.dive.suitList.indexOf(diveDetailsListView.currentItem.modelData.dive.suit)
    154                 if (diveDetailsListView.currentItem.modelData.dive.buddy.indexOf(",") > 0) {
    155                         buddyIndex = diveDetailsListView.currentItem.modelData.dive.buddyList.indexOf(qsTr("Multiple Buddies"));
     154                duration = currentItem.modelData.dive.duration
     155                depth = currentItem.modelData.dive.depth
     156                airtemp = currentItem.modelData.dive.airTemp
     157                watertemp = currentItem.modelData.dive.waterTemp
     158                suitIndex = currentItem.modelData.dive.suitList.indexOf(currentItem.modelData.dive.suit)
     159                if (currentItem.modelData.dive.buddy.indexOf(",") > 0) {
     160                        buddyIndex = currentItem.modelData.dive.buddyList.indexOf(qsTr("Multiple Buddies"));
    156161                } else {
    157                         buddyIndex = diveDetailsListView.currentItem.modelData.dive.buddyList.indexOf(diveDetailsListView.currentItem.modelData.dive.buddy)
    158                 }
    159                 divemasterIndex = diveDetailsListView.currentItem.modelData.dive.divemasterList.indexOf(diveDetailsListView.currentItem.modelData.dive.divemaster)
    160                 notes = diveDetailsListView.currentItem.modelData.dive.notes
    161                 if (diveDetailsListView.currentItem.modelData.dive.singleWeight) {
     162                        buddyIndex = currentItem.modelData.dive.buddyList.indexOf(currentItem.modelData.dive.buddy)
     163                }
     164                divemasterIndex = currentItem.modelData.dive.divemasterList.indexOf(currentItem.modelData.dive.divemaster)
     165                notes = currentItem.modelData.dive.notes
     166                if (currentItem.modelData.dive.singleWeight) {
    162167                        // we have only one weight, go ahead, have fun and edit it
    163                         weight = diveDetailsListView.currentItem.modelData.dive.sumWeight
     168                        weight = currentItem.modelData.dive.sumWeight
    164169                } else {
    165170                        // careful when translating, this text is "magic" in DiveDetailsEdit.qml
    166171                        weight = "cannot edit multiple weight systems"
    167172                }
    168                 startpressure = diveDetailsListView.currentItem.modelData.dive.startPressure
    169                 endpressure = diveDetailsListView.currentItem.modelData.dive.endPressure
    170                 gasmix = diveDetailsListView.currentItem.modelData.dive.firstGas
    171                 cylinderIndex = diveDetailsListView.currentItem.modelData.dive.cylinderList.indexOf(diveDetailsListView.currentItem.modelData.dive.getCylinder)
     173                startpressure = currentItem.modelData.dive.startPressure
     174                endpressure = currentItem.modelData.dive.endPressure
     175                gasmix = currentItem.modelData.dive.firstGas
     176                cylinderIndex = currentItem.modelData.dive.cylinderList.indexOf(currentItem.modelData.dive.getCylinder)
    172177
    173178                diveDetailsPage.state = "edit"
Note: See TracChangeset for help on using the changeset viewer.