Minor icon improvements
This commit is contained in:
@ -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
|
||||
|
@ -14,8 +14,6 @@ ColumnLayout {
|
||||
signal addClicked(index: int)
|
||||
signal removeClicked(index: int)
|
||||
|
||||
id: editableListViewLayout
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ public:
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QMap<int, QVariant> itemData(const QModelIndex &index) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
Q_INVOKABLE QMap<int, QVariant> itemData(const QModelIndex &index) const override;
|
||||
Q_INVOKABLE QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
||||
|
Reference in New Issue
Block a user