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 StatusBar.qml
RegisterGroupsSettingsPage.qml RegisterGroupsSettingsPage.qml
RegistersSettingsItem.qml RegistersSettingsItem.qml
IconComboBox.qml
) )
set_target_properties(applightcontrol PROPERTIES set_target_properties(applightcontrol PROPERTIES

View File

@@ -77,38 +77,32 @@ ColumnLayout {
enabled: false enabled: false
Layout.fillWidth: true Layout.fillWidth: true
value: listView.currentData ? listView.currentData.id : -1 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:") } Label { text: qsTr("Name:") }
TextField { TextField {
Layout.fillWidth: true Layout.fillWidth: true
text: listView.currentData ? listView.currentData.name : '' 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:") } Label { text: qsTr("Icon:") }
ComboBox { IconComboBox {
id: iconComboBox
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: 64 Layout.preferredHeight: 64
id: iconCombobox
textRole: "fileName" textRole: "fileBaseName"
valueRole: "fileUrl" valueRole: "fileBaseName"
delegate: ItemDelegate { iconSourceRole: "fileUrl"
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
}
model: iconsModel 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:") } Label { text: qsTr("Registers:") }
RegistersSettingsItem { 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 { enum {
IdRole = Qt::UserRole, IdRole = Qt::UserRole,
IconRole IconNameRole
}; };
void DeviceTypesModel::setController(DmxController *controller) void DeviceTypesModel::setController(DmxController *controller)
@@ -69,6 +69,7 @@ QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole: case Qt::DisplayRole:
case Qt::EditRole: return deviceType.name; case Qt::EditRole: return deviceType.name;
case IdRole: return deviceType.id; case IdRole: return deviceType.id;
case IconNameRole: return deviceType.iconName;
} }
return {}; return {};
@@ -106,7 +107,8 @@ QMap<int, QVariant> DeviceTypesModel::itemData(const QModelIndex &index) const
return { return {
{ Qt::DisplayRole, deviceType.name }, { Qt::DisplayRole, deviceType.name },
{ IdRole, deviceType.id } { IdRole, deviceType.id },
{ IconNameRole, deviceType.iconName }
}; };
} }
@@ -114,7 +116,8 @@ QHash<int, QByteArray> DeviceTypesModel::roleNames() const
{ {
return { return {
{ Qt::DisplayRole, "name" }, { 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(); deviceType.id = value.toInt();
emit dataChanged(index, index, { IdRole }); emit dataChanged(index, index, { IdRole });
return true; 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; return false;

View File

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

View File

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