Implemented adding of new registers to device types

This commit is contained in:
2023-02-18 20:02:29 +01:00
parent a6dc8f29d8
commit 9d3c42c40c
5 changed files with 55 additions and 4 deletions

View File

@ -27,6 +27,7 @@ ApplicationWindow {
ListModel {
id: deviceTypeRegisterTypesModel
ListElement { text: qsTr('Dummy'); value: DeviceTypeRegisterType.Dummy }
ListElement { text: qsTr('Dimmer'); value: DeviceTypeRegisterType.Dimmer }
ListElement { text: qsTr('Red'); value: DeviceTypeRegisterType.Red }
ListElement { text: qsTr('Green'); value: DeviceTypeRegisterType.Green }

View File

@ -31,6 +31,7 @@ Pane {
model: deviceTypeRegistersModel
onAddClicked: (index) => deviceTypeRegistersModel.insertRow(index < 0 ? 0 : index + 1);
onRemoveClicked: (index) => deviceTypeRegistersModel.removeRow(index)
}
}

View File

@ -215,8 +215,60 @@ bool DeviceTypeRegistersModel::setData(const QModelIndex &index, const QVariant
return true;
}
bool DeviceTypeRegistersModel::insertRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return true;
}
if (m_deviceTypeId == -1)
{
qWarning() << "hilfe" << __LINE__;
return true;
}
auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
if (!deviceTypePtr)
{
qWarning() << "hilfe" << __LINE__;
return true;
}
auto &deviceType = *deviceTypePtr;
if (row < 0)
{
qWarning() << "hilfe" << __LINE__;
return true;
}
auto &registers = deviceType.registers;
beginInsertRows({}, row, row+count-1);
auto iter = std::begin(registers) + row;
for (; count > 0; count--)
iter = registers.insert(iter, DeviceTypeRegisterConfig{ .type = DeviceTypeRegisterType::Dummy }) + 1;
endInsertRows();
return true;
}
bool DeviceTypeRegistersModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;

View File

@ -26,6 +26,7 @@ public:
QHash<int, QByteArray> roleNames() const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
bool insertRows(int row, int count, const QModelIndex &parent) override;
bool removeRows(int row, int count, const QModelIndex &parent) override;
signals:

View File

@ -3,8 +3,6 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QDebug>
#include <QDir>
#include "dmxcontroller.h"
int main(int argc, char *argv[])
@ -24,8 +22,6 @@ int main(int argc, char *argv[])
QGuiApplication app{argc, argv};
qDebug() << QDir{":/lightcontrol"}.entryInfoList();
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();