From 01129e7a306c68713cea198ddb7004f8c63fada4 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sun, 19 Feb 2023 20:23:18 +0100 Subject: [PATCH] Implemented setter for register groups model --- RegisterGroupsSettingsPage.qml | 8 +++++ devicesmodel.cpp | 5 ++-- devicetyperegistersmodel.cpp | 1 - devicetypesmodel.cpp | 5 ++-- registergroupsmodel.cpp | 55 ++++++++++++++++++++++++++++++++++ registergroupsmodel.h | 2 ++ 6 files changed, 71 insertions(+), 5 deletions(-) diff --git a/RegisterGroupsSettingsPage.qml b/RegisterGroupsSettingsPage.qml index 9da226a..e1a1c08 100644 --- a/RegisterGroupsSettingsPage.qml +++ b/RegisterGroupsSettingsPage.qml @@ -40,6 +40,14 @@ ColumnLayout { SpinBox { enabled: false Layout.fillWidth: true + value: listView.currentData ? listView.currentData.id : -1 + 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: if (listView.currentData) listView.currentData.name = text; else console.warn('discarded'); } } Item { diff --git a/devicesmodel.cpp b/devicesmodel.cpp index e57cecd..ab117b6 100644 --- a/devicesmodel.cpp +++ b/devicesmodel.cpp @@ -205,9 +205,10 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int device.position = value.value(); emit dataChanged(index, index, { PositionRole }); return true; + default: + qWarning() << "hilfe" << __LINE__; + return false; } - - return false; } bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent) diff --git a/devicetyperegistersmodel.cpp b/devicetyperegistersmodel.cpp index aaec0f1..0981ba7 100644 --- a/devicetyperegistersmodel.cpp +++ b/devicetyperegistersmodel.cpp @@ -250,7 +250,6 @@ bool DeviceTypeRegistersModel::setData(const QModelIndex &index, const QVariant this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterTypeChanged); return true; - default: qWarning() << "hilfe" << __LINE__; return false; diff --git a/devicetypesmodel.cpp b/devicetypesmodel.cpp index f430c6f..4ed33f0 100644 --- a/devicetypesmodel.cpp +++ b/devicetypesmodel.cpp @@ -209,9 +209,10 @@ bool DeviceTypesModel::setData(const QModelIndex &index, const QVariant &value, deviceType.iconName = value.toString(); emit dataChanged(index, index, { IconNameRole }); return true; + default: + qWarning() << "hilfe" << __LINE__; + return false; } - - return false; } bool DeviceTypesModel::insertRows(int row, int count, const QModelIndex &parent) diff --git a/registergroupsmodel.cpp b/registergroupsmodel.cpp index 18d6440..a919c74 100644 --- a/registergroupsmodel.cpp +++ b/registergroupsmodel.cpp @@ -118,6 +118,61 @@ QHash RegisterGroupsModel::roleNames() const }; } +bool RegisterGroupsModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!index.isValid()) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + if (!m_controller) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + auto ®isterGroups = m_controller->lightProject().registerGroups; + if (index.row() < 0 || index.row() >= registerGroups.size()) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + if (index.column() != 0) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + auto ®isterGroup = registerGroups.at(index.row()); + switch (role) + { + case Qt::DisplayRole: + case Qt::EditRole: + if (value.userType() != QMetaType::QString) + { + qWarning() << "hilfe" << __LINE__ << value.userType(); + return false; + } + registerGroup.name = value.toString(); + emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole }); + return true; + case IdRole: + if (value.userType() != QMetaType::Int) + { + qWarning() << "hilfe" << __LINE__ << value.userType(); + return false; + } + registerGroup.id = value.toInt(); + emit dataChanged(index, index, { IdRole }); + return true; + default: + qWarning() << "hilfe" << __LINE__; + return false; + } +} + namespace { void registrierDenShit() { diff --git a/registergroupsmodel.h b/registergroupsmodel.h index 3d806f8..eca9f2c 100644 --- a/registergroupsmodel.h +++ b/registergroupsmodel.h @@ -21,6 +21,8 @@ public: QMap itemData(const QModelIndex &index) const override; QHash roleNames() const override; + bool setData(const QModelIndex &index, const QVariant &value, int role) override; + signals: void controllerChanged(DmxController *controller);