forked from qt-creator/qt-creator
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:
@@ -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,23 +95,31 @@ StudioControls.ComboBox {
|
||||
|
||||
if (comboBox.manualMapping) {
|
||||
comboBox.valueFromBackendChanged()
|
||||
} else if (!comboBox.useInteger) {
|
||||
var enumString = comboBox.backendValue.enumeration
|
||||
|
||||
if (enumString === "")
|
||||
enumString = comboBox.backendValue.value
|
||||
|
||||
var index = comboBox.find(enumString)
|
||||
|
||||
if (index < 0)
|
||||
index = 0
|
||||
|
||||
if (index !== comboBox.currentIndex)
|
||||
comboBox.currentIndex = index
|
||||
|
||||
} else {
|
||||
if (comboBox.currentIndex !== comboBox.backendValue.value)
|
||||
comboBox.currentIndex = comboBox.backendValue.value
|
||||
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 === "")
|
||||
enumString = comboBox.backendValue.value
|
||||
|
||||
var index = comboBox.find(enumString)
|
||||
|
||||
if (index < 0)
|
||||
index = 0
|
||||
|
||||
if (index !== comboBox.currentIndex)
|
||||
comboBox.currentIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
comboBox.block = false
|
||||
@@ -108,10 +136,16 @@ StudioControls.ComboBox {
|
||||
if (comboBox.manualMapping)
|
||||
return
|
||||
|
||||
if (!comboBox.useInteger) {
|
||||
comboBox.backendValue.setEnumeration(comboBox.scope, comboBox.currentText)
|
||||
} else {
|
||||
comboBox.backendValue.value = comboBox.currentIndex
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user