Skip to content

Commit

Permalink
Add support for time selection in data plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
miikasda committed Jul 23, 2024
1 parent 94ee707 commit 6e38501
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions qml/pages/PlotDataPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Sailfish.Share 1.0
import "../modules/GraphData"

Page {
id: plotDataPage

property var startTime: pageStack.pop().startTime
property var endTime: pageStack.pop().endTime
Expand All @@ -34,15 +35,9 @@ Page {
property var humidityData: []
property var pressureData: []

function calculateUnixTimestamp(day, month, year, start) {
function calculateUnixTimestamp(minute, hour, day, month, year) {
var date = new Date(year, month - 1, day);
if (start) {
// Set the time to the start of the day (00:00:00)
date.setHours(0, 0, 0, 0);
} else {
// Set the time to the end of the day (23:59:59)
date.setHours(23, 59, 59, 999);
}
date.setHours(hour, minute, 0, 0);
var unixTimestamp = Math.floor(date.getTime() / 1000);
return unixTimestamp;
}
Expand Down Expand Up @@ -250,22 +245,29 @@ Page {
anchors.top: parent.top
width: parent.width - leftMargin - rightMargin
anchors.horizontalCenter: parent.horizontalCenter
text: "Start date"
text: "Start time"
property bool clicked: false

onClicked: {
var dialog = pageStack.push(startPicker, {})
dialog.accepted.connect(function() {
startDateButton.text = "Start date: " + dialog.dateText
startTime = calculateUnixTimestamp(dialog.day, dialog.month, dialog.year, true)
startDateButton.clicked = true
var startDatePicker = pageStack.push("Sailfish.Silica.DatePickerDialog", {})
startDatePicker.accepted.connect(function() {
// Ask for time
var startTimePicker = pageStack.push("Sailfish.Silica.TimePickerDialog", {
hourMode: DateTime.TwentyFourHours,
hour: 0,
minute: 0
})
// Set plotDataPage as return destination on accept,
// otherwise we will return to datepicker
startTimePicker.acceptDestinationAction = PageStackAction.Pop
startTimePicker.acceptDestination = plotDataPage
startTimePicker.accepted.connect(function() {
startDateButton.text = "Start time: " + startDatePicker.dateText + " " + startTimePicker.timeText
startTime = calculateUnixTimestamp(startTimePicker.minute, startTimePicker.hour, startDatePicker.day, startDatePicker.month, startDatePicker.year)
startDateButton.clicked = true
})
})
}

Component {
id: startPicker
DatePickerDialog {}
}
}

// Whitespace inbetween buttons
Expand All @@ -281,22 +283,27 @@ Page {
anchors.top: whiteSpace.bottom
width: parent.width - leftMargin - rightMargin
anchors.horizontalCenter: parent.horizontalCenter
text: "End date"
text: "End time"
property bool clicked: false

onClicked: {
var dialog = pageStack.push(endPicker, {})
dialog.accepted.connect(function() {
endDateButton.text = "End date: " + dialog.dateText
endTime = calculateUnixTimestamp(dialog.day, dialog.month, dialog.year, false)
endDateButton.clicked = true
var endDatePicker = pageStack.push("Sailfish.Silica.DatePickerDialog", {})
endDatePicker.accepted.connect(function() {
// Ask for time
var endTimePicker = pageStack.push("Sailfish.Silica.TimePickerDialog", {
hourMode: DateTime.TwentyFourHours,
hour: 23,
minute: 59
})
endTimePicker.acceptDestinationAction = PageStackAction.Pop
endTimePicker.acceptDestination = plotDataPage
endTimePicker.accepted.connect(function() {
endDateButton.text = "End time: " + endDatePicker.dateText + " " + endTimePicker.timeText
endTime = calculateUnixTimestamp(endTimePicker.minute, endTimePicker.hour, endDatePicker.day, endDatePicker.month, endDatePicker.year)
endDateButton.clicked = true
})
})
}

Component {
id: endPicker
DatePickerDialog {}
}
}
}
}
Expand Down

0 comments on commit 6e38501

Please sign in to comment.