From 2128040cc1ef29334753d2b93911ec20c31539e0 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 23 Feb 2023 01:15:59 +0100 Subject: [PATCH] Minor icon improvements --- DevicesSettingsPage.qml | 15 ++++++++--- EditableListView.qml | 2 -- IconComboBox.qml | 55 +++++++++++++++++++++++++++++++---------- devicetypesmodel.h | 4 +-- 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/DevicesSettingsPage.qml b/DevicesSettingsPage.qml index 87004db..810929f 100644 --- a/DevicesSettingsPage.qml +++ b/DevicesSettingsPage.qml @@ -17,6 +17,8 @@ ColumnLayout { EditableListView { id: listView + iconSourceRole: "iconUrl" + Layout.preferredWidth: 300 Layout.maximumWidth: 300 Layout.fillHeight: true @@ -65,9 +67,13 @@ ColumnLayout { ColumnLayout { enabled: listView.currentIndex !== -1 + Layout.preferredWidth: 400 + Layout.maximumWidth: 400 + GridLayout { - Layout.preferredWidth: 300 - Layout.maximumWidth: 300 + Layout.fillWidth: true +// Layout.preferredWidth: 300 +// Layout.maximumWidth: 300 columns: 2 @@ -85,7 +91,7 @@ ColumnLayout { onTextEdited: listView.currentData.name = text } Label { text: qsTr("DeviceType:") } - ComboBox { + IconComboBox { id: deviceTypeCombobox Layout.fillWidth: true model: DeviceTypesModel { @@ -93,6 +99,7 @@ ColumnLayout { } textRole: "name" valueRole: "id" + iconSourceRole: "iconUrl" currentIndex: listView.currentData ? deviceTypeCombobox.indexOfValue(listView.currentData.deviceTypeId) : -1 onActivated: if (listView.currentData) listView.currentData.deviceTypeId = currentValue; else console.warn('discarded'); } @@ -121,6 +128,8 @@ ColumnLayout { Layout.fillWidth: true Layout.fillHeight: true +// Layout.preferredWidth: 300 + Layout.minimumWidth: 300 model: model selectedItem: listView.currentIndex diff --git a/EditableListView.qml b/EditableListView.qml index 4079615..476f25c 100644 --- a/EditableListView.qml +++ b/EditableListView.qml @@ -14,8 +14,6 @@ ColumnLayout { signal addClicked(index: int) signal removeClicked(index: int) - id: editableListViewLayout - RowLayout { Layout.fillWidth: true diff --git a/IconComboBox.qml b/IconComboBox.qml index 2aac585..4e8d5bb 100644 --- a/IconComboBox.qml +++ b/IconComboBox.qml @@ -3,22 +3,13 @@ import QtQuick.Controls import QtQuick.Controls.Material import Qt.labs.folderlistmodel 2.4 +import scheincommander 1.0 + 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 @@ -27,12 +18,50 @@ ComboBox { anchors.top: parent.top anchors.bottom: parent.bottom text: model[comboBox.textRole] - iconSource: comboBox.getIconUrl(index) + iconSource: model[comboBox.iconSourceRole] } } contentItem: IconChooserDelegateLayout { text: comboBox.displayText - iconSource: comboBox.currentIndex >= 0 ? comboBox.getIconUrl(comboBox.currentIndex) : "" + iconSource: { +// console.log("QAbstractListModel", model instanceof QAbstractListModel); +// console.log("QAbstractItemModel", model instanceof QAbstractItemModel); +// console.log("FolderListModel", model instanceof FolderListModel); +// console.log("DeviceTypesModel", model instanceof DeviceTypesModel); +// console.log("QtObject", model instanceof QtObject); + + if (comboBox.currentIndex < 0) + return ''; + if (!comboBox.model) + return ''; + if (!comboBox.iconSourceRole) + return ''; + + if (model instanceof FolderListModel) + return model.get(comboBox.currentIndex, iconSourceRole); + else if ('get' in model) + { + const data = model.get(comboBox.currentIndex); + console.log(data); + return data[iconSourceRole]; + } + else if ('roleNames' in model || 'itemData' in model) + { + if (!('roleNames' in model && 'itemData' in model)) + throw 'roleNames or itemData not defined!'; + + const roleNames = model.roleNames(); + console.log('roleNames', roleNames); + + const index = model.index(comboBox.currentIndex, 0); + const itemData = model.itemData(index); + console.log('itemData', itemData); + + throw 'getting data from model using roleNames and itemData is not yet implemented.'; + } + else + throw 'unknown model type' + typeof model; + } isInsideMaterialComboBox: true } } diff --git a/devicetypesmodel.h b/devicetypesmodel.h index aacdc02..b0fd45c 100644 --- a/devicetypesmodel.h +++ b/devicetypesmodel.h @@ -18,8 +18,8 @@ public: int rowCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; - QMap itemData(const QModelIndex &index) const override; - QHash roleNames() const override; + Q_INVOKABLE QMap itemData(const QModelIndex &index) const override; + Q_INVOKABLE QHash roleNames() const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; bool insertRows(int row, int count, const QModelIndex &parent) override;