From 7926d90aa82875e5c7e87e8c41c766c1f1d156c0 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Mon, 24 Mar 2025 14:18:15 -0600 Subject: [PATCH] AlarmForm: create duration and snooze models correctly Currently these are created imperatively to work around the fact that ListItem can't accept i18n() strings. This imperative assignment breaks implicitWidth bindings on the Repeater object, which bubbles up and eventually causes the dialog to have a content size of zero. Instead, create the data models as arrays of dictionaries, which preserves the bindings and is the recommended way to do this sort of lightweight custom model. --- src/kclock/qml/alarm/AlarmForm.qml | 64 ++++++++++++++---------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/kclock/qml/alarm/AlarmForm.qml b/src/kclock/qml/alarm/AlarmForm.qml index 29644d8..969ad47 100644 --- a/src/kclock/qml/alarm/AlarmForm.qml +++ b/src/kclock/qml/alarm/AlarmForm.qml @@ -129,30 +129,27 @@ Kirigami.FormLayout { } } title: i18n("Select Ring Duration") - model: ListModel { - // we can't use i18n with ListElement - Component.onCompleted: { - append({"name": i18n("None"), "value": -1}); - append({"name": i18n("1 minute"), "value": 1}); - append({"name": i18n("2 minutes"), "value": 2}); - append({"name": i18n("5 minutes"), "value": 5}); - append({"name": i18n("10 minutes"), "value": 10}); - append({"name": i18n("15 minutes"), "value": 15}); - append({"name": i18n("30 minutes"), "value": 30}); - append({"name": i18n("1 hour"), "value": 60}); - } - } - + model: [ + {"name": i18n("None"), "value": -1}, + {"name": i18n("1 minute"), "value": 1}, + {"name": i18n("2 minutes"), "value": 2}, + {"name": i18n("5 minutes"), "value": 5}, + {"name": i18n("10 minutes"), "value": 10}, + {"name": i18n("15 minutes"), "value": 15}, + {"name": i18n("30 minutes"), "value": 30}, + {"name": i18n("1 hour"), "value": 60} + ] + dialogDelegate: RadioDelegate { implicitWidth: Kirigami.Units.gridUnit * 16 topPadding: Kirigami.Units.smallSpacing * 2 bottomPadding: Kirigami.Units.smallSpacing * 2 - - text: name - checked: root.formRingDuration == value + + text: modelData.name + checked: root.formRingDuration == modelData.value onCheckedChanged: { if (checked) { - root.formRingDuration = value; + root.formRingDuration = modelData.value; } } } @@ -167,29 +164,26 @@ Kirigami.FormLayout { Kirigami.FormData.label: i18n("Snooze Length:") title: i18n("Select Snooze Length") text: formSnoozeDuration === 1 ? i18n("1 minute") : i18n("%1 minutes", formSnoozeDuration) - model: ListModel { - // we can't use i18n with ListElement - Component.onCompleted: { - append({"name": i18n("1 minute"), "value": 1}); - append({"name": i18n("2 minutes"), "value": 2}); - append({"name": i18n("5 minutes"), "value": 5}); - append({"name": i18n("10 minutes"), "value": 10}); - append({"name": i18n("15 minutes"), "value": 15}); - append({"name": i18n("30 minutes"), "value": 30}); - append({"name": i18n("1 hour"), "value": 60}); - } - } - + model: [ + {"name": i18n("1 minute"), "value": 1}, + {"name": i18n("2 minutes"), "value": 2}, + {"name": i18n("5 minutes"), "value": 5}, + {"name": i18n("10 minutes"), "value": 10}, + {"name": i18n("15 minutes"), "value": 15}, + {"name": i18n("30 minutes"), "value": 30}, + {"name": i18n("1 hour"), "value": 60}, + ] + dialogDelegate: RadioDelegate { implicitWidth: Kirigami.Units.gridUnit * 16 topPadding: Kirigami.Units.smallSpacing * 2 bottomPadding: Kirigami.Units.smallSpacing * 2 - - text: name - checked: root.formSnoozeDuration == value + + text: modelData.name + checked: root.formSnoozeDuration == modelData.value onCheckedChanged: { if (checked) { - root.formSnoozeDuration = value; + root.formSnoozeDuration = modelData.value; } } } -- GitLab