Minor icon improvements

This commit is contained in:
2023-02-23 01:15:59 +01:00
parent 97be6c6b6e
commit 2128040cc1
4 changed files with 56 additions and 20 deletions

View File

@@ -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
}
}