2023-02-15 21:54:26 +01:00
|
|
|
#include "devicetyperegistersmodel.h"
|
|
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QQmlEngine>
|
|
|
|
|
|
|
|
|
|
void DeviceTypeRegistersModel::setController(DmxController *controller)
|
|
|
|
|
{
|
|
|
|
|
if (m_controller == controller)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
beginResetModel();
|
|
|
|
|
m_controller = controller;
|
|
|
|
|
endResetModel();
|
|
|
|
|
emit controllerChanged(m_controller);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DeviceTypeRegistersModel::setDeviceTypeId(int deviceTypeId)
|
|
|
|
|
{
|
|
|
|
|
if (m_deviceTypeId == deviceTypeId)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
beginResetModel();
|
|
|
|
|
m_deviceTypeId = deviceTypeId;
|
|
|
|
|
endResetModel();
|
|
|
|
|
emit deviceTypeIdChanged(m_deviceTypeId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int DeviceTypeRegistersModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (parent.isValid())
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_controller)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (m_deviceTypeId == -1)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
|
|
|
|
|
if (!deviceTypePtr)
|
2023-02-15 21:54:26 +01:00
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
const auto &deviceType = *deviceTypePtr;
|
|
|
|
|
|
|
|
|
|
return deviceType.registers.size();
|
2023-02-15 21:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_controller)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_deviceTypeId == -1)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
|
|
|
|
|
if (!deviceTypePtr)
|
2023-02-15 21:54:26 +01:00
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
const auto &deviceType = *deviceTypePtr;
|
|
|
|
|
|
|
|
|
|
if (index.row() < 0 || index.row() >= deviceType.registers.size())
|
2023-02-15 21:54:26 +01:00
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index.column() != 0)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
const auto &deviceTypeRegister = deviceType.registers.at(index.row());
|
2023-02-15 21:54:26 +01:00
|
|
|
|
|
|
|
|
switch (role)
|
|
|
|
|
{
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
{
|
2023-02-15 22:45:18 +01:00
|
|
|
return QMetaEnum::fromType<DeviceTypeRegisterType>().valueToKey(std::to_underlying(deviceTypeRegister.type));
|
2023-02-15 21:54:26 +01:00
|
|
|
}
|
|
|
|
|
case Qt::EditRole:
|
2023-02-15 22:45:18 +01:00
|
|
|
return QVariant::fromValue(deviceTypeRegister.type);
|
2023-02-15 21:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<int, QVariant> DeviceTypeRegistersModel::itemData(const QModelIndex &index) const
|
|
|
|
|
{
|
2023-02-15 22:00:10 +01:00
|
|
|
if (!index.isValid())
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_controller)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_deviceTypeId == -1)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
|
|
|
|
|
if (!deviceTypePtr)
|
2023-02-15 22:00:10 +01:00
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
auto &deviceType = *deviceTypePtr;
|
|
|
|
|
|
|
|
|
|
if (index.row() < 0 || index.row() >= deviceType.registers.size())
|
2023-02-15 22:00:10 +01:00
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index.column() != 0)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
const auto &deviceTypeRegister = deviceType.registers.at(index.row());
|
2023-02-15 22:00:10 +01:00
|
|
|
|
|
|
|
|
return {
|
2023-02-15 22:45:18 +01:00
|
|
|
{ Qt::DisplayRole, QMetaEnum::fromType<DeviceTypeRegisterType>().valueToKey(std::to_underlying(deviceTypeRegister.type)) },
|
|
|
|
|
{ Qt::EditRole, QVariant::fromValue(deviceTypeRegister.type) }
|
2023-02-15 22:00:10 +01:00
|
|
|
};
|
2023-02-15 21:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QHash<int, QByteArray> DeviceTypeRegistersModel::roleNames() const
|
|
|
|
|
{
|
2023-02-15 22:00:10 +01:00
|
|
|
return {
|
|
|
|
|
{ Qt::DisplayRole, "registerTypeName" },
|
|
|
|
|
{ Qt::EditRole, "registerType" },
|
|
|
|
|
};
|
2023-02-15 21:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-18 18:14:42 +01:00
|
|
|
bool DeviceTypeRegistersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
2023-02-18 18:58:42 +01:00
|
|
|
return true;
|
2023-02-18 18:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_controller)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
2023-02-18 18:58:42 +01:00
|
|
|
return true;
|
2023-02-18 18:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_deviceTypeId == -1)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
2023-02-18 18:58:42 +01:00
|
|
|
return true;
|
2023-02-18 18:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
|
|
|
|
|
if (!deviceTypePtr)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
2023-02-18 18:58:42 +01:00
|
|
|
return true;
|
2023-02-18 18:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto &deviceType = *deviceTypePtr;
|
|
|
|
|
|
|
|
|
|
if (index.row() < 0 || index.row() >= deviceType.registers.size())
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
2023-02-18 18:58:42 +01:00
|
|
|
return true;
|
2023-02-18 18:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index.column() != 0)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "hilfe" << __LINE__;
|
2023-02-18 18:58:42 +01:00
|
|
|
return true;
|
2023-02-18 18:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto &deviceTypeRegister = deviceType.registers.at(index.row());
|
|
|
|
|
|
|
|
|
|
deviceTypeRegister.type = value.value<DeviceTypeRegisterType>();
|
|
|
|
|
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
|
|
|
|
|
return true;
|
2023-02-18 18:58:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceTypeRegistersModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
|
{
|
2023-02-18 18:14:42 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 21:54:26 +01:00
|
|
|
namespace {
|
|
|
|
|
void registerDenShit()
|
|
|
|
|
{
|
|
|
|
|
qmlRegisterType<DeviceTypeRegistersModel>("com.büro", 1, 0, "DeviceTypeRegistersModel");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Q_COREAPP_STARTUP_FUNCTION(registerDenShit)
|
|
|
|
|
|