2017-04-27 18:30:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-10-29 07:44:06 +00:00
|
|
|
import QtQuick 2.6
|
2017-10-29 12:44:22 +00:00
|
|
|
import QtQuick.Controls 2.2
|
2015-07-21 12:00:29 +00:00
|
|
|
import QtQuick.Dialogs 1.2
|
2016-01-12 00:15:02 +00:00
|
|
|
import QtQuick.Layouts 1.2
|
2015-07-21 12:00:29 +00:00
|
|
|
import org.subsurfacedivelog.mobile 1.0
|
2018-09-27 20:09:26 +00:00
|
|
|
import org.kde.kirigami 2.4 as Kirigami
|
2015-07-21 12:00:29 +00:00
|
|
|
|
2016-03-08 20:26:54 +00:00
|
|
|
Kirigami.Page {
|
2017-03-18 21:19:18 +00:00
|
|
|
id: diveDetailsPage // but this is referenced as detailsWindow
|
2017-12-18 13:37:02 +00:00
|
|
|
objectName: "DiveDetails"
|
2016-01-29 00:01:29 +00:00
|
|
|
property alias currentIndex: diveDetailsListView.currentIndex
|
2016-04-14 13:01:36 +00:00
|
|
|
property alias currentItem: diveDetailsListView.currentItem
|
2016-01-29 02:29:02 +00:00
|
|
|
property alias dive_id: detailsEdit.dive_id
|
|
|
|
property alias number: detailsEdit.number
|
|
|
|
property alias date: detailsEdit.dateText
|
|
|
|
property alias airtemp: detailsEdit.airtempText
|
|
|
|
property alias watertemp: detailsEdit.watertempText
|
2016-05-16 17:59:05 +00:00
|
|
|
property alias buddyIndex: detailsEdit.buddyIndex
|
2017-04-15 00:09:09 +00:00
|
|
|
property alias buddyText: detailsEdit.buddyText
|
2018-02-02 12:05:42 +00:00
|
|
|
property alias buddyModel: detailsEdit.buddyModel
|
2016-05-16 17:59:05 +00:00
|
|
|
property alias divemasterIndex: detailsEdit.divemasterIndex
|
2017-04-15 00:09:09 +00:00
|
|
|
property alias divemasterText: detailsEdit.divemasterText
|
2016-05-20 16:48:36 +00:00
|
|
|
property alias divemasterModel: detailsEdit.divemasterModel
|
2016-01-29 02:29:02 +00:00
|
|
|
property alias depth: detailsEdit.depthText
|
|
|
|
property alias duration: detailsEdit.durationText
|
|
|
|
property alias location: detailsEdit.locationText
|
2017-11-22 15:19:44 +00:00
|
|
|
property alias locationModel: detailsEdit.locationModel
|
2018-03-09 13:49:15 +00:00
|
|
|
property alias locationIndex: detailsEdit.locationIndex
|
2016-04-15 12:17:39 +00:00
|
|
|
property alias gps: detailsEdit.gpsText
|
2016-01-29 02:29:02 +00:00
|
|
|
property alias notes: detailsEdit.notesText
|
2016-05-16 17:59:05 +00:00
|
|
|
property alias suitIndex: detailsEdit.suitIndex
|
2017-04-15 00:09:09 +00:00
|
|
|
property alias suitText: detailsEdit.suitText
|
2018-02-02 12:05:42 +00:00
|
|
|
property alias suitModel: detailsEdit.suitModel
|
2016-01-29 02:29:02 +00:00
|
|
|
property alias weight: detailsEdit.weightText
|
2018-08-06 07:34:39 +00:00
|
|
|
property alias startpressure: detailsEdit.startpressure
|
|
|
|
property alias endpressure: detailsEdit.endpressure
|
2018-07-16 13:21:39 +00:00
|
|
|
property alias cylinderIndex0: detailsEdit.cylinderIndex0
|
|
|
|
property alias cylinderIndex1: detailsEdit.cylinderIndex1
|
|
|
|
property alias cylinderIndex2: detailsEdit.cylinderIndex2
|
|
|
|
property alias cylinderIndex3: detailsEdit.cylinderIndex3
|
|
|
|
property alias cylinderIndex4: detailsEdit.cylinderIndex4
|
2018-07-28 13:07:43 +00:00
|
|
|
property alias usedGas: detailsEdit.usedGas
|
2016-04-15 12:17:39 +00:00
|
|
|
property alias gpsCheckbox: detailsEdit.gpsCheckbox
|
2016-04-14 13:01:36 +00:00
|
|
|
property int updateCurrentIdx: manager.updateSelectedDive
|
2017-07-28 15:43:26 +00:00
|
|
|
property alias rating: detailsEdit.rating
|
|
|
|
property alias visibility: detailsEdit.visibility
|
2018-07-16 13:21:39 +00:00
|
|
|
property alias usedCyl: detailsEdit.usedCyl
|
2018-07-28 13:43:05 +00:00
|
|
|
property alias cylinderModel0: detailsEdit.cylinderModel0
|
|
|
|
property alias cylinderModel1: detailsEdit.cylinderModel1
|
|
|
|
property alias cylinderModel2: detailsEdit.cylinderModel2
|
|
|
|
property alias cylinderModel3: detailsEdit.cylinderModel3
|
|
|
|
property alias cylinderModel4: detailsEdit.cylinderModel4
|
2016-01-12 02:01:15 +00:00
|
|
|
|
2017-06-21 23:30:10 +00:00
|
|
|
title: currentItem && currentItem.modelData ? currentItem.modelData.dive.location : qsTr("Dive details")
|
2016-01-20 22:07:06 +00:00
|
|
|
state: "view"
|
2016-04-19 17:11:07 +00:00
|
|
|
leftPadding: 0
|
2018-09-26 13:05:25 +00:00
|
|
|
topPadding: Kirigami.Units.gridUnit / 2
|
2016-04-19 17:11:07 +00:00
|
|
|
rightPadding: 0
|
|
|
|
bottomPadding: 0
|
2018-02-16 10:17:20 +00:00
|
|
|
background: Rectangle { color: subsurfaceTheme.backgroundColor }
|
2016-01-20 22:07:06 +00:00
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "view"
|
2016-04-19 11:51:19 +00:00
|
|
|
PropertyChanges {
|
|
|
|
target: diveDetailsPage;
|
|
|
|
actions {
|
|
|
|
right: deleteAction
|
2017-06-21 23:30:10 +00:00
|
|
|
left: currentItem ? (currentItem.modelData && currentItem.modelData.dive.gps !== "" ? mapAction : null) : null
|
2016-04-19 11:51:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-20 22:07:06 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "edit"
|
2017-10-04 19:22:36 +00:00
|
|
|
PropertyChanges {
|
|
|
|
target: diveDetailsPage;
|
|
|
|
actions {
|
|
|
|
right: cancelAction
|
|
|
|
left: null
|
|
|
|
}
|
|
|
|
}
|
2016-01-29 14:47:27 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "add"
|
2017-10-04 19:22:36 +00:00
|
|
|
PropertyChanges {
|
|
|
|
target: diveDetailsPage;
|
|
|
|
actions {
|
|
|
|
right: cancelAction
|
|
|
|
left: null
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 22:07:06 +00:00
|
|
|
}
|
2017-10-05 04:53:40 +00:00
|
|
|
]
|
|
|
|
transitions: [
|
|
|
|
Transition {
|
|
|
|
from: "view"
|
|
|
|
to: "*"
|
2017-10-05 19:14:57 +00:00
|
|
|
ParallelAnimation {
|
2017-10-05 19:15:33 +00:00
|
|
|
SequentialAnimation {
|
|
|
|
NumberAnimation {
|
|
|
|
target: detailsEditFlickable
|
|
|
|
properties: "visible"
|
|
|
|
from: 0
|
|
|
|
to: 1
|
|
|
|
duration: 10
|
|
|
|
}
|
|
|
|
ScaleAnimator {
|
|
|
|
target: detailsEditFlickable
|
|
|
|
from: 0.3
|
|
|
|
to: 1
|
|
|
|
duration: 400
|
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
}
|
2017-10-05 04:53:40 +00:00
|
|
|
}
|
2017-10-05 19:15:33 +00:00
|
|
|
|
|
|
|
NumberAnimation {
|
2017-10-05 04:53:40 +00:00
|
|
|
target: detailsEditFlickable
|
2017-10-05 19:15:33 +00:00
|
|
|
property: "contentY"
|
|
|
|
to: 0
|
|
|
|
duration: 200
|
2017-10-05 04:53:40 +00:00
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Transition {
|
|
|
|
from: "*"
|
|
|
|
to: "view"
|
|
|
|
SequentialAnimation {
|
|
|
|
ScaleAnimator {
|
|
|
|
target: detailsEditFlickable
|
|
|
|
from: 1
|
|
|
|
to: 0.3
|
|
|
|
duration: 400
|
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
}
|
|
|
|
NumberAnimation {
|
|
|
|
target: detailsEditFlickable
|
|
|
|
properties: "visible"
|
|
|
|
from: 1
|
|
|
|
to: 0
|
|
|
|
duration: 10
|
|
|
|
}
|
|
|
|
}
|
2016-01-29 14:47:27 +00:00
|
|
|
|
2017-10-05 04:53:40 +00:00
|
|
|
}
|
2016-01-20 22:07:06 +00:00
|
|
|
]
|
2016-02-12 12:51:03 +00:00
|
|
|
|
2017-03-31 14:15:14 +00:00
|
|
|
property QtObject deleteAction: Kirigami.Action {
|
2016-05-03 19:24:00 +00:00
|
|
|
text: qsTr("Delete dive")
|
2018-01-02 16:02:19 +00:00
|
|
|
icon {
|
2018-06-17 13:30:02 +00:00
|
|
|
name: ":/icons/trash-empty.svg"
|
2018-01-02 16:02:19 +00:00
|
|
|
}
|
2016-03-24 03:33:17 +00:00
|
|
|
onTriggered: {
|
2017-06-21 23:30:10 +00:00
|
|
|
var deletedId = currentItem.modelData.dive.id
|
2016-04-11 19:10:46 +00:00
|
|
|
var deletedIndex = diveDetailsListView.currentIndex
|
2016-03-24 03:33:17 +00:00
|
|
|
manager.deleteDive(deletedId)
|
2018-10-12 12:57:43 +00:00
|
|
|
pageStack.pop()
|
2016-03-24 03:33:17 +00:00
|
|
|
showPassiveNotification("Dive deleted", 3000, "Undo",
|
|
|
|
function() {
|
2016-04-11 19:10:46 +00:00
|
|
|
diveDetailsListView.currentIndex = manager.undoDelete(deletedId) ? deletedIndex : diveDetailsListView.currentIndex
|
2016-03-24 03:33:17 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 19:22:36 +00:00
|
|
|
property QtObject cancelAction: Kirigami.Action {
|
|
|
|
text: qsTr("Cancel edit")
|
2018-01-02 16:02:19 +00:00
|
|
|
icon {
|
2018-06-17 13:30:02 +00:00
|
|
|
name: ":/icons/dialog-cancel.svg"
|
2018-01-02 16:02:19 +00:00
|
|
|
}
|
2017-10-04 19:22:36 +00:00
|
|
|
onTriggered: {
|
|
|
|
endEditMode()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 14:15:14 +00:00
|
|
|
property QtObject mapAction: Kirigami.Action {
|
2016-05-03 19:24:00 +00:00
|
|
|
text: qsTr("Show on map")
|
2018-01-02 16:02:19 +00:00
|
|
|
icon {
|
2018-04-17 00:28:53 +00:00
|
|
|
name: ":/icons/gps"
|
2018-01-02 16:02:19 +00:00
|
|
|
}
|
2016-04-19 12:09:17 +00:00
|
|
|
onTriggered: {
|
2018-03-08 20:22:35 +00:00
|
|
|
showMap()
|
2018-10-25 18:46:12 +00:00
|
|
|
mapPage.centerOnDiveSite(currentItem.modelData.dive.dive_site)
|
2016-04-19 12:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 14:15:14 +00:00
|
|
|
actions.main: Kirigami.Action {
|
2018-01-02 16:02:19 +00:00
|
|
|
icon {
|
2018-06-17 13:30:02 +00:00
|
|
|
name: state !== "view" ? ":/icons/document-save.svg" : ":/icons/document-edit.svg"
|
2017-11-19 18:27:45 +00:00
|
|
|
color: subsurfaceTheme.primaryColor
|
2018-01-02 16:02:19 +00:00
|
|
|
}
|
2018-10-03 07:54:49 +00:00
|
|
|
text: state !== "view" ? qsTr("Save edits") : qsTr("Edit dive")
|
2016-01-12 00:15:02 +00:00
|
|
|
onTriggered: {
|
2017-03-18 21:25:59 +00:00
|
|
|
manager.appendTextToLog("save/edit button triggered")
|
2016-02-14 05:25:10 +00:00
|
|
|
if (state === "edit" || state === "add") {
|
|
|
|
detailsEdit.saveData()
|
2016-01-29 14:47:27 +00:00
|
|
|
} else {
|
2016-02-07 21:23:06 +00:00
|
|
|
startEditMode()
|
2015-12-04 02:32:52 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-12 00:15:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 16:41:42 +00:00
|
|
|
onBackRequested: {
|
2016-02-14 05:25:10 +00:00
|
|
|
if (state === "edit") {
|
|
|
|
endEditMode()
|
|
|
|
event.accepted = true;
|
|
|
|
} else if (state === "add") {
|
2016-03-31 01:48:50 +00:00
|
|
|
endEditMode()
|
2018-10-12 12:57:43 +00:00
|
|
|
pageStack.pop()
|
2016-02-08 16:41:42 +00:00
|
|
|
event.accepted = true;
|
|
|
|
}
|
2016-02-14 05:25:10 +00:00
|
|
|
// if we were in view mode, don't accept the event and pop the page
|
2016-02-08 16:41:42 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 13:01:36 +00:00
|
|
|
onCurrentItemChanged: {
|
2017-06-21 23:30:10 +00:00
|
|
|
manager.selectedDiveTimestamp = currentItem.modelData.dive.timestamp
|
2016-04-14 13:01:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 00:15:02 +00:00
|
|
|
function showDiveIndex(index) {
|
2016-01-29 18:17:22 +00:00
|
|
|
currentIndex = index;
|
2018-05-07 21:37:49 +00:00
|
|
|
diveDetailsListView.positionViewAtIndex(index, ListView.End);
|
2016-01-12 00:15:02 +00:00
|
|
|
}
|
2016-02-07 21:23:06 +00:00
|
|
|
|
2016-02-07 21:23:07 +00:00
|
|
|
function endEditMode() {
|
2016-03-31 01:48:50 +00:00
|
|
|
// if we were adding a dive, we need to remove it
|
|
|
|
if (state === "add")
|
|
|
|
manager.addDiveAborted(dive_id)
|
|
|
|
// just cancel the edit/add state
|
2016-02-07 21:23:07 +00:00
|
|
|
state = "view";
|
2017-07-31 16:52:01 +00:00
|
|
|
focus = false;
|
2016-02-07 21:23:07 +00:00
|
|
|
Qt.inputMethod.hide();
|
mobile: clear internal data when edit/add dive is finished
When editing (or adding) a dive, the internal data containing the
attributes on the edit page was not cleared when editing was
finished (in any way, by saving the edit or by cancelling it).
As long as the user only edits existing dives, all this poses
no problem, as at the start of a dive edit, the data is filled
from the dive to be edited. However, when adding a dive, data
coming from previous edits shows up. This not clearing data
also causes the strange effect as written in issue #950: adding
a dive, deleting it, and adding a dive again, added the first
added dive data, without the edit screen being shown.
All this can be solved by clearing the data from the edit when
editing is done.
Fixes: #950
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-15 16:13:15 +00:00
|
|
|
detailsEdit.clearDetailsEdit();
|
2016-02-07 21:23:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 21:23:06 +00:00
|
|
|
function startEditMode() {
|
2017-06-21 23:30:10 +00:00
|
|
|
if (!currentItem.modelData) {
|
|
|
|
console.log("DiveDetails trying to access undefined currentItem.modelData")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-02-07 21:23:06 +00:00
|
|
|
// set things up for editing - so make sure that the detailsEdit has
|
|
|
|
// all the right data (using the property aliases set up above)
|
2019-08-22 17:52:25 +00:00
|
|
|
var dive = currentItem.modelData.dive
|
|
|
|
dive_id = dive.id
|
|
|
|
number = dive.number
|
|
|
|
date = dive.date + " " + dive.time
|
|
|
|
location = dive.location
|
|
|
|
locationIndex = manager.locationList.indexOf(dive.location)
|
|
|
|
gps = dive.gps
|
2016-04-15 12:17:39 +00:00
|
|
|
gpsCheckbox = false
|
2019-08-22 17:52:25 +00:00
|
|
|
duration = dive.duration
|
|
|
|
depth = dive.depth
|
|
|
|
airtemp = dive.airTemp
|
|
|
|
watertemp = dive.waterTemp
|
|
|
|
suitIndex = manager.suitList.indexOf(dive.suit)
|
|
|
|
if (dive.buddy.indexOf(",") > 0) {
|
|
|
|
buddyIndex = manager.buddyList.indexOf(dive.buddy.split(",", 1).toString())
|
2016-09-12 18:30:07 +00:00
|
|
|
} else {
|
2019-08-22 17:52:25 +00:00
|
|
|
buddyIndex = manager.buddyList.indexOf(dive.buddy)
|
2016-09-12 18:30:07 +00:00
|
|
|
}
|
2019-08-22 17:52:25 +00:00
|
|
|
buddyText = dive.buddy;
|
|
|
|
if (dive.divemaster.indexOf(",") > 0) {
|
|
|
|
divemasterIndex = manager.divemasterList.indexOf(dive.divemaster.split(",", 1).toString())
|
2018-11-13 20:28:18 +00:00
|
|
|
} else {
|
2019-08-22 17:52:25 +00:00
|
|
|
divemasterIndex = manager.divemasterList.indexOf(dive.divemaster)
|
2018-11-13 20:28:18 +00:00
|
|
|
}
|
2019-08-22 17:52:25 +00:00
|
|
|
divemasterText = dive.divemaster
|
|
|
|
notes = dive.notes
|
|
|
|
if (dive.singleWeight) {
|
2016-02-07 21:23:06 +00:00
|
|
|
// we have only one weight, go ahead, have fun and edit it
|
2019-08-22 17:52:25 +00:00
|
|
|
weight = dive.sumWeight
|
2016-02-07 21:23:06 +00:00
|
|
|
} else {
|
|
|
|
// careful when translating, this text is "magic" in DiveDetailsEdit.qml
|
|
|
|
weight = "cannot edit multiple weight systems"
|
|
|
|
}
|
2019-08-22 17:52:25 +00:00
|
|
|
startpressure = dive.startPressure
|
|
|
|
endpressure = dive.endPressure
|
|
|
|
usedGas = dive.firstGas
|
|
|
|
usedCyl = dive.getCylinder
|
|
|
|
cylinderIndex0 = dive.cylinderList.indexOf(usedCyl[0])
|
|
|
|
cylinderIndex1 = dive.cylinderList.indexOf(usedCyl[1])
|
|
|
|
cylinderIndex2 = dive.cylinderList.indexOf(usedCyl[2])
|
|
|
|
cylinderIndex3 = dive.cylinderList.indexOf(usedCyl[3])
|
|
|
|
cylinderIndex4 = dive.cylinderList.indexOf(usedCyl[4])
|
|
|
|
rating = dive.rating
|
|
|
|
visibility = dive.visibility
|
2016-02-07 21:23:06 +00:00
|
|
|
|
|
|
|
diveDetailsPage.state = "edit"
|
|
|
|
}
|
|
|
|
|
2016-03-08 20:26:54 +00:00
|
|
|
Item {
|
2015-11-11 23:40:13 +00:00
|
|
|
anchors.fill: parent
|
2017-10-04 19:22:36 +00:00
|
|
|
visible: diveDetailsPage.state == "view"
|
2017-03-31 14:15:14 +00:00
|
|
|
ListView {
|
|
|
|
id: diveDetailsListView
|
2015-11-30 00:12:47 +00:00
|
|
|
anchors.fill: parent
|
2017-03-31 14:15:14 +00:00
|
|
|
model: diveModel
|
|
|
|
currentIndex: -1
|
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
maximumFlickVelocity: parent.width * 5
|
|
|
|
orientation: ListView.Horizontal
|
2017-10-26 20:26:14 +00:00
|
|
|
highlightFollowsCurrentItem: false
|
2017-03-31 14:15:14 +00:00
|
|
|
focus: true
|
2018-09-30 18:42:28 +00:00
|
|
|
clip: true
|
2017-03-31 14:15:14 +00:00
|
|
|
snapMode: ListView.SnapOneItem
|
|
|
|
highlightRangeMode: ListView.StrictlyEnforceRange
|
|
|
|
onMovementEnded: {
|
|
|
|
currentIndex = indexAt(contentX+1, 1);
|
|
|
|
}
|
|
|
|
delegate: Flickable {
|
|
|
|
id: internalScrollView
|
|
|
|
width: diveDetailsListView.width
|
|
|
|
height: diveDetailsListView.height
|
|
|
|
contentHeight: diveDetails.height
|
2016-03-08 20:26:54 +00:00
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
2017-03-31 14:15:14 +00:00
|
|
|
property var modelData: model
|
|
|
|
DiveDetailsView {
|
|
|
|
id: diveDetails
|
|
|
|
width: internalScrollView.width
|
2015-12-04 00:38:04 +00:00
|
|
|
}
|
2017-03-31 14:15:14 +00:00
|
|
|
ScrollBar.vertical: ScrollBar { }
|
2015-07-21 12:00:29 +00:00
|
|
|
}
|
2017-03-31 14:15:14 +00:00
|
|
|
ScrollIndicator.horizontal: ScrollIndicator { }
|
2015-07-21 12:00:29 +00:00
|
|
|
}
|
2017-10-04 19:22:36 +00:00
|
|
|
}
|
2017-10-04 19:27:13 +00:00
|
|
|
Flickable {
|
|
|
|
id: detailsEditFlickable
|
|
|
|
anchors.fill: parent
|
|
|
|
leftMargin: Kirigami.Units.smallSpacing
|
|
|
|
rightMargin: Kirigami.Units.smallSpacing
|
|
|
|
contentHeight: detailsEdit.height
|
2017-10-05 04:53:40 +00:00
|
|
|
// start invisible and scaled down, to get the transition
|
|
|
|
// off to the right start
|
|
|
|
visible: false
|
|
|
|
scale: 0.3
|
2017-10-04 19:27:13 +00:00
|
|
|
DiveDetailsEdit {
|
|
|
|
id: detailsEdit
|
|
|
|
}
|
|
|
|
ScrollBar.vertical: ScrollBar { }
|
2016-01-12 00:15:02 +00:00
|
|
|
}
|
2015-07-21 12:00:29 +00:00
|
|
|
}
|