Add iconName property to model

This commit is contained in:
2023-02-18 23:48:28 +01:00
parent e968ae42cf
commit e627f8ebca
6 changed files with 70 additions and 25 deletions

View File

@ -41,6 +41,7 @@ qt_add_qml_module(applightcontrol
StatusBar.qml
RegisterGroupsSettingsPage.qml
RegistersSettingsItem.qml
IconComboBox.qml
)
set_target_properties(applightcontrol PROPERTIES

View File

@ -77,38 +77,32 @@ ColumnLayout {
enabled: false
Layout.fillWidth: true
value: listView.currentData ? listView.currentData.id : -1
onValueModified: listView.currentData.id = value
onValueModified: if (listView.currentData) listView.currentData.id = value; else console.warn('discarded');
}
Label { text: qsTr("Name:") }
TextField {
Layout.fillWidth: true
text: listView.currentData ? listView.currentData.name : ''
onTextEdited: listView.currentData.name = text
onTextEdited: if (listView.currentData) listView.currentData.name = text; else console.warn('discarded');
}
Label { text: qsTr("Icon:") }
ComboBox {
IconComboBox {
id: iconComboBox
Layout.fillWidth: true
Layout.preferredHeight: 64
id: iconCombobox
textRole: "fileName"
valueRole: "fileUrl"
delegate: ItemDelegate {
height: 64
anchors.left: parent.left
anchors.right: parent.right
contentItem: IconChooserDelegateLayout {
anchors.top: parent.top
anchors.bottom: parent.bottom
text: fileName
iconSource: fileUrl
}
}
contentItem: IconChooserDelegateLayout {
text: iconCombobox.currentText
iconSource: iconCombobox.currentValue
}
textRole: "fileBaseName"
valueRole: "fileBaseName"
iconSourceRole: "fileUrl"
model: iconsModel
currentIndex: listView.currentData ? iconComboBox.indexOfValue(listView.currentData.iconName) : -1
onActivated: {
console.log(currentValue);
if (listView.currentData) listView.currentData.iconName = currentValue; else console.warn('discarded');
}
}
Label { text: qsTr("Registers:") }
RegistersSettingsItem {

32
IconComboBox.qml Normal file
View File

@ -0,0 +1,32 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
ComboBox {
id: comboBox
property string iconSourceRole
delegate: ItemDelegate {
height: 64
anchors.left: parent.left
anchors.right: parent.right
contentItem: IconChooserDelegateLayout {
anchors.top: parent.top
anchors.bottom: parent.bottom
text: model[comboBox.textRole]
iconSource: model[comboBox.iconSourceRole]
}
}
contentItem: IconChooserDelegateLayout {
text: comboBox.currentText
iconSource: {
if (!comboBox.model)
return '';
const url = comboBox.model.get(comboBox.currentIndex, "fileUrl");
if (!url)
return '';
return url;
}
}
}

View File

@ -6,7 +6,7 @@
enum {
IdRole = Qt::UserRole,
IconRole
IconNameRole
};
void DeviceTypesModel::setController(DmxController *controller)
@ -69,6 +69,7 @@ QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
case Qt::EditRole: return deviceType.name;
case IdRole: return deviceType.id;
case IconNameRole: return deviceType.iconName;
}
return {};
@ -106,7 +107,8 @@ QMap<int, QVariant> DeviceTypesModel::itemData(const QModelIndex &index) const
return {
{ Qt::DisplayRole, deviceType.name },
{ IdRole, deviceType.id }
{ IdRole, deviceType.id },
{ IconNameRole, deviceType.iconName }
};
}
@ -114,7 +116,8 @@ QHash<int, QByteArray> DeviceTypesModel::roleNames() const
{
return {
{ Qt::DisplayRole, "name" },
{ IdRole, "id" }
{ IdRole, "id" },
{ IconNameRole, "iconName" }
};
}
@ -167,6 +170,15 @@ bool DeviceTypesModel::setData(const QModelIndex &index, const QVariant &value,
deviceType.id = value.toInt();
emit dataChanged(index, index, { IdRole });
return true;
case IconNameRole:
if (value.userType() != QMetaType::QString)
{
qWarning() << "hilfe" << __LINE__ << value.userType();
return false;
}
deviceType.iconName = value.toString();
emit dataChanged(index, index, { IconNameRole });
return true;
}
return false;

View File

@ -14,11 +14,13 @@ DmxController::DmxController(QObject *parent) :
.deviceTypes {
{
.id=0,
.name="Stairville MH-X50+"
.name="Stairville MH-X50+",
.iconName="movinghead"
},
{
.id=1,
.name="RGBW Strahler Klein",
.iconName="rgbstrahler",
.registers {
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dimmer },
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Red },
@ -32,6 +34,7 @@ DmxController::DmxController(QObject *parent) :
{
.id=2,
.name="RGB Strahler",
.iconName="rgbstrahler",
.registers {
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Red },
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Green },
@ -41,6 +44,7 @@ DmxController::DmxController(QObject *parent) :
{
.id=3,
.name="Nebelmaschine",
.iconName="nebelmaschine",
.registers {
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dimmer }
}
@ -48,6 +52,7 @@ DmxController::DmxController(QObject *parent) :
{
.id=4,
.name="RGBW Strahler Groß",
.iconName="rgbstrahler",
.registers {
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dimmer },
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Red },

View File

@ -37,6 +37,7 @@ struct DeviceTypeConfig
{
int id;
QString name;
QString iconName;
std::vector<DeviceTypeRegisterConfig> registers;
};