diff --git a/CMakeLists.txt b/CMakeLists.txt index cb54a66..fc12631 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ qt_add_qml_module(applightcontrol DmxSlider.qml StatusBar.qml RegisterGroupsSettingsPage.qml + RegistersSettingsItem.qml ) set_target_properties(applightcontrol PROPERTIES diff --git a/DeviceTypesSettingsPage.qml b/DeviceTypesSettingsPage.qml index 9f2211a..2a43880 100644 --- a/DeviceTypesSettingsPage.qml +++ b/DeviceTypesSettingsPage.qml @@ -14,7 +14,7 @@ ColumnLayout { Layout.fillHeight: true EditableListView { - id: deviceTypesListView + id: listView Layout.preferredWidth: 300 Layout.maximumWidth: 300 @@ -27,7 +27,7 @@ ColumnLayout { } ColumnLayout { - enabled: deviceTypesListView.currentIndex !== -1 + enabled: listView.currentIndex !== -1 GridLayout { Layout.preferredWidth: 600 @@ -39,74 +39,21 @@ ColumnLayout { SpinBox { enabled: false Layout.fillWidth: true - value: deviceTypesListView.currentData.id - onValueModified: deviceTypesListView.currentData.id = value + value: listView.currentData.id + onValueModified: listView.currentData.id = value } Label { text: qsTr("Name:") } TextField { Layout.fillWidth: true - text: deviceTypesListView.currentData.name - onTextEdited: deviceTypesListView.currentData.name = text + text: listView.currentData.name + onTextEdited: listView.currentData.name = text } Label { text: qsTr("Registers:") } - Pane { + RegistersSettingsItem { Layout.fillWidth: true Layout.fillHeight: true - Material.elevation: 6 - - RowLayout { - anchors.fill: parent - - Pane { - Layout.preferredWidth: 300 - Layout.fillHeight: true - - Material.elevation: 6 - - EditableListView { - id: deviceTypesRegistersListView - anchors.fill: parent - - textRole: 'registerTypeName' - - model: DeviceTypeRegistersModel { - controller: __controller - deviceTypeId: deviceTypesListView.currentData.id - } - } - } - - ColumnLayout { - Layout.fillWidth: true - Layout.fillHeight: true - - enabled: deviceTypesRegistersListView.currentIndex >= 0 - - GridLayout { - Layout.fillWidth: true - - columns: 2 - - Label { - text: qsTr('Type:') - } - ComboBox { - id: comboBox - model: deviceTypeRegisterTypesModel - textRole: "text" - valueRole: "value" - - currentIndex: deviceTypesRegistersListView.currentData ? comboBox.indexOfValue(deviceTypesRegistersListView.currentData.registerType) : -1 - } - } - - Item { - Layout.fillWidth: true - Layout.fillHeight: true - } - } - } + deviceTypeId: listView.currentData.id } } Item { diff --git a/DevicesSettingsPage.qml b/DevicesSettingsPage.qml index 5607f6b..363f32c 100644 --- a/DevicesSettingsPage.qml +++ b/DevicesSettingsPage.qml @@ -56,7 +56,7 @@ ColumnLayout { textRole: "name" valueRole: "id" currentIndex: listView.currentData ? deviceTypeCombobox.indexOfValue(listView.currentData.deviceTypeId) : -1 - onCurrentValueChanged: if (listView.currentData) listView.currentData.deviceTypeId = currentValue; else console.warn('discarded'); + onActivated: if (listView.currentData) listView.currentData.deviceTypeId = currentValue; else console.warn('discarded'); } Label { text: qsTr("Address:") } SpinBox { diff --git a/RegistersSettingsItem.qml b/RegistersSettingsItem.qml new file mode 100644 index 0000000..f6b7a72 --- /dev/null +++ b/RegistersSettingsItem.qml @@ -0,0 +1,67 @@ +import QtQuick +import QtQuick.Controls.Material +import QtQuick.Layouts + +import com.büro 1.0 + +Pane { + property alias deviceTypeId: deviceTypeRegistersModel.deviceTypeId + + Material.elevation: 6 + + DeviceTypeRegistersModel { + id: deviceTypeRegistersModel + controller: __controller + } + + RowLayout { + anchors.fill: parent + + Pane { + Layout.preferredWidth: 300 + Layout.fillHeight: true + + Material.elevation: 6 + + EditableListView { + id: listView + anchors.fill: parent + + textRole: 'registerTypeName' + + model: deviceTypeRegistersModel + } + } + + ColumnLayout { + Layout.fillWidth: true + Layout.fillHeight: true + + enabled: listView.currentIndex >= 0 + + GridLayout { + Layout.fillWidth: true + + columns: 2 + + Label { + text: qsTr('Type:') + } + ComboBox { + id: comboBox + model: deviceTypeRegisterTypesModel + textRole: "text" + valueRole: "value" + + currentIndex: listView.currentData ? comboBox.indexOfValue(listView.currentData.registerType) : -1 + onActivated: if (listView.currentData) listView.currentData.registerType = currentValue; else console.warn('discarded'); + } + } + + Item { + Layout.fillWidth: true + Layout.fillHeight: true + } + } + } +} diff --git a/devicetyperegistersmodel.cpp b/devicetyperegistersmodel.cpp index 2b514eb..e589dd5 100644 --- a/devicetyperegistersmodel.cpp +++ b/devicetyperegistersmodel.cpp @@ -42,14 +42,16 @@ int DeviceTypeRegistersModel::rowCount(const QModelIndex &parent) const if (m_deviceTypeId == -1) return 0; - auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); - if (!deviceType) + auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; return 0; } - return deviceType->registers.size(); + const auto &deviceType = *deviceTypePtr; + + return deviceType.registers.size(); } QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) const @@ -72,14 +74,16 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons return {}; } - auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); - if (!deviceType) + auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; return {}; } - if (index.row() < 0 || index.row() >= deviceType->registers.size()) + const auto &deviceType = *deviceTypePtr; + + if (index.row() < 0 || index.row() >= deviceType.registers.size()) { qWarning() << "hilfe" << __LINE__; return {}; @@ -91,7 +95,7 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons return {}; } - const auto &deviceTypeRegister = deviceType->registers.at(index.row()); + const auto &deviceTypeRegister = deviceType.registers.at(index.row()); switch (role) { @@ -126,14 +130,16 @@ QMap DeviceTypeRegistersModel::itemData(const QModelIndex &index) return {}; } - auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); - if (!deviceType) + auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; return {}; } - if (index.row() < 0 || index.row() >= deviceType->registers.size()) + auto &deviceType = *deviceTypePtr; + + if (index.row() < 0 || index.row() >= deviceType.registers.size()) { qWarning() << "hilfe" << __LINE__; return {}; @@ -145,7 +151,7 @@ QMap DeviceTypeRegistersModel::itemData(const QModelIndex &index) return {}; } - const auto &deviceTypeRegister = deviceType->registers.at(index.row()); + const auto &deviceTypeRegister = deviceType.registers.at(index.row()); return { { Qt::DisplayRole, QMetaEnum::fromType().valueToKey(std::to_underlying(deviceTypeRegister.type)) }, @@ -161,6 +167,58 @@ QHash DeviceTypeRegistersModel::roleNames() const }; } +bool DeviceTypeRegistersModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!index.isValid()) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (!m_controller) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (m_deviceTypeId == -1) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + if (!deviceTypePtr) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + auto &deviceType = *deviceTypePtr; + + if (index.row() < 0 || index.row() >= deviceType.registers.size()) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (index.column() != 0) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + qDebug() << value.value(); + + auto &deviceTypeRegister = deviceType.registers.at(index.row()); + + deviceTypeRegister.type = value.value(); + emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole }); + return true; + + return false; +} + namespace { void registerDenShit() { diff --git a/devicetyperegistersmodel.h b/devicetyperegistersmodel.h index 3a0c937..ab6c403 100644 --- a/devicetyperegistersmodel.h +++ b/devicetyperegistersmodel.h @@ -25,6 +25,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); void deviceTypeIdChanged(int deviceTypeId);