fix critici: PullDownMenu dentro lista/flickable (figli di Page non funzionano su questo kit); via setTimeout (non esiste in QML JS Qt 5.6) — ripara sea state e ricerca online

This commit is contained in:
2026-09-02 18:27:48 +02:00
parent d2f738ba7d
commit e965b78d56
2 changed files with 44 additions and 57 deletions
+37 -39
View File
@@ -55,6 +55,26 @@ Page {
{ port: page.port }) { port: page.port })
} }
function setPreferred() {
if (!port) return
console.log("[tide] setPreferred:", port[0])
appSettings.preferredPort = port[0]
// se è un comune (custom) salva le coordinate per la cover
if (custom) {
appSettings.preferredLat = port[2]
appSettings.preferredLon = port[3]
} else {
appSettings.preferredLat = -1
appSettings.preferredLon = -1
}
pageStack.replace(Qt.resolvedUrl("MainPage.qml"))
}
function openSettings() {
console.log("[tide] openSettings")
pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
}
function refresh() { function refresh() {
if (!port) { if (!port) {
console.log("[tide] refresh: port UNDEFINED") console.log("[tide] refresh: port UNDEFINED")
@@ -107,14 +127,6 @@ Page {
if (!port) return if (!port) return
console.log("[tide] seaState fetch:", port[0]) console.log("[tide] seaState fetch:", port[0])
var xhr = new XMLHttpRequest() var xhr = new XMLHttpRequest()
var done = false
var to = setTimeout(function() {
if (!done) {
done = true
console.log("[tide] seaState timeout")
seaFail()
}
}, 12000)
xhr.open("GET", xhr.open("GET",
"https://marine-api.open-meteo.com/v1/marine?latitude=" + port[2] "https://marine-api.open-meteo.com/v1/marine?latitude=" + port[2]
+ "&longitude=" + port[3] + "&longitude=" + port[3]
@@ -122,9 +134,6 @@ Page {
true) true)
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
if (done) return
done = true
clearTimeout(to)
console.log("[tide] seaState status:", xhr.status) console.log("[tide] seaState status:", xhr.status)
if (xhr.status === 200) { if (xhr.status === 200) {
try { try {
@@ -378,6 +387,23 @@ Page {
Item { width: parent.width; height: Theme.paddingLarge } Item { width: parent.width; height: Theme.paddingLarge }
} }
PullDownMenu {
MenuItem {
text: qsTr("Set as preferred port")
visible: page.port && page.port[0] !== appSettings.preferredPort
onClicked: page.setPreferred()
}
MenuItem {
text: qsTr("30-day calendar")
visible: page.port !== undefined
onClicked: page.openCalendar()
}
MenuItem {
text: qsTr("Settings")
onClicked: page.openSettings()
}
}
} }
// disegno della curva (stesso algoritmo del mockup) // disegno della curva (stesso algoritmo del mockup)
@@ -453,32 +479,4 @@ Page {
} }
Component.onCompleted: init() Component.onCompleted: init()
PullDownMenu {
MenuItem {
text: qsTr("Set as preferred port")
visible: page.port && page.port[0] !== appSettings.preferredPort
onClicked: {
appSettings.preferredPort = page.port[0]
// se è un comune (custom) salva le coordinate per la cover
if (page.custom) {
appSettings.preferredLat = page.port[2]
appSettings.preferredLon = page.port[3]
} else {
appSettings.preferredLat = -1
appSettings.preferredLon = -1
}
pageStack.replace(Qt.resolvedUrl("MainPage.qml"))
}
}
MenuItem {
text: qsTr("30-day calendar")
visible: page.port !== undefined
onClicked: page.openCalendar()
}
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
}
}
} }
+7 -18
View File
@@ -6,13 +6,6 @@ import "../js/comuni.js" as Comuni
Page { Page {
id: page id: page
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: page.openSettings()
}
}
// Campi di ricerca FUORI dall'header della lista: gli id dichiarati nel // Campi di ricerca FUORI dall'header della lista: gli id dichiarati nel
// componente header hanno scope chiuso e le funzioni del Page non li // componente header hanno scope chiuso e le funzioni del Page non li
// vedono (ReferenceError "filter is not defined"). // vedono (ReferenceError "filter is not defined").
@@ -42,6 +35,13 @@ Page {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
model: ListModel { id: resultModel } model: ListModel { id: resultModel }
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: page.openSettings()
}
}
footer: Item { footer: Item {
width: parent.width width: parent.width
height: resultModel.count === 0 ? Theme.itemSizeSmall * 1.6 : 0 height: resultModel.count === 0 ? Theme.itemSizeSmall * 1.6 : 0
@@ -208,21 +208,10 @@ Page {
// e supporta il filtro osm_tag=place:city per le città vere. // e supporta il filtro osm_tag=place:city per le città vere.
console.log("[tide] geoXhr:", query) console.log("[tide] geoXhr:", query)
var xhr = new XMLHttpRequest() var xhr = new XMLHttpRequest()
var done = false
var to = setTimeout(function() {
if (!done) {
done = true
console.log("[tide] geoXhr timeout")
cb(null)
}
}, 12000)
xhr.open("GET", "https://photon.komoot.io/api/?limit=1&osm_tag=place:city&q=" xhr.open("GET", "https://photon.komoot.io/api/?limit=1&osm_tag=place:city&q="
+ encodeURIComponent(query), true) + encodeURIComponent(query), true)
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
if (done) return
done = true
clearTimeout(to)
console.log("[tide] geoXhr status:", xhr.status) console.log("[tide] geoXhr status:", xhr.status)
if (xhr.status === 200) { if (xhr.status === 200) {
try { try {