Make combobox for device type register types work

This commit is contained in:
2023-02-18 18:14:42 +01:00
parent 4d61e066f4
commit 14af9d0093
6 changed files with 148 additions and 73 deletions

View File

@ -35,6 +35,7 @@ qt_add_qml_module(applightcontrol
DmxSlider.qml DmxSlider.qml
StatusBar.qml StatusBar.qml
RegisterGroupsSettingsPage.qml RegisterGroupsSettingsPage.qml
RegistersSettingsItem.qml
) )
set_target_properties(applightcontrol PROPERTIES set_target_properties(applightcontrol PROPERTIES

View File

@ -14,7 +14,7 @@ ColumnLayout {
Layout.fillHeight: true Layout.fillHeight: true
EditableListView { EditableListView {
id: deviceTypesListView id: listView
Layout.preferredWidth: 300 Layout.preferredWidth: 300
Layout.maximumWidth: 300 Layout.maximumWidth: 300
@ -27,7 +27,7 @@ ColumnLayout {
} }
ColumnLayout { ColumnLayout {
enabled: deviceTypesListView.currentIndex !== -1 enabled: listView.currentIndex !== -1
GridLayout { GridLayout {
Layout.preferredWidth: 600 Layout.preferredWidth: 600
@ -39,74 +39,21 @@ ColumnLayout {
SpinBox { SpinBox {
enabled: false enabled: false
Layout.fillWidth: true Layout.fillWidth: true
value: deviceTypesListView.currentData.id value: listView.currentData.id
onValueModified: deviceTypesListView.currentData.id = value onValueModified: listView.currentData.id = value
} }
Label { text: qsTr("Name:") } Label { text: qsTr("Name:") }
TextField { TextField {
Layout.fillWidth: true Layout.fillWidth: true
text: deviceTypesListView.currentData.name text: listView.currentData.name
onTextEdited: deviceTypesListView.currentData.name = text onTextEdited: listView.currentData.name = text
} }
Label { text: qsTr("Registers:") } Label { text: qsTr("Registers:") }
Pane { RegistersSettingsItem {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Material.elevation: 6 deviceTypeId: listView.currentData.id
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
}
}
}
} }
} }
Item { Item {

View File

@ -56,7 +56,7 @@ ColumnLayout {
textRole: "name" textRole: "name"
valueRole: "id" valueRole: "id"
currentIndex: listView.currentData ? deviceTypeCombobox.indexOfValue(listView.currentData.deviceTypeId) : -1 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:") } Label { text: qsTr("Address:") }
SpinBox { SpinBox {

67
RegistersSettingsItem.qml Normal file
View File

@ -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
}
}
}
}

View File

@ -42,14 +42,16 @@ int DeviceTypeRegistersModel::rowCount(const QModelIndex &parent) const
if (m_deviceTypeId == -1) if (m_deviceTypeId == -1)
return 0; return 0;
auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
if (!deviceType) if (!deviceTypePtr)
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return 0; return 0;
} }
return deviceType->registers.size(); const auto &deviceType = *deviceTypePtr;
return deviceType.registers.size();
} }
QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) const QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) const
@ -72,14 +74,16 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons
return {}; return {};
} }
auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
if (!deviceType) if (!deviceTypePtr)
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; 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__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
@ -91,7 +95,7 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons
return {}; return {};
} }
const auto &deviceTypeRegister = deviceType->registers.at(index.row()); const auto &deviceTypeRegister = deviceType.registers.at(index.row());
switch (role) switch (role)
{ {
@ -126,14 +130,16 @@ QMap<int, QVariant> DeviceTypeRegistersModel::itemData(const QModelIndex &index)
return {}; return {};
} }
auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
if (!deviceType) if (!deviceTypePtr)
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; 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__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
@ -145,7 +151,7 @@ QMap<int, QVariant> DeviceTypeRegistersModel::itemData(const QModelIndex &index)
return {}; return {};
} }
const auto &deviceTypeRegister = deviceType->registers.at(index.row()); const auto &deviceTypeRegister = deviceType.registers.at(index.row());
return { return {
{ Qt::DisplayRole, QMetaEnum::fromType<DeviceTypeRegisterType>().valueToKey(std::to_underlying(deviceTypeRegister.type)) }, { Qt::DisplayRole, QMetaEnum::fromType<DeviceTypeRegisterType>().valueToKey(std::to_underlying(deviceTypeRegister.type)) },
@ -161,6 +167,58 @@ QHash<int, QByteArray> 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<DeviceTypeRegisterType>();
auto &deviceTypeRegister = deviceType.registers.at(index.row());
deviceTypeRegister.type = value.value<DeviceTypeRegisterType>();
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
return true;
return false;
}
namespace { namespace {
void registerDenShit() void registerDenShit()
{ {

View File

@ -25,6 +25,8 @@ public:
QMap<int, QVariant> itemData(const QModelIndex &index) const override; QMap<int, QVariant> itemData(const QModelIndex &index) const override;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
signals: signals:
void controllerChanged(DmxController *controller); void controllerChanged(DmxController *controller);
void deviceTypeIdChanged(int deviceTypeId); void deviceTypeIdChanged(int deviceTypeId);