diff --git a/DeviceTypesSettingsPage.qml b/DeviceTypesSettingsPage.qml index 879fef4..16d8783 100644 --- a/DeviceTypesSettingsPage.qml +++ b/DeviceTypesSettingsPage.qml @@ -99,6 +99,12 @@ ColumnLayout { model: iconsModel currentIndex: listView.currentData ? iconComboBox.indexOfValue(listView.currentData.iconName) : -1 + Component.onCompleted: { + iconsModel.onRowCountChanged.connect(function(){ + currentIndex = Qt.binding(function() { return listView.currentData ? iconComboBox.indexOfValue(listView.currentData.iconName) : -1}); + }); + } + onActivated: { console.log(currentValue); if (listView.currentData) listView.currentData.iconName = currentValue; else console.warn('discarded'); diff --git a/IconComboBox.qml b/IconComboBox.qml index ff3a647..73f0ecf 100644 --- a/IconComboBox.qml +++ b/IconComboBox.qml @@ -1,12 +1,24 @@ import QtQuick import QtQuick.Controls import QtQuick.Controls.Material +import Qt.labs.folderlistmodel 2.4 ComboBox { id: comboBox property string iconSourceRole + property bool hasTwoArgumentGetter: model instanceof FolderListModel + + function getIconUrl(index) { + if (!comboBox.model) + return ''; + if (hasTwoArgumentGetter) + return model.get(index, iconSourceRole); + else + return model.get(index)[iconSourceRole]; + } + delegate: ItemDelegate { height: 64 anchors.left: parent.left @@ -15,18 +27,11 @@ ComboBox { anchors.top: parent.top anchors.bottom: parent.bottom text: model[comboBox.textRole] - iconSource: model[comboBox.iconSourceRole] + iconSource: comboBox.getIconUrl(index) } } contentItem: IconChooserDelegateLayout { - text: comboBox.currentText - iconSource: { - if (!comboBox.model) - return ''; - const url = comboBox.model.get(comboBox.currentIndex, "fileUrl"); - if (!url) - return ''; - return url; - } + text: comboBox.displayText + iconSource: comboBox.currentIndex >= 0 ? comboBox.getIconUrl(comboBox.currentIndex) : "" } }