From 5bb111d73653de56ef3a5879f30c504887aa09d5 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 15 Feb 2023 22:00:10 +0100 Subject: [PATCH] More preperations for registers in light types --- DeviceTypesSettingsPage.qml | 17 ++++++++++--- DevicesSettingsPage.qml | 14 +++++------ EditableListView.qml | 4 ++- devicetyperegistersmodel.cpp | 49 ++++++++++++++++++++++++++++++++++-- 4 files changed, 70 insertions(+), 14 deletions(-) diff --git a/DeviceTypesSettingsPage.qml b/DeviceTypesSettingsPage.qml index 7dec727..c4f8183 100644 --- a/DeviceTypesSettingsPage.qml +++ b/DeviceTypesSettingsPage.qml @@ -2,6 +2,8 @@ import QtQuick import QtQuick.Controls.Material import QtQuick.Layouts +import com.büro 1.0 + ColumnLayout { Label { text: qsTr("Device Types Settings") @@ -36,20 +38,27 @@ ColumnLayout { Label { text: qsTr("Id:") } SpinBox { Layout.fillWidth: true - value: listView.currentItem.myData.id - onValueModified: listView.currentItem.myData.id = value + value: listView.currentData.id + onValueModified: listView.currentData.id = value } Label { text: qsTr("Name:") } TextField { Layout.fillWidth: true - text: listView.currentItem.myData.name - onTextEdited: listView.currentItem.myData.name = text + text: listView.currentData.name + onTextEdited: listView.currentData.name = text } Label { text: qsTr("Registers:") } Pane { Layout.fillWidth: true Layout.fillHeight: true EditableListView { + textRole: 'registerTypeName' + + model: DeviceTypeRegistersModel { + controller: __controller + deviceTypeId: listView.currentData.id + } + anchors.fill: parent } } diff --git a/DevicesSettingsPage.qml b/DevicesSettingsPage.qml index 39c2ea9..6c79cbc 100644 --- a/DevicesSettingsPage.qml +++ b/DevicesSettingsPage.qml @@ -38,14 +38,14 @@ ColumnLayout { Label { text: qsTr("Id:") } SpinBox { Layout.fillWidth: true - value: listView.currentItem.myData.id - onValueModified: listView.currentItem.myData.id = value + value: listView.currentData.id + onValueModified: listView.currentData.id = value } Label { text: qsTr("Name:") } TextField { Layout.fillWidth: true - text: listView.currentItem.myData.name - onTextEdited: listView.currentItem.myData.name = text + text: listView.currentData.name + onTextEdited: listView.currentData.name = text } Label { text: qsTr("DeviceType:") } ComboBox { @@ -58,14 +58,14 @@ ColumnLayout { Label { text: qsTr("Address:") } SpinBox { Layout.fillWidth: true - value: listView.currentItem.myData.address - onValueModified: listView.currentItem.myData.address = value + value: listView.currentData.address + onValueModified: listView.currentData.address = value } Label { text: qsTr("Position:") } Vector3DField { id: test Layout.fillWidth: true - onValueModified: listView.currentItem.myData.position = value; + onValueModified: listView.currentData.position = value; // TODO solve without onCurrentDataChanged } } diff --git a/EditableListView.qml b/EditableListView.qml index 54885dd..f85d563 100644 --- a/EditableListView.qml +++ b/EditableListView.qml @@ -3,6 +3,8 @@ import QtQuick.Controls.Material import QtQuick.Layouts ColumnLayout { + property string textRole: "name" + property alias model: listView.model property alias currentIndex: listView.currentIndex property alias currentItem: listView.currentItem @@ -59,7 +61,7 @@ ColumnLayout { anchors.fill: parent //anchors.verticalCenter: parent.verticalCenter id: text - text: model.name + text: model[textRole] padding: 10 fontSizeMode: Text.VerticalFit minimumPixelSize: 10; diff --git a/devicetyperegistersmodel.cpp b/devicetyperegistersmodel.cpp index e5b7c78..a7853c8 100644 --- a/devicetyperegistersmodel.cpp +++ b/devicetyperegistersmodel.cpp @@ -108,12 +108,57 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons QMap DeviceTypeRegistersModel::itemData(const QModelIndex &index) const { - // TODO + if (!index.isValid()) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (!m_controller) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (m_deviceTypeId == -1) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + auto lightType = m_controller->lightProject().lightTypes.findById(m_deviceTypeId); + if (!lightType) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (index.row() < 0 || index.row() >= lightType->registers.size()) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (index.column() != 0) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + const auto &lightTypeRegister = lightType->registers.at(index.row()); + + return { + { Qt::DisplayRole, QMetaEnum::fromType().valueToKey(std::to_underlying(lightTypeRegister.type)) }, + { Qt::EditRole, QVariant::fromValue(lightTypeRegister.type) } + }; } QHash DeviceTypeRegistersModel::roleNames() const { - // TODO + return { + { Qt::DisplayRole, "registerTypeName" }, + { Qt::EditRole, "registerType" }, + }; } namespace {