Skip to content

Commit 524decd

Browse files
committed
qml: Validate input for dbcache, threads, and prune target settings
Validates that the input for these settings is not less or larger than the allowed values. If so, displays an informational error text.
1 parent 317b1a5 commit 524decd

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

src/qml/components/DeveloperOptions.qml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ ColumnLayout {
2727
id: dbcacheSetting
2828
Layout.fillWidth: true
2929
header: qsTr("Database cache size (MiB)")
30+
errorText: qsTr("This is not a valid cache size. Please choose a value between %1 and %2 MiB.").arg(optionsModel.minDbcacheSizeMiB).arg(optionsModel.maxDbcacheSizeMiB)
31+
showErrorText: false
3032
actionItem: ValueInput {
3133
parentState: dbcacheSetting.state
3234
description: optionsModel.dbcacheSizeMiB
3335
onEditingFinished: {
34-
optionsModel.dbcacheSizeMiB = parseInt(text)
35-
dbcacheSetting.forceActiveFocus()
36+
if (checkValidity(optionsModel.minDbcacheSizeMiB, optionsModel.maxDbcacheSizeMiB, parseInt(text))) {
37+
optionsModel.dbcacheSizeMiB = parseInt(text)
38+
dbcacheSetting.forceActiveFocus()
39+
dbcacheSetting.showErrorText = false
40+
} else {
41+
dbcacheSetting.showErrorText = true
42+
}
3643
}
3744
}
3845
onClicked: {
@@ -45,12 +52,19 @@ ColumnLayout {
4552
id: parSetting
4653
Layout.fillWidth: true
4754
header: qsTr("Script verification threads")
55+
errorText: qsTr("This is not a valid thread count. Please choose a value between %1 and %2 threads.").arg(optionsModel.minScriptThreads).arg(optionsModel.maxScriptThreads)
56+
showErrorText: !loadedItem.acceptableInput && loadedItem.length > 0
4857
actionItem: ValueInput {
4958
parentState: parSetting.state
5059
description: optionsModel.scriptThreads
5160
onEditingFinished: {
52-
optionsModel.scriptThreads = parseInt(text)
53-
parSetting.forceActiveFocus()
61+
if (checkValidity(optionsModel.minScriptThreads, optionsModel.maxScriptThreads, parseInt(text))) {
62+
optionsModel.scriptThreads = parseInt(text)
63+
parSetting.forceActiveFocus()
64+
parSetting.showErrorText = false
65+
} else {
66+
parSetting.showErrorText = true
67+
}
5468
}
5569
}
5670
onClicked: {

src/qml/components/StorageSettings.qml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ ColumnLayout {
3333
id: pruneTargetSetting
3434
Layout.fillWidth: true
3535
header: qsTr("Storage limit (GB)")
36+
errorText: qsTr("This is not a valid prune target. Please choose a value that is equal to or larger than 1GB")
37+
showErrorText: false
3638
actionItem: ValueInput {
3739
parentState: pruneTargetSetting.state
3840
description: optionsModel.pruneSizeGB
3941
onEditingFinished: {
40-
optionsModel.pruneSizeGB = parseInt(text)
41-
pruneTargetSetting.forceActiveFocus()
42+
if (parseInt(text) < 1) {
43+
pruneTargetSetting.showErrorText = true
44+
} else {
45+
optionsModel.pruneSizeGB = parseInt(text)
46+
pruneTargetSetting.forceActiveFocus()
47+
pruneTargetSetting.showErrorText = false
48+
}
4249
}
4350
}
4451
onClicked: {

src/qml/controls/ValueInput.qml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ TextInput {
1414
property color textColor: root.filled ? Theme.color.neutral9 : Theme.color.neutral5
1515
enabled: true
1616
state: root.parentState
17+
validator: IntValidator{}
18+
maximumLength: 5
1719

1820
states: [
1921
State {
@@ -48,4 +50,12 @@ TextInput {
4850
Behavior on color {
4951
ColorAnimation { duration: 150 }
5052
}
53+
54+
function checkValidity(minVal, maxVal, input) {
55+
if (input < minVal || input > maxVal) {
56+
return false
57+
} else {
58+
return true
59+
}
60+
}
5161
}

0 commit comments

Comments
 (0)