aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls/fusion
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2019-03-04 11:12:05 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-04-23 11:11:18 +0000
commitf462312365d4955fc82b247b72f84e1c77d8104d (patch)
tree0b240fda0fe60d5110b91aecc6da413f5b086b81 /src/imports/controls/fusion
parent8b61881469901a793e9ac8eec7caefad547258a2 (diff)
Add valueRole API to ComboBox
This allows the user to conveniently manage data for a role associated with the text role. A common example of this is an enum stored in a backend with nicely formatted text displayed to the user. Before this patch, developers would have to write code like this: ComboBox { textRole: "text" onActivated: backend.modifier = model[currentIndex].value Component.onCompleted: currentIndex = findValue(backend.modifier) model: [ { value: Qt.NoModifier, text: qsTr("No modifier") }, { value: Qt.ShiftModifier, text: qsTr("Shift") }, { value: Qt.ControlModifier, text: qsTr("Control") } ] function findValue(value) { for (var i = 0; i < model.length; ++i) { if (model[i].value === value) return i } return -1 } } With this patch, the code becomes much simpler: ComboBox { textRole: "text" valueRole: "value" onActivated: backend.modifier = currentValue Component.onCompleted: currentIndex = indexOfValue(backend.modifier) model: [ { value: Qt.NoModifier, text: qsTr("No modifier") }, { value: Qt.ShiftModifier, text: qsTr("Shift") }, { value: Qt.ControlModifier, text: qsTr("Control") } ] } [ChangeLog][Controls][ComboBox] Added valueRole, currentValue and indexOfValue(). These allow convenient management of data for a role associated with the text role. Change-Id: I0ed19bd0ba9cf6b044a8113ff1a8782d43065449 Fixes: QTBUG-73491 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/controls/fusion')
-rw-r--r--src/imports/controls/fusion/ComboBox.qml14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/imports/controls/fusion/ComboBox.qml b/src/imports/controls/fusion/ComboBox.qml
index 3ecb0cf2..58764809 100644
--- a/src/imports/controls/fusion/ComboBox.qml
+++ b/src/imports/controls/fusion/ComboBox.qml
@@ -34,13 +34,13 @@
**
****************************************************************************/
-import QtQuick 2.12
-import QtQuick.Window 2.12
-import QtQuick.Templates 2.12 as T
-import QtQuick.Controls 2.12
-import QtQuick.Controls.impl 2.12
-import QtQuick.Controls.Fusion 2.12
-import QtQuick.Controls.Fusion.impl 2.12
+import QtQuick 2.14
+import QtQuick.Window 2.14
+import QtQuick.Templates 2.14 as T
+import QtQuick.Controls 2.14
+import QtQuick.Controls.impl 2.14
+import QtQuick.Controls.Fusion 2.14
+import QtQuick.Controls.Fusion.impl 2.14
T.ComboBox {
id: control