| 
									
										
										
										
											2017-04-27 20:30:36 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2017-10-29 08:44:06 +01:00
										 |  |  | import QtQuick 2.6 | 
					
						
							| 
									
										
										
										
											2017-10-29 13:44:22 +01:00
										 |  |  | import QtQuick.Controls 2.2 | 
					
						
							| 
									
										
										
										
											2015-07-21 15:00:29 +03:00
										 |  |  | import QtQuick.Dialogs 1.2 | 
					
						
							| 
									
										
										
										
											2016-01-12 01:15:02 +01:00
										 |  |  | import QtQuick.Layouts 1.2 | 
					
						
							| 
									
										
										
										
											2015-07-21 15:00:29 +03:00
										 |  |  | import org.subsurfacedivelog.mobile 1.0 | 
					
						
							| 
									
										
										
										
											2018-09-27 22:09:26 +02:00
										 |  |  | import org.kde.kirigami 2.4 as Kirigami | 
					
						
							| 
									
										
										
										
											2015-07-21 15:00:29 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 21:26:54 +01:00
										 |  |  | Kirigami.Page { | 
					
						
							| 
									
										
										
										
											2017-03-18 14:19:18 -07:00
										 |  |  | 	id: diveDetailsPage // but this is referenced as detailsWindow
 | 
					
						
							| 
									
										
										
										
											2017-12-18 14:37:02 +01:00
										 |  |  | 	objectName: "DiveDetails" | 
					
						
							| 
									
										
										
										
											2016-01-28 16:01:29 -08:00
										 |  |  | 	property alias currentIndex: diveDetailsListView.currentIndex | 
					
						
							| 
									
										
										
										
											2016-04-14 06:01:36 -07:00
										 |  |  | 	property alias currentItem: diveDetailsListView.currentItem | 
					
						
							| 
									
										
										
										
											2016-01-28 18:29:02 -08: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 19:59:05 +02:00
										 |  |  | 	property alias buddyIndex: detailsEdit.buddyIndex | 
					
						
							| 
									
										
										
										
											2017-04-14 17:09:09 -07:00
										 |  |  | 	property alias buddyText: detailsEdit.buddyText | 
					
						
							| 
									
										
										
										
											2018-02-02 13:05:42 +01:00
										 |  |  | 	property alias buddyModel: detailsEdit.buddyModel | 
					
						
							| 
									
										
										
										
											2016-05-16 19:59:05 +02:00
										 |  |  | 	property alias divemasterIndex: detailsEdit.divemasterIndex | 
					
						
							| 
									
										
										
										
											2017-04-14 17:09:09 -07:00
										 |  |  | 	property alias divemasterText: detailsEdit.divemasterText | 
					
						
							| 
									
										
										
										
											2016-05-20 18:48:36 +02:00
										 |  |  | 	property alias divemasterModel: detailsEdit.divemasterModel | 
					
						
							| 
									
										
										
										
											2021-08-15 19:55:17 -07:00
										 |  |  | 	property alias tagText: detailsEdit.tagText | 
					
						
							| 
									
										
										
										
											2016-01-28 18:29:02 -08:00
										 |  |  | 	property alias depth: detailsEdit.depthText | 
					
						
							|  |  |  | 	property alias duration: detailsEdit.durationText | 
					
						
							|  |  |  | 	property alias location: detailsEdit.locationText | 
					
						
							| 
									
										
										
										
											2016-04-15 05:17:39 -07:00
										 |  |  | 	property alias gps: detailsEdit.gpsText | 
					
						
							| 
									
										
										
										
											2016-01-28 18:29:02 -08:00
										 |  |  | 	property alias notes: detailsEdit.notesText | 
					
						
							| 
									
										
										
										
											2016-05-16 19:59:05 +02:00
										 |  |  | 	property alias suitIndex: detailsEdit.suitIndex | 
					
						
							| 
									
										
										
										
											2017-04-14 17:09:09 -07:00
										 |  |  | 	property alias suitText: detailsEdit.suitText | 
					
						
							| 
									
										
										
										
											2018-02-02 13:05:42 +01:00
										 |  |  | 	property alias suitModel: detailsEdit.suitModel | 
					
						
							| 
									
										
										
										
											2016-01-28 18:29:02 -08:00
										 |  |  | 	property alias weight: detailsEdit.weightText | 
					
						
							| 
									
										
										
										
											2018-08-06 09:34:39 +02:00
										 |  |  | 	property alias startpressure: detailsEdit.startpressure | 
					
						
							|  |  |  | 	property alias endpressure: detailsEdit.endpressure | 
					
						
							| 
									
										
										
										
											2018-07-16 15:21:39 +02: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 15:07:43 +02:00
										 |  |  | 	property alias usedGas: detailsEdit.usedGas | 
					
						
							| 
									
										
										
										
											2017-07-28 17:43:26 +02:00
										 |  |  | 	property alias rating: detailsEdit.rating | 
					
						
							|  |  |  | 	property alias visibility: detailsEdit.visibility | 
					
						
							| 
									
										
										
										
											2018-07-16 15:21:39 +02:00
										 |  |  | 	property alias usedCyl: detailsEdit.usedCyl | 
					
						
							| 
									
										
										
										
											2018-07-28 15:43:05 +02: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 03:01:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:45:37 -04:00
										 |  |  | 	title: currentItem && currentItem.modelData && currentItem.modelData.location && "" !== currentItem.modelData.location ? | 
					
						
							|  |  |  | 		       currentItem.modelData.location : qsTr("Dive details") | 
					
						
							| 
									
										
										
										
											2016-01-20 14:07:06 -08:00
										 |  |  | 	state: "view" | 
					
						
							| 
									
										
										
										
											2016-04-19 19:11:07 +02:00
										 |  |  | 	leftPadding: 0 | 
					
						
							| 
									
										
										
										
											2018-09-26 15:05:25 +02:00
										 |  |  | 	topPadding: Kirigami.Units.gridUnit / 2 | 
					
						
							| 
									
										
										
										
											2016-04-19 19:11:07 +02:00
										 |  |  | 	rightPadding: 0 | 
					
						
							|  |  |  | 	bottomPadding: 0 | 
					
						
							| 
									
										
										
										
											2018-02-16 11:17:20 +01:00
										 |  |  | 	background: Rectangle { color: subsurfaceTheme.backgroundColor } | 
					
						
							| 
									
										
										
										
											2019-10-05 20:27:05 -07:00
										 |  |  | 	width: rootItem.colWidth | 
					
						
							| 
									
										
										
										
											2020-12-22 15:02:39 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// we want to use our own colors for Kirigami, so let's define our colorset
 | 
					
						
							|  |  |  | 	Kirigami.Theme.inherit: false | 
					
						
							|  |  |  | 	Kirigami.Theme.colorSet: Kirigami.Theme.Button | 
					
						
							| 
									
										
										
										
											2020-12-19 14:10:32 -08:00
										 |  |  | 	Kirigami.Theme.backgroundColor: subsurfaceTheme.backgroundColor | 
					
						
							| 
									
										
										
										
											2020-12-22 15:02:39 -08:00
										 |  |  | 	Kirigami.Theme.textColor: subsurfaceTheme.textColor | 
					
						
							| 
									
										
										
										
											2016-01-20 14:07:06 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 14:06:03 -08:00
										 |  |  | 	property QtObject removeDiveFromTripAction: Kirigami.Action { | 
					
						
							|  |  |  | 		text: qsTr ("Remove this dive from trip") | 
					
						
							| 
									
										
										
										
											2020-02-22 15:23:24 -08:00
										 |  |  | 		icon { name: ":/icons/chevron_left.svg" } | 
					
						
							| 
									
										
										
										
											2020-02-20 13:25:44 -08:00
										 |  |  | 		enabled: currentItem && currentItem.modelData && currentItem.modelData.diveInTrip | 
					
						
							| 
									
										
										
										
											2020-02-19 14:06:03 -08:00
										 |  |  | 		onTriggered: { | 
					
						
							|  |  |  | 			manager.appendTextToLog("remove dive #" + currentItem.modelData.number + " from its trip") | 
					
						
							|  |  |  | 			manager.removeDiveFromTrip(currentItem.modelData.id) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-20 13:25:44 -08:00
										 |  |  | 	property QtObject addDiveToTripAboveAction: Kirigami.Action { | 
					
						
							|  |  |  | 		text: qsTr ("Add dive to trip above") | 
					
						
							| 
									
										
										
										
											2020-02-22 15:23:24 -08:00
										 |  |  | 		icon { name: ":/icons/expand_less.svg" } | 
					
						
							| 
									
										
										
										
											2020-02-20 13:25:44 -08:00
										 |  |  | 		enabled: currentItem && currentItem.modelData && !currentItem.modelData.diveInTrip && currentItem.modelData.tripAbove !== -1 | 
					
						
							|  |  |  | 		onTriggered: { | 
					
						
							|  |  |  | 			manager.appendTextToLog("add dive #" + currentItem.modelData.number + " to trip with id " + currentItem.modelData.tripAbove) | 
					
						
							|  |  |  | 			manager.addDiveToTrip(currentItem.modelData.id, currentItem.modelData.tripAbove) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	property QtObject addDiveToTripBelowAction: Kirigami.Action { | 
					
						
							|  |  |  | 		text: qsTr ("Add dive to trip below") | 
					
						
							| 
									
										
										
										
											2020-02-22 15:23:24 -08:00
										 |  |  | 		icon { name: ":/icons/expand_more.svg" } | 
					
						
							| 
									
										
										
										
											2020-02-20 13:25:44 -08:00
										 |  |  | 		enabled: currentItem && currentItem.modelData && !currentItem.modelData.diveInTrip && currentItem.modelData.tripBelow !== -1 | 
					
						
							|  |  |  | 		onTriggered: { | 
					
						
							|  |  |  | 			manager.appendTextToLog("add dive #" + currentItem.modelData.number + " to trip with id " + currentItem.modelData.tripBelow) | 
					
						
							|  |  |  | 			manager.addDiveToTrip(currentItem.modelData.id, currentItem.modelData.tripBelow) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-03-26 16:48:45 -07:00
										 |  |  | 	property QtObject createTripForDiveAction: Kirigami.Action { | 
					
						
							|  |  |  | 		text: qsTr("Create trip with dive") | 
					
						
							|  |  |  | 		icon { name: ":/icons/list-add" } | 
					
						
							|  |  |  | 		enabled: currentItem && currentItem.modelData && !currentItem.modelData.isTrip && currentItem.modelData.isTopLevel | 
					
						
							| 
									
										
										
										
											2020-03-31 09:57:37 -07:00
										 |  |  | 		onTriggered: manager.addTripForDive(currentItem.modelData.id) | 
					
						
							| 
									
										
										
										
											2020-03-26 16:48:45 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-03-31 09:58:43 -07:00
										 |  |  | 	property QtObject toggleInvalidAction: Kirigami.Action { | 
					
						
							|  |  |  | 		text: currentItem && currentItem.modelData && currentItem.modelData.isInvalid ? qsTr("Mark dive as valid") : qsTr("Mark dive as invalid") | 
					
						
							|  |  |  | 		visible: currentItem && currentItem.modelData | 
					
						
							|  |  |  | 		onTriggered: manager.toggleDiveInvalid(currentItem.modelData.id) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-18 16:12:12 -08:00
										 |  |  | 	property QtObject undoAction: Kirigami.Action { | 
					
						
							|  |  |  | 		text: qsTr("Undo") + " " + manager.undoText | 
					
						
							| 
									
										
										
										
											2020-02-22 15:23:24 -08:00
										 |  |  | 		icon { name: ":/icons/undo.svg" } | 
					
						
							| 
									
										
										
										
											2020-02-18 16:12:12 -08:00
										 |  |  | 		enabled: manager.undoText !== "" | 
					
						
							|  |  |  | 		onTriggered: manager.undo() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	property QtObject redoAction: Kirigami.Action { | 
					
						
							|  |  |  | 		text: qsTr("Redo") + " " + manager.redoText | 
					
						
							| 
									
										
										
										
											2020-02-22 15:23:24 -08:00
										 |  |  | 		icon { name: ":/icons/redo.svg" } | 
					
						
							| 
									
										
										
										
											2020-02-18 16:12:12 -08:00
										 |  |  | 		enabled: manager.redoText !== "" | 
					
						
							|  |  |  | 		onTriggered: manager.redo() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-17 11:29:22 -08:00
										 |  |  | 	property variant contextactions: [ removeDiveFromTripAction, addDiveToTripAboveAction, addDiveToTripBelowAction, deleteAction, undoAction, redoAction ] | 
					
						
							| 
									
										
										
										
											2020-02-18 16:12:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 14:07:06 -08:00
										 |  |  | 	states: [ | 
					
						
							|  |  |  | 		State { | 
					
						
							|  |  |  | 			name: "view" | 
					
						
							| 
									
										
										
										
											2016-04-19 04:51:19 -07:00
										 |  |  | 			PropertyChanges { | 
					
						
							|  |  |  | 				target: diveDetailsPage; | 
					
						
							|  |  |  | 				actions { | 
					
						
							| 
									
										
										
										
											2021-01-17 11:29:22 -08:00
										 |  |  | 					right: null | 
					
						
							| 
									
										
										
										
											2019-10-19 22:12:50 -04:00
										 |  |  | 					left: currentItem ? (currentItem.modelData && currentItem.modelData.gps !== "" ? mapAction : null) : null | 
					
						
							| 
									
										
										
										
											2016-04-19 04:51:19 -07:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-02-18 16:12:12 -08:00
										 |  |  | 				contextualActions: contextactions | 
					
						
							| 
									
										
										
										
											2016-04-19 04:51:19 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-01-20 14:07:06 -08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		State { | 
					
						
							|  |  |  | 			name: "edit" | 
					
						
							| 
									
										
										
										
											2017-10-04 12:22:36 -07:00
										 |  |  | 			PropertyChanges { | 
					
						
							|  |  |  | 				target: diveDetailsPage; | 
					
						
							|  |  |  | 				actions { | 
					
						
							|  |  |  | 					right: cancelAction | 
					
						
							|  |  |  | 					left: null | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-02-18 16:12:12 -08:00
										 |  |  | 				contextualActions: [] | 
					
						
							| 
									
										
										
										
											2017-10-04 12:22:36 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-01-29 06:47:27 -08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		State { | 
					
						
							|  |  |  | 			name: "add" | 
					
						
							| 
									
										
										
										
											2017-10-04 12:22:36 -07:00
										 |  |  | 			PropertyChanges { | 
					
						
							|  |  |  | 				target: diveDetailsPage; | 
					
						
							|  |  |  | 				actions { | 
					
						
							|  |  |  | 					right: cancelAction | 
					
						
							|  |  |  | 					left: null | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-02-18 16:12:12 -08:00
										 |  |  | 				contextualActions: [] | 
					
						
							| 
									
										
										
										
											2017-10-04 12:22:36 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-01-20 14:07:06 -08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-04 21:53:40 -07:00
										 |  |  | 	] | 
					
						
							|  |  |  | 	transitions: [ | 
					
						
							|  |  |  | 		Transition { | 
					
						
							|  |  |  | 			from: "view" | 
					
						
							|  |  |  | 			to: "*" | 
					
						
							| 
									
										
										
										
											2017-10-05 12:14:57 -07:00
										 |  |  | 			ParallelAnimation { | 
					
						
							| 
									
										
										
										
											2017-10-05 12:15:33 -07: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-04 21:53:40 -07:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-10-05 12:15:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				NumberAnimation { | 
					
						
							| 
									
										
										
										
											2017-10-04 21:53:40 -07:00
										 |  |  | 					target: detailsEditFlickable | 
					
						
							| 
									
										
										
										
											2017-10-05 12:15:33 -07:00
										 |  |  | 					property: "contentY" | 
					
						
							|  |  |  | 					to: 0 | 
					
						
							|  |  |  | 					duration: 200 | 
					
						
							| 
									
										
										
										
											2017-10-04 21:53:40 -07: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 06:47:27 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 21:53:40 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-01-20 14:07:06 -08:00
										 |  |  | 	] | 
					
						
							| 
									
										
										
										
											2016-02-12 04:51:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 09:24:19 -07:00
										 |  |  | 	Component.onCompleted: { | 
					
						
							|  |  |  | 		// when we first create this page, we are in "view" mode and shouldn't show
 | 
					
						
							|  |  |  | 		// a virtual keyboard. This should be unnecessary, but in some circumstances,
 | 
					
						
							|  |  |  | 		// when the user editied a dive, went back to the dive list, and then tried to
 | 
					
						
							|  |  |  | 		// view a different dive, the Android keyboard would pop up
 | 
					
						
							|  |  |  | 		Qt.inputMethod.hide() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	onHeightChanged: { | 
					
						
							|  |  |  | 		// even with the explicit attempt to hide the keyboard above, it STILL sometimes
 | 
					
						
							|  |  |  | 		// pops up when first showing a dive. So let's get more aggressive
 | 
					
						
							|  |  |  | 		// QML doesn't let me trigger this based on the visible property of the inputMethod,
 | 
					
						
							|  |  |  | 		// but when it becomes visible, the height of the page changes, so let's use that
 | 
					
						
							|  |  |  | 		if (Qt.inputMethod.visible && state === "view") | 
					
						
							|  |  |  | 			Qt.inputMethod.hide() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 	property QtObject deleteAction: Kirigami.Action { | 
					
						
							| 
									
										
										
										
											2016-05-03 21:24:00 +02:00
										 |  |  | 		text: qsTr("Delete dive") | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:19 +01:00
										 |  |  | 		icon { | 
					
						
							| 
									
										
										
										
											2018-06-17 15:30:02 +02:00
										 |  |  | 			name: ":/icons/trash-empty.svg" | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:19 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-12-21 13:57:10 -08:00
										 |  |  | 		color: subsurfaceTheme.textColor | 
					
						
							| 
									
										
										
										
											2020-01-11 15:29:45 -08:00
										 |  |  | 		onTriggered: manager.deleteDive(currentItem.modelData.id) | 
					
						
							| 
									
										
										
										
											2016-03-23 20:33:17 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 12:22:36 -07:00
										 |  |  | 	property QtObject cancelAction: Kirigami.Action { | 
					
						
							|  |  |  | 		text: qsTr("Cancel edit") | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:19 +01:00
										 |  |  | 		icon { | 
					
						
							| 
									
										
										
										
											2018-06-17 15:30:02 +02:00
										 |  |  | 			name: ":/icons/dialog-cancel.svg" | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:19 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-12-21 13:57:10 -08:00
										 |  |  | 		color: subsurfaceTheme.textColor | 
					
						
							| 
									
										
										
										
											2017-10-04 12:22:36 -07:00
										 |  |  | 		onTriggered: { | 
					
						
							|  |  |  | 			endEditMode() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 	property QtObject mapAction: Kirigami.Action { | 
					
						
							| 
									
										
										
										
											2016-05-03 21:24:00 +02:00
										 |  |  | 		text: qsTr("Show on map") | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:19 +01:00
										 |  |  | 		icon { | 
					
						
							| 
									
										
										
										
											2018-04-16 17:28:53 -07:00
										 |  |  | 			name: ":/icons/gps" | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:19 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-12-21 13:57:10 -08:00
										 |  |  | 		color: subsurfaceTheme.textColor | 
					
						
							| 
									
										
										
										
											2016-04-19 05:09:17 -07:00
										 |  |  | 		onTriggered: { | 
					
						
							| 
									
										
										
										
											2018-03-08 22:22:35 +02:00
										 |  |  | 			showMap() | 
					
						
							| 
									
										
										
										
											2019-10-19 22:12:50 -04:00
										 |  |  | 			mapPage.centerOnDiveSite(currentItem.modelData.diveSite) | 
					
						
							| 
									
										
										
										
											2016-04-19 05:09:17 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 	actions.main: Kirigami.Action { | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:19 +01:00
										 |  |  | 		icon { | 
					
						
							| 
									
										
										
										
											2020-03-20 12:20:43 -07:00
										 |  |  | 			name: state !== "view" ? ":/icons/document-save.svg" : | 
					
						
							|  |  |  | 						 ":/icons/document-edit.svg" | 
					
						
							| 
									
										
										
										
											2017-11-19 19:27:45 +01:00
										 |  |  | 			color: subsurfaceTheme.primaryColor | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:19 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-03 09:54:49 +02:00
										 |  |  | 		text: state !== "view" ? qsTr("Save edits") : qsTr("Edit dive") | 
					
						
							| 
									
										
										
										
											2016-01-12 01:15:02 +01:00
										 |  |  | 		onTriggered: { | 
					
						
							| 
									
										
										
										
											2017-03-18 14:25:59 -07:00
										 |  |  | 			manager.appendTextToLog("save/edit button triggered") | 
					
						
							| 
									
										
										
										
											2016-02-13 21:25:10 -08:00
										 |  |  | 			if (state === "edit" || state === "add") { | 
					
						
							|  |  |  | 				detailsEdit.saveData() | 
					
						
							| 
									
										
										
										
											2016-01-29 06:47:27 -08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:06 +01:00
										 |  |  | 				startEditMode() | 
					
						
							| 
									
										
										
										
											2015-12-04 03:32:52 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-01-12 01:15:02 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 08:41:42 -08:00
										 |  |  | 	onBackRequested: { | 
					
						
							| 
									
										
										
										
											2020-03-31 09:40:28 -07:00
										 |  |  | 		// if one of the drawers/menus is open, the back button should close those
 | 
					
						
							|  |  |  | 		if (globalDrawer.visible) { | 
					
						
							|  |  |  | 			globalDrawer.close() | 
					
						
							|  |  |  | 			event.accepted = true | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (contextDrawer.visible) { | 
					
						
							|  |  |  | 			contextDrawer.close() | 
					
						
							|  |  |  | 			event.accepted = true | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// if we didn't close either of the drawer, check if we need to close add/edit
 | 
					
						
							|  |  |  | 		if (event.accepted === false) { | 
					
						
							|  |  |  | 			if (state === "edit") { | 
					
						
							|  |  |  | 				endEditMode() | 
					
						
							|  |  |  | 				event.accepted = true; | 
					
						
							|  |  |  | 			} else if (state === "add") { | 
					
						
							|  |  |  | 				endEditMode() | 
					
						
							|  |  |  | 				pageStack.pop() | 
					
						
							|  |  |  | 				event.accepted = true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-02-08 08:41:42 -08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-31 09:40:28 -07:00
										 |  |  | 		// if we were in view mode and no menus are open, don't accept the event and pop the page
 | 
					
						
							| 
									
										
										
										
											2016-02-08 08:41:42 -08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 06:01:36 -07:00
										 |  |  | 	onCurrentItemChanged: { | 
					
						
							| 
									
										
										
										
											2019-10-22 17:06:29 -04:00
										 |  |  | 		if (currentItem && currentItem.modelData) { | 
					
						
							|  |  |  | 			// make sure the core data structures reflect that this dive is selected
 | 
					
						
							|  |  |  | 			manager.selectDive(currentItem.modelData.id) | 
					
						
							|  |  |  | 			// update the map to show the highlighted flag and center on it
 | 
					
						
							|  |  |  | 			if (rootItem.pageIndex(mapPage) !== -1) { | 
					
						
							|  |  |  | 				mapPage.reloadMap() | 
					
						
							|  |  |  | 				mapPage.centerOnDiveSite(currentItem.modelData.diveSite) | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-10-07 22:38:20 -05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-04-14 06:01:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:07 +01:00
										 |  |  | 	function endEditMode() { | 
					
						
							| 
									
										
										
										
											2020-03-26 11:47:18 -07:00
										 |  |  | 		// we need to clean up either an edit or an add - and in case this
 | 
					
						
							|  |  |  | 		// was an add, we need to undo the addDive action that created the empty dive
 | 
					
						
							|  |  |  | 		// and we should also go back to the DiveDetails where we came from...
 | 
					
						
							|  |  |  | 		manager.appendTextToLog("endEditMode called with state " + state) | 
					
						
							|  |  |  | 		if (state === "add") { | 
					
						
							|  |  |  | 			manager.undo() | 
					
						
							|  |  |  | 			pageStack.pop() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// now all that is left is to cancel the edit/add state
 | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:07 +01:00
										 |  |  | 		state = "view"; | 
					
						
							| 
									
										
										
										
											2017-07-31 18:52:01 +02:00
										 |  |  | 		focus = false; | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:07 +01: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 17:13:15 +01:00
										 |  |  | 		detailsEdit.clearDetailsEdit(); | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:07 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:06 +01:00
										 |  |  | 	function startEditMode() { | 
					
						
							| 
									
										
										
										
											2017-06-21 16:30:10 -07:00
										 |  |  | 		if (!currentItem.modelData) { | 
					
						
							| 
									
										
										
										
											2019-10-30 09:16:58 +01:00
										 |  |  | 			manager.appendTextToLog("DiveDetails trying to access undefined currentItem.modelData") | 
					
						
							| 
									
										
										
										
											2017-06-21 16:30:10 -07:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:06 +01: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-10-19 22:12:50 -04:00
										 |  |  | 		var modelData = currentItem.modelData | 
					
						
							|  |  |  | 		dive_id = modelData.id | 
					
						
							|  |  |  | 		number = modelData.number | 
					
						
							|  |  |  | 		date = modelData.dateTime | 
					
						
							| 
									
										
										
										
											2020-01-12 22:42:57 -08:00
										 |  |  | 		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 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-10-19 22:12:50 -04:00
										 |  |  | 		gps = modelData.gps | 
					
						
							|  |  |  | 		duration = modelData.duration | 
					
						
							|  |  |  | 		depth = modelData.depth | 
					
						
							|  |  |  | 		airtemp = modelData.airTemp | 
					
						
							|  |  |  | 		watertemp = modelData.waterTemp | 
					
						
							|  |  |  | 		suitIndex = manager.suitList.indexOf(modelData.suit) | 
					
						
							|  |  |  | 		buddyText = modelData.buddy; | 
					
						
							|  |  |  | 		divemasterText = modelData.diveMaster | 
					
						
							| 
									
										
										
										
											2021-08-15 19:55:17 -07:00
										 |  |  | 		tagText = modelData.tags | 
					
						
							| 
									
										
										
										
											2019-10-19 22:12:50 -04:00
										 |  |  | 		notes = modelData.notes | 
					
						
							|  |  |  | 		if (modelData.singleWeight) { | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:06 +01:00
										 |  |  | 			// we have only one weight, go ahead, have fun and edit it
 | 
					
						
							| 
									
										
										
										
											2019-10-19 22:12:50 -04:00
										 |  |  | 			weight = modelData.sumWeight | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:06 +01:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			// careful when translating, this text is "magic" in DiveDetailsEdit.qml
 | 
					
						
							|  |  |  | 			weight = "cannot edit multiple weight systems" | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-10-20 07:37:51 -04:00
										 |  |  | 		startpressure = modelData.startPressure | 
					
						
							|  |  |  | 		endpressure = modelData.endPressure | 
					
						
							|  |  |  | 		usedGas = modelData.firstGas | 
					
						
							|  |  |  | 		usedCyl = modelData.getCylinder | 
					
						
							|  |  |  | 		cylinderIndex0 = modelData.cylinderList.indexOf(usedCyl[0]) | 
					
						
							|  |  |  | 		cylinderIndex1 = modelData.cylinderList.indexOf(usedCyl[1]) | 
					
						
							|  |  |  | 		cylinderIndex2 = modelData.cylinderList.indexOf(usedCyl[2]) | 
					
						
							|  |  |  | 		cylinderIndex3 = modelData.cylinderList.indexOf(usedCyl[3]) | 
					
						
							|  |  |  | 		cylinderIndex4 = modelData.cylinderList.indexOf(usedCyl[4]) | 
					
						
							| 
									
										
										
										
											2019-10-19 22:12:50 -04:00
										 |  |  | 		rating = modelData.rating | 
					
						
							|  |  |  | 		visibility = modelData.viz | 
					
						
							| 
									
										
										
										
											2020-12-30 12:32:57 -08:00
										 |  |  | 		detailsEdit.focusReset() | 
					
						
							| 
									
										
										
										
											2016-02-07 22:23:06 +01:00
										 |  |  | 		diveDetailsPage.state = "edit" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 21:26:54 +01:00
										 |  |  | 	Item { | 
					
						
							| 
									
										
										
										
											2015-11-12 00:40:13 +01:00
										 |  |  | 		anchors.fill: parent | 
					
						
							| 
									
										
										
										
											2017-10-04 12:22:36 -07:00
										 |  |  | 		visible: diveDetailsPage.state == "view" | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 		ListView { | 
					
						
							|  |  |  | 			id: diveDetailsListView | 
					
						
							| 
									
										
										
										
											2015-11-30 01:12:47 +01:00
										 |  |  | 			anchors.fill: parent | 
					
						
							| 
									
										
										
										
											2020-03-06 12:48:47 +01:00
										 |  |  | 			model: swipeModel | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 			currentIndex: -1 | 
					
						
							|  |  |  | 			boundsBehavior: Flickable.StopAtBounds | 
					
						
							|  |  |  | 			maximumFlickVelocity: parent.width * 5 | 
					
						
							|  |  |  | 			orientation: ListView.Horizontal | 
					
						
							| 
									
										
										
										
											2017-10-26 22:26:14 +02:00
										 |  |  | 			highlightFollowsCurrentItem: false | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 			focus: true | 
					
						
							| 
									
										
										
										
											2018-09-30 20:42:28 +02:00
										 |  |  | 			clip: true | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 			snapMode: ListView.SnapOneItem | 
					
						
							|  |  |  | 			highlightRangeMode: ListView.StrictlyEnforceRange | 
					
						
							|  |  |  | 			onMovementEnded: { | 
					
						
							|  |  |  | 				currentIndex = indexAt(contentX+1, 1); | 
					
						
							| 
									
										
										
										
											2019-12-21 20:41:06 +01:00
										 |  |  | 				manager.selectSwipeRow(currentIndex) | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			delegate: Flickable { | 
					
						
							|  |  |  | 				id: internalScrollView | 
					
						
							|  |  |  | 				width: diveDetailsListView.width | 
					
						
							|  |  |  | 				height: diveDetailsListView.height | 
					
						
							|  |  |  | 				contentHeight: diveDetails.height | 
					
						
							| 
									
										
										
										
											2016-03-08 21:26:54 +01:00
										 |  |  | 				boundsBehavior: Flickable.StopAtBounds | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 				property var modelData: model | 
					
						
							|  |  |  | 				DiveDetailsView { | 
					
						
							|  |  |  | 					id: diveDetails | 
					
						
							|  |  |  | 					width: internalScrollView.width | 
					
						
							| 
									
										
										
										
											2020-12-21 04:38:48 -08:00
										 |  |  | 					myId: model.id | 
					
						
							| 
									
										
										
										
											2015-12-04 01:38:04 +01:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 				ScrollBar.vertical: ScrollBar { } | 
					
						
							| 
									
										
										
										
											2015-07-21 15:00:29 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-31 16:15:14 +02:00
										 |  |  | 			ScrollIndicator.horizontal: ScrollIndicator { } | 
					
						
							| 
									
										
										
										
											2019-12-08 17:42:56 +01:00
										 |  |  | 			Connections { | 
					
						
							| 
									
										
										
										
											2020-03-06 12:48:47 +01:00
										 |  |  | 				target: swipeModel | 
					
						
							| 
									
										
										
										
											2019-12-08 17:42:56 +01:00
										 |  |  | 				onCurrentDiveChanged: { | 
					
						
							|  |  |  | 					currentIndex = index.row | 
					
						
							|  |  |  | 					diveDetailsListView.positionViewAtIndex(currentIndex, ListView.End) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-21 15:00:29 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-04 12:22:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-04 12:27:13 -07:00
										 |  |  | 	Flickable { | 
					
						
							|  |  |  | 		id: detailsEditFlickable | 
					
						
							|  |  |  | 		anchors.fill: parent | 
					
						
							|  |  |  | 		leftMargin: Kirigami.Units.smallSpacing | 
					
						
							|  |  |  | 		rightMargin: Kirigami.Units.smallSpacing | 
					
						
							|  |  |  | 		contentHeight: detailsEdit.height | 
					
						
							| 
									
										
										
										
											2017-10-04 21:53:40 -07:00
										 |  |  | 		// start invisible and scaled down, to get the transition
 | 
					
						
							|  |  |  | 		// off to the right start
 | 
					
						
							|  |  |  | 		visible: false | 
					
						
							|  |  |  | 		scale: 0.3 | 
					
						
							| 
									
										
										
										
											2017-10-04 12:27:13 -07:00
										 |  |  | 		DiveDetailsEdit { | 
					
						
							|  |  |  | 			id: detailsEdit | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ScrollBar.vertical: ScrollBar { } | 
					
						
							| 
									
										
										
										
											2016-01-12 01:15:02 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-21 15:00:29 +03:00
										 |  |  | } |