From ebdb8bd84811c4291d8ac1917131cee826f96c3f Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Sun, 6 Apr 2025 20:54:53 -0400 Subject: [PATCH] kcms/mobileshell: Use js list model instead of ListModel Use a proper JS list model instead of creating a ListModel and then appending items to it. --- kcms/mobileshell/ui/VibrationForm.qml | 26 +++---- kcms/mobileshell/ui/main.qml | 100 ++++++++++---------------- 2 files changed, 47 insertions(+), 79 deletions(-) diff --git a/kcms/mobileshell/ui/VibrationForm.qml b/kcms/mobileshell/ui/VibrationForm.qml index 37655404..0ea8c400 100644 --- a/kcms/mobileshell/ui/VibrationForm.qml +++ b/kcms/mobileshell/ui/VibrationForm.qml @@ -39,27 +39,19 @@ FormCard.FormCardPage { text: i18n("Vibration Duration") description: i18n("How long shell vibrations should be.") - property string longString: i18nc("Long duration", "Long") - property string mediumString: i18nc("Medium duration", "Medium") - property string shortString: i18nc("Short duration", "Short") - - currentIndex: indexOfValue(ShellSettings.Settings.vibrationDuration) - model: ListModel { - // we can't use i18n with ListElement - Component.onCompleted: { - append({"name": vibrationDurationDelegate.longString, "value": 100}); - append({"name": vibrationDurationDelegate.mediumString, "value": 50}); - append({"name": vibrationDurationDelegate.shortString, "value": 10}); - - // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here - vibrationDurationDelegate.currentIndex = vibrationDurationDelegate.indexOfValue(ShellSettings.Settings.vibrationDuration) - } - } + model: [ + {"name": i18nc("Long duration", "Long"), "value": 100}, + {"name": i18nc("Medium duration", "Medium"), "value": 50}, + {"name": i18nc("Short duration", "Short"), "value": 10} + ] textRole: "name" valueRole: "value" - Component.onCompleted: dialog.parent = root + Component.onCompleted: { + currentIndex = indexOfValue(ShellSettings.Settings.vibrationDuration); + dialog.parent = root; + } onCurrentValueChanged: ShellSettings.Settings.vibrationDuration = currentValue; } } diff --git a/kcms/mobileshell/ui/main.qml b/kcms/mobileshell/ui/main.qml index 394f7907..5d119326 100644 --- a/kcms/mobileshell/ui/main.qml +++ b/kcms/mobileshell/ui/main.qml @@ -85,35 +85,24 @@ KCM.SimpleKCM { FormCard.FormComboBoxDelegate { id: statusBarScaleFactorDelegate - property string tinyString: i18nc("Status bar height", "Tiny") - property string smallString: i18nc("Status bar height", "Small") - property string normalString: i18nc("Status bar height", "Normal") - property string largeString: i18nc("Status bar height","Large") - property string xlargeString: i18nc("Status bar height", "Very Large") - - text: i18n("Status Bar Size") description: i18n("Size of the top panel (needs restart).") - currentIndex: indexOfValue(ShellSettings.Settings.statusBarScaleFactor) - model: ListModel { - // We can't use i18n with ListElement, so use a property instead - Component.onCompleted: { - append({"name": statusBarScaleFactorDelegate.tinyString, "value": 1.0}); - append({"name": statusBarScaleFactorDelegate.smallString, "value": 1.15}); - append({"name": statusBarScaleFactorDelegate.normalString, "value": 1.25}); - append({"name": statusBarScaleFactorDelegate.largeString, "value": 1.5}); - append({"name": statusBarScaleFactorDelegate.xlargeString, "value": 2.0}); - - // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here - statusBarScaleFactorDelegate.currentIndex = statusBarScaleFactorDelegate.indexOfValue(ShellSettings.Settings.statusBarScaleFactor) - } - } + model: [ + {"name": i18nc("Status bar height", "Tiny"), "value": 1.0}, + {"name": i18nc("Status bar height", "Small"), "value": 1.15}, + {"name": i18nc("Status bar height", "Normal"), "value": 1.25}, + {"name": i18nc("Status bar height", "Large"), "value": 1.5}, + {"name": i18nc("Status bar height", "Very Large"), "value": 2.0} + ] textRole: "name" valueRole: "value" - Component.onCompleted: dialog.parent = root + Component.onCompleted: { + currentIndex = indexOfValue(ShellSettings.Settings.statusBarScaleFactor); + dialog.parent = root; + } onCurrentValueChanged: ShellSettings.Settings.statusBarScaleFactor = currentValue } @@ -175,22 +164,18 @@ KCM.SimpleKCM { text: i18n("Top Left Drawer Mode") description: i18n("Mode when opening from the top left.") - currentIndex: indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode) - model: ListModel { - // we can't use i18n with ListElement - Component.onCompleted: { - append({"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned}); - append({"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded}); - - // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here - topLeftActionDrawerModeDelegate.currentIndex = topLeftActionDrawerModeDelegate.indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode) - } - } + model: [ + {"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned}, + {"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded} + ] textRole: "name" valueRole: "value" - Component.onCompleted: dialog.parent = root + Component.onCompleted: { + currentIndex = indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode); + dialog.parent = root; + } onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopLeftMode = currentValue } @@ -201,21 +186,16 @@ KCM.SimpleKCM { text: i18n("Top Right Drawer Mode") description: i18n("Mode when opening from the top right.") - model: ListModel { - // we can't use i18n with ListElement - Component.onCompleted: { - append({"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned}); - append({"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded}); - - // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here - topRightActionDrawerModeDelegate.currentIndex = topRightActionDrawerModeDelegate.indexOfValue(ShellSettings.Settings.actionDrawerTopRightMode) - } - } + model: [ + {"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned}, + {"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded} + ] textRole: "name" valueRole: "value" Component.onCompleted: { + currentIndex = indexOfValue(ShellSettings.Settings.actionDrawerTopRightMode); dialog.parent = root } onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopRightMode = currentValue @@ -236,20 +216,18 @@ KCM.SimpleKCM { id: lockscreenLeftButtonDelegate text: i18nc("@label:listbox", "Left button") - model: ListModel { - Component.onCompleted: { - append({"name": quickActionButtons.noneString, "value": ShellSettings.Settings.None}); - append({"name": quickActionButtons.flashlightString, "value": ShellSettings.Settings.Flashlight}); - // append({"name": quickActionButtons.cameraString, "value": ShellSettings.Settings.Camera}); - lockscreenLeftButtonDelegate.currentIndex = lockscreenLeftButtonDelegate.indexOfValue(ShellSettings.Settings.lockscreenLeftButtonAction) - } - } + model: [ + {"name": quickActionButtons.noneString, "value": ShellSettings.Settings.None}, + {"name": quickActionButtons.flashlightString, "value": ShellSettings.Settings.Flashlight} + // {"name": quickActionButtons.cameraString, "value": ShellSettings.Settings.Camera} + ] textRole: "name" valueRole: "value" Component.onCompleted: { - dialog.parent = root + currentIndex = indexOfValue(ShellSettings.Settings.lockscreenLeftButtonAction); + dialog.parent = root; } onCurrentValueChanged: ShellSettings.Settings.lockscreenLeftButtonAction = currentValue } @@ -260,20 +238,18 @@ KCM.SimpleKCM { id: lockscreenRightButtonDelegate text: i18nc("@label:listbox", "Right button") - model: ListModel { - Component.onCompleted: { - append({"name": quickActionButtons.noneString, "value": ShellSettings.Settings.None}); - append({"name": quickActionButtons.flashlightString, "value": ShellSettings.Settings.Flashlight}); - // append({"name": quickActionButtons.cameraString, "value": ShellSettings.Settings.Camera}); - lockscreenRightButtonDelegate.currentIndex = lockscreenRightButtonDelegate.indexOfValue(ShellSettings.Settings.lockscreenRightButtonAction) - } - } + model: [ + {"name": quickActionButtons.noneString, "value": ShellSettings.Settings.None}, + {"name": quickActionButtons.flashlightString, "value": ShellSettings.Settings.Flashlight} + // {"name": quickActionButtons.cameraString, "value": ShellSettings.Settings.Camera} + ] textRole: "name" valueRole: "value" Component.onCompleted: { - dialog.parent = root + currentIndex = indexOfValue(ShellSettings.Settings.lockscreenRightButtonAction); + dialog.parent = root; } onCurrentValueChanged: ShellSettings.Settings.lockscreenRightButtonAction = currentValue }