From a946dc323b28d1012001ca5f1d62e730bccfde85 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Wed, 14 Feb 2024 16:41:44 +1300 Subject: [PATCH] Mobile: Add Input Validation and Conversion for Gradient Factors. Add input validation and input conversion for the gradient factor settings. Signed-off-by: Michael Keller --- mobile-widgets/qml/Settings.qml | 34 +++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/mobile-widgets/qml/Settings.qml b/mobile-widgets/qml/Settings.qml index ae8d1ac73..dad40cf40 100644 --- a/mobile-widgets/qml/Settings.qml +++ b/mobile-widgets/qml/Settings.qml @@ -633,8 +633,8 @@ TemplatePage { } } TemplateLabel { - visible: PrefTechnicalDetails.calcceiling - text: qsTr("GFLow") + enabled: PrefTechnicalDetails.calcceiling + text: qsTr("GFLow (10 to 150)") } TemplateSpinBox { visible: PrefTechnicalDetails.calcceiling @@ -645,17 +645,30 @@ TemplatePage { to: 150 stepSize: 1 value: PrefTechnicalDetails.gflow + validator: RegExpValidator { regExp: /1?\d{0,2}%?/ } textFromValue: function (value, locale) { return value + "%" } + valueFromText: function(text, locale) { + var result = parseInt(text); + + if (result < 10) + result = 10; + else if (result > 150) + result = 150; + else if (isNaN(result)) + result = 35; + + return result; + } onValueChanged: { PrefTechnicalDetails.gflow = value rootItem.settingsChanged() } } TemplateLabel { - visible: PrefTechnicalDetails.calcceiling - text: qsTr("GFHigh") + enabled: PrefTechnicalDetails.calcceiling + text: qsTr("GFHigh (10 to 150") } TemplateSpinBox { visible: PrefTechnicalDetails.calcceiling @@ -666,9 +679,22 @@ TemplatePage { to: 150 stepSize: 1 value: PrefTechnicalDetails.gfhigh + validator: RegExpValidator { regExp: /1?\d{0,2}%?/ } textFromValue: function (value, locale) { return value + "%" } + valueFromText: function(text, locale) { + var result = parseInt(text); + + if (result < 10) + result = 10; + else if (result > 150) + result = 150; + else if (isNaN(result)) + result = 70; + + return result; + } onValueChanged: { PrefTechnicalDetails.gfhigh = value rootItem.settingsChanged()