forked from qt-creator/qt-creator
QmlDesigner: Clean up code
Change-Id: Iaedeec123170473031708f5a268d896d58678154 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
committed by
Henning Gründl
parent
a45be61691
commit
c55ca15442
@@ -6,7 +6,7 @@ import HelperWidgets 2.0 as HelperWidgets
|
|||||||
import StudioControls 1.0 as StudioControls
|
import StudioControls 1.0 as StudioControls
|
||||||
|
|
||||||
StudioControls.ComboBox {
|
StudioControls.ComboBox {
|
||||||
id: comboBox
|
id: root
|
||||||
|
|
||||||
property alias typeFilter: itemFilterModel.typeFilter
|
property alias typeFilter: itemFilterModel.typeFilter
|
||||||
|
|
||||||
@@ -24,49 +24,49 @@ StudioControls.ComboBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
comboBox.__isCompleted = true
|
root.__isCompleted = true
|
||||||
resetInitialIndex()
|
root.resetInitialIndex()
|
||||||
}
|
}
|
||||||
|
|
||||||
onInitialModelDataChanged: resetInitialIndex()
|
onInitialModelDataChanged: root.resetInitialIndex()
|
||||||
onValueRoleChanged: resetInitialIndex()
|
onValueRoleChanged: root.resetInitialIndex()
|
||||||
onModelChanged: resetInitialIndex()
|
onModelChanged: root.resetInitialIndex()
|
||||||
onTextRoleChanged: resetInitialIndex()
|
onTextRoleChanged: root.resetInitialIndex()
|
||||||
|
|
||||||
function resetInitialIndex() {
|
function resetInitialIndex() {
|
||||||
let currentSelectedDataIndex = -1
|
let currentSelectedDataIndex = -1
|
||||||
|
|
||||||
// Workaround for proper initialization. Use the initial modelData value and search for it
|
// Workaround for proper initialization. Use the initial modelData value and search for it
|
||||||
// in the model. If nothing was found, set the editText to the initial modelData.
|
// in the model. If nothing was found, set the editText to the initial modelData.
|
||||||
if (textRole === valueRole) {
|
if (root.textRole === root.valueRole) {
|
||||||
currentSelectedDataIndex = comboBox.find(comboBox.initialModelData)
|
currentSelectedDataIndex = root.find(root.initialModelData)
|
||||||
} else {
|
} else {
|
||||||
for (let i = 0; i < comboBox.count; ++i) {
|
for (let i = 0; i < root.count; ++i) {
|
||||||
let movingModelIndex = model.index(i)
|
let movingModelIndex = root.model.index(i)
|
||||||
let movingModelValueData = model.data(movingModelIndex, valueRole)
|
let movingModelValueData = root.model.data(movingModelIndex, root.valueRole)
|
||||||
if (movingModelValueData === initialModelData) {
|
if (movingModelValueData === root.initialModelData) {
|
||||||
currentSelectedDataIndex = i
|
currentSelectedDataIndex = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
comboBox.currentIndex = currentSelectedDataIndex
|
root.currentIndex = currentSelectedDataIndex
|
||||||
if (comboBox.currentIndex === -1)
|
if (root.currentIndex === -1)
|
||||||
comboBox.editText = comboBox.initialModelData
|
root.editText = root.initialModelData
|
||||||
}
|
}
|
||||||
|
|
||||||
function currentData(role = valueRole) {
|
function currentData(role = root.valueRole) {
|
||||||
if (comboBox.currentIndex !== -1) {
|
if (root.currentIndex !== -1) {
|
||||||
let currentModelIndex = model.index(currentIndex)
|
let currentModelIndex = root.model.index(root.currentIndex)
|
||||||
return model.data(currentModelIndex, role)
|
return root.model.data(currentModelIndex, role)
|
||||||
}
|
}
|
||||||
return comboBox.editText
|
return root.editText
|
||||||
}
|
}
|
||||||
|
|
||||||
function availableValue() {
|
function availableValue() {
|
||||||
if (comboBox.currentIndex !== -1 && currentValue !== "")
|
if (root.currentIndex !== -1 && root.currentValue !== "")
|
||||||
return currentValue
|
return root.currentValue
|
||||||
|
|
||||||
return comboBox.editText
|
return root.editText
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user