More preperations for registers in light types

This commit is contained in:
2023-02-15 22:00:10 +01:00
parent 975b2b7a52
commit 5bb111d736
4 changed files with 70 additions and 14 deletions

View File

@ -2,6 +2,8 @@ import QtQuick
import QtQuick.Controls.Material import QtQuick.Controls.Material
import QtQuick.Layouts import QtQuick.Layouts
import com.büro 1.0
ColumnLayout { ColumnLayout {
Label { Label {
text: qsTr("Device Types Settings") text: qsTr("Device Types Settings")
@ -36,20 +38,27 @@ ColumnLayout {
Label { text: qsTr("Id:") } Label { text: qsTr("Id:") }
SpinBox { SpinBox {
Layout.fillWidth: true Layout.fillWidth: true
value: listView.currentItem.myData.id value: listView.currentData.id
onValueModified: listView.currentItem.myData.id = value onValueModified: listView.currentData.id = value
} }
Label { text: qsTr("Name:") } Label { text: qsTr("Name:") }
TextField { TextField {
Layout.fillWidth: true Layout.fillWidth: true
text: listView.currentItem.myData.name text: listView.currentData.name
onTextEdited: listView.currentItem.myData.name = text onTextEdited: listView.currentData.name = text
} }
Label { text: qsTr("Registers:") } Label { text: qsTr("Registers:") }
Pane { Pane {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
EditableListView { EditableListView {
textRole: 'registerTypeName'
model: DeviceTypeRegistersModel {
controller: __controller
deviceTypeId: listView.currentData.id
}
anchors.fill: parent anchors.fill: parent
} }
} }

View File

@ -38,14 +38,14 @@ ColumnLayout {
Label { text: qsTr("Id:") } Label { text: qsTr("Id:") }
SpinBox { SpinBox {
Layout.fillWidth: true Layout.fillWidth: true
value: listView.currentItem.myData.id value: listView.currentData.id
onValueModified: listView.currentItem.myData.id = value onValueModified: listView.currentData.id = value
} }
Label { text: qsTr("Name:") } Label { text: qsTr("Name:") }
TextField { TextField {
Layout.fillWidth: true Layout.fillWidth: true
text: listView.currentItem.myData.name text: listView.currentData.name
onTextEdited: listView.currentItem.myData.name = text onTextEdited: listView.currentData.name = text
} }
Label { text: qsTr("DeviceType:") } Label { text: qsTr("DeviceType:") }
ComboBox { ComboBox {
@ -58,14 +58,14 @@ ColumnLayout {
Label { text: qsTr("Address:") } Label { text: qsTr("Address:") }
SpinBox { SpinBox {
Layout.fillWidth: true Layout.fillWidth: true
value: listView.currentItem.myData.address value: listView.currentData.address
onValueModified: listView.currentItem.myData.address = value onValueModified: listView.currentData.address = value
} }
Label { text: qsTr("Position:") } Label { text: qsTr("Position:") }
Vector3DField { Vector3DField {
id: test id: test
Layout.fillWidth: true Layout.fillWidth: true
onValueModified: listView.currentItem.myData.position = value; onValueModified: listView.currentData.position = value;
// TODO solve without onCurrentDataChanged // TODO solve without onCurrentDataChanged
} }
} }

View File

@ -3,6 +3,8 @@ import QtQuick.Controls.Material
import QtQuick.Layouts import QtQuick.Layouts
ColumnLayout { ColumnLayout {
property string textRole: "name"
property alias model: listView.model property alias model: listView.model
property alias currentIndex: listView.currentIndex property alias currentIndex: listView.currentIndex
property alias currentItem: listView.currentItem property alias currentItem: listView.currentItem
@ -59,7 +61,7 @@ ColumnLayout {
anchors.fill: parent anchors.fill: parent
//anchors.verticalCenter: parent.verticalCenter //anchors.verticalCenter: parent.verticalCenter
id: text id: text
text: model.name text: model[textRole]
padding: 10 padding: 10
fontSizeMode: Text.VerticalFit fontSizeMode: Text.VerticalFit
minimumPixelSize: 10; minimumPixelSize: 10;

View File

@ -108,12 +108,57 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons
QMap<int, QVariant> DeviceTypeRegistersModel::itemData(const QModelIndex &index) const QMap<int, QVariant> 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<LightTypeRegisterType>().valueToKey(std::to_underlying(lightTypeRegister.type)) },
{ Qt::EditRole, QVariant::fromValue(lightTypeRegister.type) }
};
} }
QHash<int, QByteArray> DeviceTypeRegistersModel::roleNames() const QHash<int, QByteArray> DeviceTypeRegistersModel::roleNames() const
{ {
// TODO return {
{ Qt::DisplayRole, "registerTypeName" },
{ Qt::EditRole, "registerType" },
};
} }
namespace { namespace {