aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-26 16:36:32 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-29 07:35:26 +0000
commitcf67efa1ea63fe11504799b9bb2329f70d99c525 (patch)
tree024fbb692210f044da403dfc8554d0b5f216766c /tests
parente4721fa68c5426d71e957dc6997753ec85f312af (diff)
SpinBox: add validator, textFromValue and valueFromText
Change-Id: I45e01199453ac5fd64b7f98c165cc12eeb0ce8c3 Task-number: QTBUG-48989 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com> Reviewed-by: Nikita Krupenko <krnekit@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-spinbox-textual.qml28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/snippets/data/qtlabscontrols-spinbox-textual.qml b/tests/auto/snippets/data/qtlabscontrols-spinbox-textual.qml
new file mode 100644
index 00000000..cdcbc1bc
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-spinbox-textual.qml
@@ -0,0 +1,28 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+//! [1]
+SpinBox {
+ from: 0
+ to: items.length - 1
+ value: 1 // "Medium"
+
+ property var items: ["Small", "Medium", "Large"]
+
+ validator: RegExpValidator {
+ regExp: new RegExp("(Small|Medium|Large)", "i")
+ }
+
+ textFromValue: function(value) {
+ return items[value];
+ }
+
+ valueFromText: function(text) {
+ for (var i = 0; i < items.length; ++i) {
+ if (items[i].toLowerCase().indexOf(text.toLowerCase()) === 0)
+ return i
+ }
+ return sb.value
+ }
+}
+//! [1]