From e30c5293ed8368402b1a3545137ea8aaa1ce317d Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 15 Feb 2023 20:17:58 +0100 Subject: [PATCH] Add position field to device settings --- CMakeLists.txt | 1 + DevicesSettingsPage.qml | 10 ++++++++- EditableListView.qml | 1 + Vector3DField.qml | 50 +++++++++++++++++++++++++++++++++++++++++ devicesmodel.cpp | 2 +- dmxcontroller.cpp | 8 +++---- 6 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 Vector3DField.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index ac39b17..19f005a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ qt_add_qml_module(applightcontrol EditableListView.qml DeviceTypesSettingsPage.qml DevicesSettingsPage.qml + Vector3DField.qml ) set_target_properties(applightcontrol PROPERTIES diff --git a/DevicesSettingsPage.qml b/DevicesSettingsPage.qml index f61d519..39c2ea9 100644 --- a/DevicesSettingsPage.qml +++ b/DevicesSettingsPage.qml @@ -22,6 +22,8 @@ ColumnLayout { onAddClicked: (index) => devicesModel.insertRow(index < 0 ? 0 : index + 1); onRemoveClicked: (index) => devicesModel.removeRow(index) + + onCurrentDataChanged: test.value = currentData.position } ColumnLayout { @@ -51,7 +53,7 @@ ColumnLayout { model: deviceTypesModel textRole: "name" valueRole: "id" - // TODO + // TODO make binding for selection } Label { text: qsTr("Address:") } SpinBox { @@ -60,6 +62,12 @@ ColumnLayout { onValueModified: listView.currentItem.myData.address = value } Label { text: qsTr("Position:") } + Vector3DField { + id: test + Layout.fillWidth: true + onValueModified: listView.currentItem.myData.position = value; + // TODO solve without onCurrentDataChanged + } } Item { Layout.fillHeight: true diff --git a/EditableListView.qml b/EditableListView.qml index 9ef7406..54885dd 100644 --- a/EditableListView.qml +++ b/EditableListView.qml @@ -6,6 +6,7 @@ ColumnLayout { property alias model: listView.model property alias currentIndex: listView.currentIndex property alias currentItem: listView.currentItem + property variant currentData: listView.currentItem ? listView.currentItem.myData : null signal addClicked(index: int) signal removeClicked(index: int) diff --git a/Vector3DField.qml b/Vector3DField.qml new file mode 100644 index 0000000..d9bce80 --- /dev/null +++ b/Vector3DField.qml @@ -0,0 +1,50 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls.Material + +RowLayout { + property vector3d value + onValueChanged: { + xBox.value = value.x + yBox.value = value.y + zBox.value = value.z + } + + signal valueModified + + function updateValue() { + const newValue = Qt.vector3d(xBox.value, yBox.value, zBox.value); + console.log(newValue); + if (newValue === value) + return; + value = newValue; + valueModified(); + } + + Label { + text: qsTr('x:') + } + + SpinBox { + id: xBox + onValueModified: updateValue() + } + + Label { + text: qsTr('y:') + } + + SpinBox { + id: yBox + onValueModified: updateValue() + } + + Label { + text: qsTr('z:') + } + + SpinBox { + id: zBox + onValueModified: updateValue() + } +} diff --git a/devicesmodel.cpp b/devicesmodel.cpp index 25a3eb3..b69e39f 100644 --- a/devicesmodel.cpp +++ b/devicesmodel.cpp @@ -229,7 +229,7 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int return false; } light.position = value.value(); - emit dataChanged(index, index, { AddressRole }); + emit dataChanged(index, index, { PositionRole }); return true; } diff --git a/dmxcontroller.cpp b/dmxcontroller.cpp index 1d7b711..bb9dedb 100644 --- a/dmxcontroller.cpp +++ b/dmxcontroller.cpp @@ -18,9 +18,9 @@ DmxController::DmxController(QObject *parent) : { .id=3, .name="Nebelmaschine" } }, .lights { - { .id=0, .name="Lampe 1", .lightTypeId=1, .address=32 }, - { .id=1, .name="Lampe 2", .lightTypeId=1, .address=0 }, - { .id=2, .name="Lampe 3", .lightTypeId=1, .address=7 }, + { .id=0, .name="Lampe 1", .lightTypeId=1, .address=32, .position{1,0,0} }, + { .id=1, .name="Lampe 2", .lightTypeId=1, .address=0, .position{2,0,0} }, + { .id=2, .name="Lampe 3", .lightTypeId=1, .address=7, .position{3,0,0} }, { .id=3, .name="Lampe 4", .lightTypeId=1, .address=14 }, { .id=4, .name="Moving Head 1", .lightTypeId=0, .address=40 }, { .id=5, .name="Moving Head 2", .lightTypeId=0, .address=43 }, @@ -102,7 +102,7 @@ void DmxController::sendDmxBuffer() if (m_lastInfo.msecsTo(now) >= 1000) { - qInfo("%i per second รค", m_counter); + qInfo("%i per second", m_counter); m_counter = 0; m_lastInfo = now; }