QmlDesigner: Add string support to ComboBox

This allows setting raw strings.

Change-Id: I372b933db071ea724236c22d9562c464744de7fc
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2020-04-06 15:50:10 +02:00
parent cdb2f9b64b
commit 0a1dcd2498

View File

@@ -35,8 +35,28 @@ StudioControls.ComboBox {
labelColor: edit && !colorLogic.errorState ? StudioTheme.Values.themeTextColor : colorLogic.textColor
property string scope: "Qt"
enum ValueType { String, Integer, Enum }
property int valueType: ComboBox.ValueType.Enum
onValueTypeChanged: {
if (comboBox.valueType === ComboBox.ValueType.Integer)
comboBox.useInteger = true
else
comboBox.useInteger = false
}
// This property shouldn't be used anymore, valueType has come to replace it.
property bool useInteger: false
onUseIntegerChanged: {
if (comboBox.useInteger) {
comboBox.valueType = ComboBox.ValueType.Integer
} else {
if (comboBox.valueType === ComboBox.ValueType.Integer)
comboBox.valueType = ComboBox.ValueType.Enum // set to default
}
}
property bool __isCompleted: false
property bool manualMapping: false
@@ -75,7 +95,18 @@ StudioControls.ComboBox {
if (comboBox.manualMapping) {
comboBox.valueFromBackendChanged()
} else if (!comboBox.useInteger) {
} else {
switch (comboBox.valueType) {
case ComboBox.ValueType.String:
if (comboBox.currentText !== comboBox.backendValue.value)
comboBox.currentText = comboBox.backendValue.value
break
case ComboBox.ValueType.Integer:
if (comboBox.currentIndex !== comboBox.backendValue.value)
comboBox.currentIndex = comboBox.backendValue.value
break
case ComboBox.ValueType.Enum:
default:
var enumString = comboBox.backendValue.enumeration
if (enumString === "")
@@ -88,10 +119,7 @@ StudioControls.ComboBox {
if (index !== comboBox.currentIndex)
comboBox.currentIndex = index
} else {
if (comboBox.currentIndex !== comboBox.backendValue.value)
comboBox.currentIndex = comboBox.backendValue.value
}
}
comboBox.block = false
@@ -108,10 +136,16 @@ StudioControls.ComboBox {
if (comboBox.manualMapping)
return
if (!comboBox.useInteger) {
comboBox.backendValue.setEnumeration(comboBox.scope, comboBox.currentText)
} else {
switch (comboBox.valueType) {
case ComboBox.ValueType.String:
comboBox.backendValue.value = comboBox.currentText
break
case ComboBox.ValueType.Integer:
comboBox.backendValue.value = comboBox.currentIndex
break
case ComboBox.ValueType.Enum:
default:
comboBox.backendValue.setEnumeration(comboBox.scope, comboBox.currentText)
}
}