| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | import QtQuick 2.6 | 
					
						
							|  |  |  | import QtQuick.Controls 2.4 | 
					
						
							|  |  |  | import QtQuick.Layouts 1.2 | 
					
						
							|  |  |  | import org.subsurfacedivelog.mobile 1.0 | 
					
						
							|  |  |  | import org.kde.kirigami 2.4 as Kirigami | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Kirigami.Page { | 
					
						
							|  |  |  | 	id: statisticsPage | 
					
						
							|  |  |  | 	objectName: "StatisticsPage" | 
					
						
							|  |  |  | 	title: qsTr("Statistics") | 
					
						
							|  |  |  | 	leftPadding: 0 | 
					
						
							|  |  |  | 	topPadding: 0 | 
					
						
							|  |  |  | 	rightPadding: 0 | 
					
						
							|  |  |  | 	bottomPadding: 0 | 
					
						
							|  |  |  | 	width: rootItem.width | 
					
						
							|  |  |  | 	implicitWidth: rootItem.width | 
					
						
							| 
									
										
										
										
											2021-01-17 17:47:14 -08:00
										 |  |  | 	background: Rectangle { color: subsurfaceTheme.backgroundColor } | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 	property bool wide: width > rootItem.height | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 	StatsManager { | 
					
						
							|  |  |  | 		id: statsManager | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-12 10:29:37 -08:00
										 |  |  | 	ChartListModel { | 
					
						
							|  |  |  | 		id: chartListModel | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 	onVisibleChanged: { | 
					
						
							|  |  |  | 		if (visible) | 
					
						
							|  |  |  | 			statsManager.doit() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 	onWidthChanged: { | 
					
						
							|  |  |  | 		if (visible) { | 
					
						
							|  |  |  | 			statsManager.doit() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-18 07:52:03 -08:00
										 |  |  | 	onWideChanged: { | 
					
						
							|  |  |  | 		// so this means we rotated the device - and sometimes after rotation
 | 
					
						
							|  |  |  | 		// the stats widget is empty.
 | 
					
						
							|  |  |  | 		rotationRedrawTrigger.start() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Timer { | 
					
						
							|  |  |  | 		// wait .5 seconds (so the OS rotation animation has a chance to run) and then set var1 again
 | 
					
						
							|  |  |  | 		// to its current value, which appears to be enough to ensure that the chart is drawn again
 | 
					
						
							|  |  |  | 		id: rotationRedrawTrigger | 
					
						
							|  |  |  | 		interval: 500 | 
					
						
							|  |  |  | 		onTriggered: statsManager.var1Changed(i1.var1currentIndex) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 10:29:37 -08:00
										 |  |  | 	Component { | 
					
						
							|  |  |  | 		id: chartListDelegate | 
					
						
							|  |  |  | 		Kirigami.AbstractListItem { | 
					
						
							|  |  |  | 			id: chartListDelegateItem | 
					
						
							|  |  |  | 			height: isHeader ? 1 + 8 * Kirigami.Units.smallSpacing : 11 * Kirigami.Units.smallSpacing // delegateInnerItem.height
 | 
					
						
							|  |  |  | 			onClicked: { | 
					
						
							|  |  |  | 				if (!isHeader) { | 
					
						
							|  |  |  | 					chartTypePopup.close() | 
					
						
							|  |  |  | 					statsManager.setChart(id) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			Item { | 
					
						
							|  |  |  | 				id: chartListDelegateInnerItem | 
					
						
							|  |  |  | 				Row { | 
					
						
							|  |  |  | 					height: childrenRect.height | 
					
						
							|  |  |  | 					spacing: Kirigami.Units.smallSpacing | 
					
						
							|  |  |  | 					Kirigami.Icon { | 
					
						
							|  |  |  | 						id: chartIcon | 
					
						
							|  |  |  | 						source: icon | 
					
						
							|  |  |  | 						width: iconSize !== undefined ? iconSize.width : 0 | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					Label { | 
					
						
							|  |  |  | 						text: chartName | 
					
						
							|  |  |  | 						font.bold: isHeader | 
					
						
							| 
									
										
										
										
											2021-01-17 17:47:14 -08:00
										 |  |  | 						color: subsurfaceTheme.textColor | 
					
						
							| 
									
										
										
										
											2021-01-12 10:29:37 -08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Popup { | 
					
						
							|  |  |  | 		id: chartTypePopup | 
					
						
							|  |  |  | 		x: Kirigami.Units.gridUnit * 2 | 
					
						
							|  |  |  | 		y: Kirigami.Units.gridUnit | 
					
						
							|  |  |  | 		width: Math.min(Kirigami.Units.gridUnit * 12, statisticsPage.width * 0.6) | 
					
						
							|  |  |  | 		height: Math.min(statisticsPage.height - 3 * Kirigami.Units.gridUnit, chartListModel.count * Kirigami.Units.gridUnit * 2.75) | 
					
						
							|  |  |  | 		modal: true | 
					
						
							|  |  |  | 		focus: true | 
					
						
							|  |  |  | 		clip: true | 
					
						
							|  |  |  | 		closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside | 
					
						
							|  |  |  | 		ListView { | 
					
						
							|  |  |  | 			id: chartTypes | 
					
						
							|  |  |  | 			model: chartListModel | 
					
						
							|  |  |  | 			anchors.fill: parent | 
					
						
							|  |  |  | 			delegate: chartListDelegate | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 	GridLayout { | 
					
						
							|  |  |  | 		anchors.fill: parent | 
					
						
							|  |  |  | 		ColumnLayout { | 
					
						
							|  |  |  | 			id: i1 | 
					
						
							|  |  |  | 			Layout.column: 0 | 
					
						
							|  |  |  | 			Layout.row: 0 | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.leftMargin: Kirigami.Units.smallSpacing | 
					
						
							|  |  |  | 			Layout.topMargin: Kirigami.Units.smallSpacing | 
					
						
							| 
									
										
										
										
											2021-01-18 07:52:03 -08:00
										 |  |  | 			property alias var1currentIndex: var1.currentIndex | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 			TemplateLabelSmall { | 
					
						
							|  |  |  | 				text: qsTr("Base variable") | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-11 08:49:23 -08:00
										 |  |  | 			TemplateSlimComboBox  { | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 				id: var1 | 
					
						
							|  |  |  | 				model: statsManager.var1List | 
					
						
							| 
									
										
										
										
											2021-01-10 18:00:19 +01:00
										 |  |  | 				currentIndex: statsManager.var1Index; | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 				onCurrentIndexChanged: { | 
					
						
							|  |  |  | 					statsManager.var1Changed(currentIndex) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ColumnLayout { | 
					
						
							|  |  |  | 			id: i2 | 
					
						
							|  |  |  | 			Layout.column: wide ? 0 : 1 | 
					
						
							|  |  |  | 			Layout.row: wide ? 1 : 0 | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.leftMargin: Kirigami.Units.smallSpacing | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 			TemplateLabelSmall { | 
					
						
							|  |  |  | 				text: qsTr("Binning") | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-11 08:49:23 -08:00
										 |  |  | 			TemplateSlimComboBox { | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 				id: var1Binner | 
					
						
							|  |  |  | 				model: statsManager.binner1List | 
					
						
							| 
									
										
										
										
											2021-01-10 18:00:19 +01:00
										 |  |  | 				currentIndex: statsManager.binner1Index; | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 				onCurrentIndexChanged: { | 
					
						
							|  |  |  | 					statsManager.var1BinnerChanged(currentIndex) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ColumnLayout { | 
					
						
							|  |  |  | 			id: i3 | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.column: wide ? 0 : 0 | 
					
						
							|  |  |  | 			Layout.row: wide ? 2 : 1 | 
					
						
							|  |  |  | 			Layout.leftMargin: Kirigami.Units.smallSpacing | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 			TemplateLabelSmall { | 
					
						
							|  |  |  | 				text: qsTr("Data") | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-11 08:49:23 -08:00
										 |  |  | 			TemplateSlimComboBox { | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 				id: var2 | 
					
						
							|  |  |  | 				model: statsManager.var2List | 
					
						
							| 
									
										
										
										
											2021-01-10 18:00:19 +01:00
										 |  |  | 				currentIndex: statsManager.var2Index; | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 				Layout.fillWidth: false | 
					
						
							|  |  |  | 				onCurrentIndexChanged: { | 
					
						
							|  |  |  | 					statsManager.var2Changed(currentIndex) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ColumnLayout { | 
					
						
							|  |  |  | 			id: i4 | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.column: wide ? 0 : 1 | 
					
						
							|  |  |  | 			Layout.row: wide ? 3 : 1 | 
					
						
							|  |  |  | 			Layout.leftMargin: Kirigami.Units.smallSpacing | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 			TemplateLabelSmall { | 
					
						
							|  |  |  | 				text: qsTr("Binning") | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-11 08:49:23 -08:00
										 |  |  | 			TemplateSlimComboBox { | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 				id: var2Binner | 
					
						
							|  |  |  | 				model: statsManager.binner2List | 
					
						
							| 
									
										
										
										
											2021-01-10 18:00:19 +01:00
										 |  |  | 				currentIndex: statsManager.binner2Index; | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 				Layout.fillWidth: false | 
					
						
							|  |  |  | 				onCurrentIndexChanged: { | 
					
						
							|  |  |  | 					statsManager.var2BinnerChanged(currentIndex) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-10 18:28:20 +01:00
										 |  |  | 		ColumnLayout { | 
					
						
							|  |  |  | 			id: i5 | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.column: wide ? 0 : 0 | 
					
						
							|  |  |  | 			Layout.row: wide ? 4 : 2 | 
					
						
							|  |  |  | 			Layout.leftMargin: Kirigami.Units.smallSpacing | 
					
						
							| 
									
										
										
										
											2021-01-10 18:28:20 +01:00
										 |  |  | 			TemplateLabelSmall { | 
					
						
							|  |  |  | 				text: qsTr("Operation") | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-11 08:49:23 -08:00
										 |  |  | 			TemplateSlimComboBox { | 
					
						
							| 
									
										
										
										
											2021-01-10 18:28:20 +01:00
										 |  |  | 				id: var2Operation | 
					
						
							|  |  |  | 				model: statsManager.operation2List | 
					
						
							|  |  |  | 				currentIndex: statsManager.operation2Index; | 
					
						
							|  |  |  | 				Layout.fillWidth: false | 
					
						
							|  |  |  | 				onCurrentIndexChanged: { | 
					
						
							|  |  |  | 					statsManager.var2OperationChanged(currentIndex) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-12 10:29:37 -08:00
										 |  |  | 		Button { | 
					
						
							|  |  |  | 			id: chartTypeButton | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.column: wide ? 0 : 1 | 
					
						
							|  |  |  | 			Layout.row: wide ? 5 : 2 | 
					
						
							| 
									
										
										
										
											2021-01-12 10:29:37 -08:00
										 |  |  | 			Layout.leftMargin: Kirigami.Units.smallSpacing | 
					
						
							|  |  |  | 			Layout.topMargin: Kirigami.Units.largeSpacing | 
					
						
							|  |  |  | 			Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | 
					
						
							|  |  |  | 			Layout.preferredWidth: Kirigami.Units.gridUnit * 8 | 
					
						
							|  |  |  | 			background: Rectangle { | 
					
						
							|  |  |  | 				color: chartTypeButton.pressed ? subsurfaceTheme.darkerPrimaryColor : subsurfaceTheme.primaryColor | 
					
						
							|  |  |  | 				antialiasing: true | 
					
						
							|  |  |  | 				radius: Kirigami.Units.smallSpacing * 2 | 
					
						
							|  |  |  | 				height: Kirigami.Units.gridUnit * 2 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			contentItem: Text { | 
					
						
							|  |  |  | 				verticalAlignment: Qt.AlignVCenter | 
					
						
							|  |  |  | 				horizontalAlignment: Qt.AlignHCenter | 
					
						
							|  |  |  | 				color: subsurfaceTheme.primaryTextColor | 
					
						
							|  |  |  | 				text: qsTr("Chart type") | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			onClicked: chartTypePopup.open() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		Item { | 
					
						
							| 
									
										
										
										
											2021-01-16 17:54:27 -08:00
										 |  |  | 			Layout.column: wide ? 0 : 2 | 
					
						
							| 
									
										
										
										
											2021-01-12 10:29:37 -08:00
										 |  |  | 			Layout.row: wide ? 6 : 2 | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 			Layout.preferredHeight: wide ? parent.height - Kirigami.Units.gridUnit * 16 : Kirigami.Units.gridUnit | 
					
						
							| 
									
										
										
										
											2021-01-16 17:54:27 -08:00
										 |  |  | 			Layout.fillWidth: wide ? false : true | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 			// just used for spacing
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		StatsView { | 
					
						
							|  |  |  | 			Layout.column: wide ? 1 : 0 | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.row: wide ? 0 : 3 | 
					
						
							|  |  |  | 			Layout.columnSpan: wide ? 1 : 3 | 
					
						
							| 
									
										
										
										
											2021-01-12 10:29:37 -08:00
										 |  |  | 			Layout.rowSpan: wide ? 7 : 1 | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 			id: statsView | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.margins: Kirigami.Units.smallSpacing | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 			Layout.fillWidth: true | 
					
						
							|  |  |  | 			Layout.fillHeight: true | 
					
						
							| 
									
										
										
										
											2021-01-09 17:54:56 +00:00
										 |  |  | 			Layout.maximumHeight: wide ? statisticsPage.height - 2 * Kirigami.Units.gridUnit : | 
					
						
							|  |  |  | 						     statisticsPage.height - 2 * Kirigami.Units.gridUnit - i4.height | 
					
						
							|  |  |  | 			Layout.maximumWidth: wide ? statisticsPage.width - 2 * Kirigami.Units.gridUnit - i4.width : | 
					
						
							|  |  |  | 						     statisticsPage.width - 2 * Kirigami.Units.smallSpacing | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Component.onCompleted: { | 
					
						
							| 
									
										
										
										
											2021-01-12 10:29:37 -08:00
										 |  |  | 		statsManager.init(statsView, chartListModel) | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-08-18 18:17:58 -07:00
										 |  |  | 	onBackRequested: { | 
					
						
							|  |  |  | 		// if the menu drawer is open, the back button should close it
 | 
					
						
							|  |  |  | 		if (globalDrawer.visible) { | 
					
						
							|  |  |  | 			globalDrawer.close() | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			showDiveList() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		event.accepted = true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-04 15:47:33 +01:00
										 |  |  | } |