DetailPage: guardie port undefined, log init/refresh, Z0 tratteggiata manuale (no setLineDash Qt5.6)

This commit is contained in:
2026-08-31 15:18:25 +02:00
parent 91fc25dd12
commit f38a677d46
+49 -32
View File
@@ -27,6 +27,11 @@ Page {
function init() { function init() {
nearPort = null nearPort = null
nearKm = 0 nearKm = 0
console.log("[tide] DetailPage.init custom:", custom, "port:", port ? port[0] : "UNDEFINED")
if (!port) {
console.log("[tide] DetailPage.init: port undefined, niente da caricare")
return
}
if (custom && port.length > 5 && port[5] !== "") { if (custom && port.length > 5 && port[5] !== "") {
var np = Tides.nearestPort(port[2], port[3]) var np = Tides.nearestPort(port[2], port[3])
if (np.port !== null) { if (np.port !== null) {
@@ -38,36 +43,44 @@ Page {
} }
function refresh() { function refresh() {
if (!port) return if (!port) {
// eventi console.log("[tide] refresh: port UNDEFINED")
eventsModel.clear() return
var ex = Tides.extrema(port, new Date(), days)
var n = Math.min(ex.length, 6)
for (var i = 0; i < n; i++) {
eventsModel.append({
kind: ex[i].kind,
date: Tides.fmtDate(ex[i].t),
time: Tides.fmtHM(ex[i].t),
height: Tides.fmtH(ex[i].h, unit)
})
} }
// astro console.log("[tide] refresh:", port[0], "days:", days, "unit:", unit)
var mp = Tides.moonPhase(new Date()) try {
moonLabel.text = mp.icon + " " + moonNames[mp.idx] + " (" + qsTr("age %1 d").arg(mp.age.toFixed(1)) + ")" // eventi
var st = Tides.sunTimes(port[2], new Date()) eventsModel.clear()
sunLabel.text = Tides.fmtHM(new Date(0, 0, 0, st.rise, 0)) + " / " + Tides.fmtHM(new Date(0, 0, 0, st.set, 0)) + " " + qsTr("(solar time)") var ex = Tides.extrema(port, new Date(), days)
rangeLabel.text = "±" + ((port[4][1][0] + port[4][2][0]) * 2).toFixed(2) + " m" var n = Math.min(ex.length, 6)
// info curva for (var i = 0; i < n; i++) {
var f = port[5] || "" eventsModel.append({
if (f.indexOf("near:") === 0) { kind: ex[i].kind,
var p = f.split(":") date: Tides.fmtDate(ex[i].t),
curveInfo.text = qsTr("Constants of the port of %1 (distance %2°)").arg(p[1]).arg(p[2]) time: Tides.fmtHM(ex[i].t),
} else if (f === "synth") { height: Tides.fmtH(ex[i].h, unit)
curveInfo.text = qsTr("Estimated constants from lat/lon (synthetic model)") })
} else { }
curveInfo.text = qsTr("Z₀ %1 m · 7 harmonic constituents").arg(port[4][0].toFixed(2)) // astro
var mp = Tides.moonPhase(new Date())
moonLabel.text = mp.icon + " " + moonNames[mp.idx] + " (" + qsTr("age %1 d").arg(mp.age.toFixed(1)) + ")"
var st = Tides.sunTimes(port[2], new Date())
sunLabel.text = Tides.fmtHM(new Date(0, 0, 0, st.rise, 0)) + " / " + Tides.fmtHM(new Date(0, 0, 0, st.set, 0)) + " " + qsTr("(solar time)")
rangeLabel.text = "±" + ((port[4][1][0] + port[4][2][0]) * 2).toFixed(2) + " m"
// info curva
var f = port[5] || ""
if (f.indexOf("near:") === 0) {
var p = f.split(":")
curveInfo.text = qsTr("Constants of the port of %1 (distance %2°)").arg(p[1]).arg(p[2])
} else if (f === "synth") {
curveInfo.text = qsTr("Estimated constants from lat/lon (synthetic model)")
} else {
curveInfo.text = qsTr("Z₀ %1 m · 7 harmonic constituents").arg(port[4][0].toFixed(2))
}
cv.requestPaint()
} catch (e) {
console.log("[tide] refresh error:", e)
} }
cv.requestPaint()
} }
property var moonNames: [ property var moonNames: [
@@ -300,11 +313,15 @@ Page {
ctx.fillText((d.getHours() < 10 ? "0" : "") + d.getHours() + ":00", x + 3, h - 3) ctx.fillText((d.getHours() < 10 ? "0" : "") + d.getHours() + ":00", x + 3, h - 3)
} }
// Z0 tratteggiata // Z0 tratteggiata (disegno manuale: setLineDash non garantito su Qt 5.6)
ctx.setLineDash([4, 4])
ctx.strokeStyle = Theme.rgba(Theme.secondaryColor, 0.6) ctx.strokeStyle = Theme.rgba(Theme.secondaryColor, 0.6)
ctx.beginPath(); ctx.moveTo(pad, Y(port[4][0])); ctx.lineTo(w - pad, Y(port[4][0])); ctx.stroke() var zy = Y(port[4][0])
ctx.setLineDash([]) for (var zx = pad; zx < w - pad; zx += 10) {
ctx.beginPath()
ctx.moveTo(zx, zy)
ctx.lineTo(Math.min(zx + 5, w - pad), zy)
ctx.stroke()
}
// curva // curva
ctx.strokeStyle = Theme.highlightColor ctx.strokeStyle = Theme.highlightColor