Skip to content

Commit a51820f

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 a51820f

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ TextInput {
4848
Behavior on color {
4949
ColorAnimation { duration: 150 }
5050
}
51+
52+
function checkValidity(minVal, maxVal, input) {
53+
if (input < minVal || input > maxVal) {
54+
return false
55+
} else {
56+
return true
57+
}
58+
}
5159
}

0 commit comments

Comments
 (0)