forked from qt-creator/qt-creator
QmlDesigner: Fix [None] item not visible
* Fix [None] item not visible in ComboBox drop down menu. * valueRole of items shouldn't be removed when textRole is empty. * Regex is modified for searching in ComboBoxes when it has idAndName role. Fixes: QDS-13655 Change-Id: I5c82c418bca1bb5dd9f389741422841a58a44c41 Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||
|
||||
import QtQuick
|
||||
import HelperWidgets 2.0 as HelperWidgets
|
||||
import HelperWidgets as HelperWidgets
|
||||
|
||||
HelperWidgets.ComboBox {
|
||||
id: comboBox
|
||||
@@ -15,7 +15,10 @@ HelperWidgets.ComboBox {
|
||||
valueRole: "id"
|
||||
textRole: (comboBox.typeFilter === "QtQuick3D.Texture") ? "idAndName" : "id"
|
||||
|
||||
validator: RegularExpressionValidator { regularExpression: /(^$|^[a-z_]\w*)/ }
|
||||
validator: RegularExpressionValidator {
|
||||
regularExpression: (comboBox.textRole !== "id") ? /^(\w+\s)*\w+\s\[[a-z_]\w*\]/
|
||||
: /(^$|^[a-z_]\w*)/
|
||||
}
|
||||
|
||||
HelperWidgets.ItemFilterModel {
|
||||
id: itemFilterModel
|
||||
@@ -89,8 +92,8 @@ HelperWidgets.ComboBox {
|
||||
comboBox.backendValue.resetValue()
|
||||
} else {
|
||||
let valueData = (comboBox.valueRole === "")
|
||||
? comboBox.editText
|
||||
: itemFilterModel.modelItemData(comboBox.currentIndex - 1)[comboBox.valueRole]
|
||||
? comboBox.editText
|
||||
: comboBox.model[comboBox.currentIndex][comboBox.valueRole]
|
||||
|
||||
if (comboBox.backendValue.expression !== valueData)
|
||||
comboBox.backendValue.expression = valueData
|
||||
@@ -98,28 +101,29 @@ HelperWidgets.ComboBox {
|
||||
comboBox.dirty = false
|
||||
}
|
||||
|
||||
Repeater {
|
||||
QtObject {
|
||||
id: optionsList
|
||||
|
||||
property var localModel: []
|
||||
property var model
|
||||
|
||||
function updateModel() {
|
||||
optionsList.localModel = []
|
||||
let localModel = []
|
||||
|
||||
if (comboBox.textRole !== "" && comboBox.valueRole !== "") {
|
||||
if (comboBox.textRole !== "") {
|
||||
let defaultItem = {}
|
||||
defaultItem[comboBox.textRole] = comboBox.defaultItem
|
||||
defaultItem[comboBox.valueRole] = ""
|
||||
optionsList.localModel.push(defaultItem)
|
||||
if (comboBox.valueRole !== "" && comboBox.textRole !== comboBox.valueRole)
|
||||
defaultItem[comboBox.valueRole] = ""
|
||||
localModel.push(defaultItem)
|
||||
} else {
|
||||
optionsList.localModel.push(comboBox.defaultItem)
|
||||
localModel.push(comboBox.defaultItem)
|
||||
}
|
||||
|
||||
let rows = itemFilterModel.rowCount()
|
||||
for (let i = 0; i < rows; ++i)
|
||||
optionsList.localModel.push(itemFilterModel.modelItemData(i))
|
||||
localModel.push(itemFilterModel.modelItemData(i))
|
||||
|
||||
optionsList.model = optionsList.localModel // trigger on change handler
|
||||
optionsList.model = localModel // trigger on change handler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user