diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-10-24 21:04:43 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-10-25 13:03:27 +0000 |
commit | 459842c6d880c1a754829b258d4ca4d1a136cdb9 (patch) | |
tree | e4d218ea1df436a5a7791efbb28d9c8afd1a171e /tests/auto/controls/data/tst_spinbox.qml | |
parent | 90659c9bed2464d87602c3d25eed2db2c4004b9a (diff) |
Add QQuickSpinBox::displayText
Allows styles to create a simple binding to display the textual value
instead of calling the textFromValue() JS-function. Furthermore, this
allows us to do the text<->value conversion in C++ using QLocale by
default, unless custom textFromValue and/or valueFromText JS-functions
are provided.
Before:
running: qmlbench/benchmarks/auto/creation/quick.controls2/delegates_spinbox.qml
100 frames
100 frames
99 frames
Average: 99.6667 frames; using samples; MedianAll=100; StdDev=0.57735, CoV=0.00579281
After:
running: qmlbench/benchmarks/auto/creation/quick.controls2/delegates_spinbox.qml
152 frames
150 frames
151 frames
Average: 151 frames; using samples; MedianAll=151; StdDev=1, CoV=0.00662252
Change-Id: I66a5ebaf685d2c30613b58099724e6e7bbe00504
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/controls/data/tst_spinbox.qml')
-rw-r--r-- | tests/auto/controls/data/tst_spinbox.qml | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index 003468a1..a1d1b7ba 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -565,4 +565,48 @@ TestCase { verify(control) compare(control.value, 1000) } + + Component { + id: sizeBox + SpinBox { + from: 0 + to: items.length - 1 + + 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 + } + } + } + + function test_textFromValue_data() { + return [ + { tag: "default", component: spinBox, values: [0, 10, 99], displayTexts: ["0", "10", "99"] }, + { tag: "custom", component: sizeBox, values: [0, 1, 2], displayTexts: ["Small", "Medium", "Large"] } + ] + } + + function test_textFromValue(data) { + var control = createTemporaryObject(data.component, testCase) + verify(control) + + for (var i = 0; i < data.values.length; ++i) { + control.value = data.values[i] + compare(control.value, data.values[i]) + compare(control.displayText, data.displayTexts[i]) + } + } } |