Make device type combobox work

This commit is contained in:
2023-02-15 22:45:18 +01:00
parent 895ac57046
commit 09d88ea75e
6 changed files with 122 additions and 121 deletions

View File

@ -50,11 +50,13 @@ ColumnLayout {
} }
Label { text: qsTr("DeviceType:") } Label { text: qsTr("DeviceType:") }
ComboBox { ComboBox {
id: deviceTypeCombobox
Layout.fillWidth: true Layout.fillWidth: true
model: deviceTypesModel model: deviceTypesModel
textRole: "name" textRole: "name"
valueRole: "id" valueRole: "id"
// TODO make binding for selection currentIndex: deviceTypeCombobox.indexOfValue(listView.currentData.deviceTypeId)
onCurrentValueChanged: if (listView.currentData) listView.currentData.deviceTypeId = currentValue; else console.warn('discarded');
} }
Label { text: qsTr("Address:") } Label { text: qsTr("Address:") }
SpinBox { SpinBox {

View File

@ -7,7 +7,7 @@
#include <QQmlEngine> #include <QQmlEngine>
constexpr auto IdRole = Qt::UserRole; constexpr auto IdRole = Qt::UserRole;
constexpr auto LightTypeIdRole = Qt::UserRole + 1; constexpr auto DeviceTypeIdRole = Qt::UserRole + 1;
constexpr auto AddressRole = Qt::UserRole + 2; constexpr auto AddressRole = Qt::UserRole + 2;
constexpr auto PositionRole = Qt::UserRole + 3; constexpr auto PositionRole = Qt::UserRole + 3;
@ -33,7 +33,7 @@ int DevicesModel::rowCount(const QModelIndex &parent) const
if (!m_controller) if (!m_controller)
return 0; return 0;
return m_controller->lightProject().lights.size(); return m_controller->lightProject().devices.size();
} }
QVariant DevicesModel::data(const QModelIndex &index, int role) const QVariant DevicesModel::data(const QModelIndex &index, int role) const
@ -50,8 +50,8 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
return {}; return {};
} }
const auto &lights = m_controller->lightProject().lights; const auto &devices = m_controller->lightProject().devices;
if (index.row() < 0 || index.row() >= lights.size()) if (index.row() < 0 || index.row() >= devices.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
@ -63,16 +63,16 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
return {}; return {};
} }
const auto &light = lights.at(index.row()); const auto &device = devices.at(index.row());
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
case Qt::EditRole: return light.name; case Qt::EditRole: return device.name;
case IdRole: return light.id; case IdRole: return device.id;
case LightTypeIdRole: return light.lightTypeId; case DeviceTypeIdRole: return device.deviceTypeId;
case AddressRole: return light.address; case AddressRole: return device.address;
case PositionRole: return light.position; case PositionRole: return device.position;
} }
return {}; return {};
@ -92,8 +92,8 @@ QMap<int, QVariant> DevicesModel::itemData(const QModelIndex &index) const
return {}; return {};
} }
const auto &lights = m_controller->lightProject().lights; const auto &devices = m_controller->lightProject().devices;
if (index.row() < 0 || index.row() >= lights.size()) if (index.row() < 0 || index.row() >= devices.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
@ -105,14 +105,13 @@ QMap<int, QVariant> DevicesModel::itemData(const QModelIndex &index) const
return {}; return {};
} }
const auto &light = lights.at(index.row()); const auto &device = devices.at(index.row());
return { return {
{ Qt::DisplayRole, light.name }, { Qt::DisplayRole, device.name },
{ IdRole, light.id }, { IdRole, device.id },
{ LightTypeIdRole, light.lightTypeId }, { DeviceTypeIdRole, device.deviceTypeId },
{ AddressRole, light.address }, { AddressRole, device.address },
{ PositionRole, light.position } { PositionRole, device.position }
}; };
} }
@ -121,7 +120,7 @@ QHash<int, QByteArray> DevicesModel::roleNames() const
return { return {
{ Qt::DisplayRole, "name" }, { Qt::DisplayRole, "name" },
{ IdRole, "id" }, { IdRole, "id" },
{ LightTypeIdRole, "lightTypeId" }, { DeviceTypeIdRole, "deviceTypeId" },
{ AddressRole, "address" }, { AddressRole, "address" },
{ PositionRole, "position" } { PositionRole, "position" }
}; };
@ -141,8 +140,8 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int
return false; return false;
} }
auto &lights = m_controller->lightProject().lights; auto &devices = m_controller->lightProject().devices;
if (index.row() < 0 || index.row() >= lights.size()) if (index.row() < 0 || index.row() >= devices.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return false; return false;
@ -154,7 +153,7 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int
return false; return false;
} }
auto &light = lights.at(index.row()); auto &device = devices.at(index.row());
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
@ -164,7 +163,7 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int
qWarning() << "hilfe" << __LINE__ << value.userType(); qWarning() << "hilfe" << __LINE__ << value.userType();
return false; return false;
} }
light.name = value.toString(); device.name = value.toString();
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole }); emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
return true; return true;
case IdRole: case IdRole:
@ -173,17 +172,17 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int
qWarning() << "hilfe" << __LINE__ << value.userType(); qWarning() << "hilfe" << __LINE__ << value.userType();
return false; return false;
} }
light.id = value.toInt(); device.id = value.toInt();
emit dataChanged(index, index, { IdRole }); emit dataChanged(index, index, { IdRole });
return true; return true;
case LightTypeIdRole: case DeviceTypeIdRole:
if (value.userType() != QMetaType::Int) if (value.userType() != QMetaType::Int)
{ {
qWarning() << "hilfe" << __LINE__ << value.userType(); qWarning() << "hilfe" << __LINE__ << value.userType();
return false; return false;
} }
light.lightTypeId = value.toInt(); device.deviceTypeId = value.toInt();
emit dataChanged(index, index, { LightTypeIdRole }); emit dataChanged(index, index, { DeviceTypeIdRole });
return true; return true;
case AddressRole: case AddressRole:
if (value.userType() != QMetaType::Int) if (value.userType() != QMetaType::Int)
@ -191,7 +190,7 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int
qWarning() << "hilfe" << __LINE__ << value.userType(); qWarning() << "hilfe" << __LINE__ << value.userType();
return false; return false;
} }
light.address = value.toInt(); device.address = value.toInt();
emit dataChanged(index, index, { AddressRole }); emit dataChanged(index, index, { AddressRole });
return true; return true;
case PositionRole: case PositionRole:
@ -200,7 +199,7 @@ bool DevicesModel::setData(const QModelIndex &index, const QVariant &value, int
qWarning() << "hilfe" << __LINE__ << value.userType(); qWarning() << "hilfe" << __LINE__ << value.userType();
return false; return false;
} }
light.position = value.value<QVector3D>(); device.position = value.value<QVector3D>();
emit dataChanged(index, index, { PositionRole }); emit dataChanged(index, index, { PositionRole });
return true; return true;
} }
@ -222,7 +221,7 @@ bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
return false; return false;
} }
auto &lights = m_controller->lightProject().lights; auto &devices = m_controller->lightProject().devices;
if (row < 0) if (row < 0)
{ {
@ -230,19 +229,19 @@ bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
return false; return false;
} }
if (row > lights.size()) if (row > devices.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return false; return false;
} }
auto max_iter = std::max_element(std::cbegin(lights), std::cend(lights), [](const auto &l, const auto &r){ return l.id < r.id; }); auto max_iter = std::max_element(std::cbegin(devices), std::cend(devices), [](const auto &l, const auto &r){ return l.id < r.id; });
auto id = max_iter != std::cend(lights) ? max_iter->id + 1 : 0; auto id = max_iter != std::cend(devices) ? max_iter->id + 1 : 0;
beginInsertRows({}, row, row+count-1); beginInsertRows({}, row, row+count-1);
auto iter = std::begin(lights) + row; auto iter = std::begin(devices) + row;
for (; count > 0; count--) for (; count > 0; count--)
iter = lights.insert(iter, LightConfig{ .id=id++, .name="<neu>", .lightTypeId=0, .address=0, .position={} }) + 1; iter = devices.insert(iter, LightConfig{ .id=id++, .name="<neu>", .deviceTypeId=0, .address=0, .position={} }) + 1;
endInsertRows(); endInsertRows();
return true; return true;
@ -262,7 +261,7 @@ bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
return false; return false;
} }
auto &lights = m_controller->lightProject().lights; auto &devices = m_controller->lightProject().devices;
if (row < 0) if (row < 0)
{ {
@ -270,22 +269,22 @@ bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
return false; return false;
} }
if (row >= lights.size()) if (row >= devices.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return false; return false;
} }
if (row + count > lights.size()) if (row + count > devices.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return false; return false;
} }
beginRemoveRows({}, row, row+count-1); beginRemoveRows({}, row, row+count-1);
auto begin = std::begin(lights) + row; auto begin = std::begin(devices) + row;
auto end = begin + count; auto end = begin + count;
lights.erase(begin, end); devices.erase(begin, end);
endRemoveRows(); endRemoveRows();
return true; return true;

View File

@ -42,14 +42,14 @@ int DeviceTypeRegistersModel::rowCount(const QModelIndex &parent) const
if (m_deviceTypeId == -1) if (m_deviceTypeId == -1)
return 0; return 0;
auto lightType = m_controller->lightProject().lightTypes.findById(m_deviceTypeId); auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
if (!lightType) if (!deviceType)
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return 0; return 0;
} }
return lightType->registers.size(); return deviceType->registers.size();
} }
QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) const QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) const
@ -72,14 +72,14 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons
return {}; return {};
} }
auto lightType = m_controller->lightProject().lightTypes.findById(m_deviceTypeId); auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
if (!lightType) if (!deviceType)
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
} }
if (index.row() < 0 || index.row() >= lightType->registers.size()) if (index.row() < 0 || index.row() >= deviceType->registers.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
@ -91,16 +91,16 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons
return {}; return {};
} }
const auto &lightTypeRegister = lightType->registers.at(index.row()); const auto &deviceTypeRegister = deviceType->registers.at(index.row());
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
{ {
return QMetaEnum::fromType<LightTypeRegisterType>().valueToKey(std::to_underlying(lightTypeRegister.type)); return QMetaEnum::fromType<DeviceTypeRegisterType>().valueToKey(std::to_underlying(deviceTypeRegister.type));
} }
case Qt::EditRole: case Qt::EditRole:
return QVariant::fromValue(lightTypeRegister.type); return QVariant::fromValue(deviceTypeRegister.type);
} }
return {}; return {};
@ -126,14 +126,14 @@ QMap<int, QVariant> DeviceTypeRegistersModel::itemData(const QModelIndex &index)
return {}; return {};
} }
auto lightType = m_controller->lightProject().lightTypes.findById(m_deviceTypeId); auto deviceType = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
if (!lightType) if (!deviceType)
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
} }
if (index.row() < 0 || index.row() >= lightType->registers.size()) if (index.row() < 0 || index.row() >= deviceType->registers.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
@ -145,11 +145,11 @@ QMap<int, QVariant> DeviceTypeRegistersModel::itemData(const QModelIndex &index)
return {}; return {};
} }
const auto &lightTypeRegister = lightType->registers.at(index.row()); const auto &deviceTypeRegister = deviceType->registers.at(index.row());
return { return {
{ Qt::DisplayRole, QMetaEnum::fromType<LightTypeRegisterType>().valueToKey(std::to_underlying(lightTypeRegister.type)) }, { Qt::DisplayRole, QMetaEnum::fromType<DeviceTypeRegisterType>().valueToKey(std::to_underlying(deviceTypeRegister.type)) },
{ Qt::EditRole, QVariant::fromValue(lightTypeRegister.type) } { Qt::EditRole, QVariant::fromValue(deviceTypeRegister.type) }
}; };
} }

View File

@ -28,7 +28,7 @@ int DeviceTypesModel::rowCount(const QModelIndex &parent) const
if (!m_controller) if (!m_controller)
return 0; return 0;
return m_controller->lightProject().lightTypes.size(); return m_controller->lightProject().deviceTypes.size();
} }
QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const
@ -45,9 +45,9 @@ QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const
return {}; return {};
} }
const auto &lightTypes = m_controller->lightProject().lightTypes; const auto &deviceTypes = m_controller->lightProject().deviceTypes;
if (index.row() < 0 || index.row() >= lightTypes.size()) if (index.row() < 0 || index.row() >= deviceTypes.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
@ -59,13 +59,13 @@ QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const
return {}; return {};
} }
const auto &lightType = lightTypes.at(index.row()); const auto &deviceType = deviceTypes.at(index.row());
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
case Qt::EditRole: return lightType.name; case Qt::EditRole: return deviceType.name;
case IdRole: return lightType.id; case IdRole: return deviceType.id;
} }
return {}; return {};
@ -85,9 +85,9 @@ QMap<int, QVariant> DeviceTypesModel::itemData(const QModelIndex &index) const
return {}; return {};
} }
const auto &lightTypes = m_controller->lightProject().lightTypes; const auto &deviceTypes = m_controller->lightProject().deviceTypes;
if (index.row() < 0 || index.row() >= lightTypes.size()) if (index.row() < 0 || index.row() >= deviceTypes.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return {}; return {};
@ -99,11 +99,11 @@ QMap<int, QVariant> DeviceTypesModel::itemData(const QModelIndex &index) const
return {}; return {};
} }
const auto &lightType = lightTypes.at(index.row()); const auto &deviceType = deviceTypes.at(index.row());
return { return {
{ Qt::DisplayRole, lightType.name }, { Qt::DisplayRole, deviceType.name },
{ IdRole, lightType.id } { IdRole, deviceType.id }
}; };
} }
@ -129,8 +129,8 @@ bool DeviceTypesModel::setData(const QModelIndex &index, const QVariant &value,
return false; return false;
} }
auto &lightTypes = m_controller->lightProject().lightTypes; auto &deviceTypes = m_controller->lightProject().deviceTypes;
if (index.row() < 0 || index.row() >= lightTypes.size()) if (index.row() < 0 || index.row() >= deviceTypes.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return false; return false;
@ -142,7 +142,7 @@ bool DeviceTypesModel::setData(const QModelIndex &index, const QVariant &value,
return false; return false;
} }
auto &lightType = lightTypes.at(index.row()); auto &deviceType = deviceTypes.at(index.row());
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
@ -152,7 +152,7 @@ bool DeviceTypesModel::setData(const QModelIndex &index, const QVariant &value,
qWarning() << "hilfe" << __LINE__ << value.userType(); qWarning() << "hilfe" << __LINE__ << value.userType();
return false; return false;
} }
lightType.name = value.toString(); deviceType.name = value.toString();
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole }); emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
return true; return true;
case IdRole: case IdRole:
@ -161,7 +161,7 @@ bool DeviceTypesModel::setData(const QModelIndex &index, const QVariant &value,
qWarning() << "hilfe" << __LINE__ << value.userType(); qWarning() << "hilfe" << __LINE__ << value.userType();
return false; return false;
} }
lightType.id = value.toInt(); deviceType.id = value.toInt();
emit dataChanged(index, index, { IdRole }); emit dataChanged(index, index, { IdRole });
return true; return true;
} }
@ -183,7 +183,7 @@ bool DeviceTypesModel::insertRows(int row, int count, const QModelIndex &parent)
return false; return false;
} }
auto &lightTypes = m_controller->lightProject().lightTypes; auto &deviceTypes = m_controller->lightProject().deviceTypes;
if (row < 0) if (row < 0)
{ {
@ -191,19 +191,19 @@ bool DeviceTypesModel::insertRows(int row, int count, const QModelIndex &parent)
return false; return false;
} }
if (row > lightTypes.size()) if (row > deviceTypes.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return false; return false;
} }
auto max_iter = std::max_element(std::cbegin(lightTypes), std::cend(lightTypes), [](const auto &l, const auto &r){ return l.id < r.id; }); auto max_iter = std::max_element(std::cbegin(deviceTypes), std::cend(deviceTypes), [](const auto &l, const auto &r){ return l.id < r.id; });
auto id = max_iter != std::cend(lightTypes) ? max_iter->id + 1 : 0; auto id = max_iter != std::cend(deviceTypes) ? max_iter->id + 1 : 0;
beginInsertRows({}, row, row+count-1); beginInsertRows({}, row, row+count-1);
auto iter = std::begin(lightTypes) + row; auto iter = std::begin(deviceTypes) + row;
for (; count > 0; count--) for (; count > 0; count--)
iter = lightTypes.insert(iter, LightTypeConfig{ .id=id++, .name="<neu>" }) + 1; iter = deviceTypes.insert(iter, DeviceTypeConfig{ .id=id++, .name="<neu>" }) + 1;
endInsertRows(); endInsertRows();
return true; return true;
@ -223,7 +223,7 @@ bool DeviceTypesModel::removeRows(int row, int count, const QModelIndex &parent)
return false; return false;
} }
auto &lightTypes = m_controller->lightProject().lightTypes; auto &deviceTypes = m_controller->lightProject().deviceTypes;
if (row < 0) if (row < 0)
{ {
@ -231,22 +231,22 @@ bool DeviceTypesModel::removeRows(int row, int count, const QModelIndex &parent)
return false; return false;
} }
if (row >= lightTypes.size()) if (row >= deviceTypes.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return false; return false;
} }
if (row + count > lightTypes.size()) if (row + count > deviceTypes.size())
{ {
qWarning() << "hilfe" << __LINE__; qWarning() << "hilfe" << __LINE__;
return false; return false;
} }
beginRemoveRows({}, row, row+count-1); beginRemoveRows({}, row, row+count-1);
auto begin = std::begin(lightTypes) + row; auto begin = std::begin(deviceTypes) + row;
auto end = begin + count; auto end = begin + count;
lightTypes.erase(begin, end); deviceTypes.erase(begin, end);
endRemoveRows(); endRemoveRows();
return true; return true;

View File

@ -11,7 +11,7 @@ DmxController::DmxController(QObject *parent) :
m_lastInfo{QDateTime::currentDateTime()}, m_lastInfo{QDateTime::currentDateTime()},
m_counter{}, m_counter{},
m_lightProject { m_lightProject {
.lightTypes { .deviceTypes {
{ {
.id=0, .id=0,
.name="Stairville MH-X50+" .name="Stairville MH-X50+"
@ -20,13 +20,13 @@ DmxController::DmxController(QObject *parent) :
.id=1, .id=1,
.name="RGBW Strahler", .name="RGBW Strahler",
.registers { .registers {
LightTypeRegisterConfig { .type = LightTypeRegisterType::Dimmer }, DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dimmer },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Red }, DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Red },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Green }, DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Green },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Blue }, DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Blue },
LightTypeRegisterConfig { .type = LightTypeRegisterType::White }, DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::White },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Strobo }, DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Strobo },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Dummy } DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dummy }
} }
}, },
{ {
@ -38,18 +38,18 @@ DmxController::DmxController(QObject *parent) :
.name="Nebelmaschine" .name="Nebelmaschine"
} }
}, },
.lights { .devices {
{ .id=0, .name="Lampe 1", .lightTypeId=1, .address=32, .position{1,0,0} }, { .id=0, .name="Lampe 1", .deviceTypeId=1, .address=32, .position{1,0,0} },
{ .id=1, .name="Lampe 2", .lightTypeId=1, .address=0, .position{2,0,0} }, { .id=1, .name="Lampe 2", .deviceTypeId=1, .address=0, .position{2,0,0} },
{ .id=2, .name="Lampe 3", .lightTypeId=1, .address=7, .position{3,0,0} }, { .id=2, .name="Lampe 3", .deviceTypeId=1, .address=7, .position{3,0,0} },
{ .id=3, .name="Lampe 4", .lightTypeId=1, .address=14 }, { .id=3, .name="Lampe 4", .deviceTypeId=1, .address=14 },
{ .id=4, .name="Moving Head 1", .lightTypeId=0, .address=40 }, { .id=4, .name="Moving Head 1", .deviceTypeId=0, .address=40 },
{ .id=5, .name="Moving Head 2", .lightTypeId=0, .address=43 }, { .id=5, .name="Moving Head 2", .deviceTypeId=0, .address=43 },
{ .id=6, .name="Moving Head 3", .lightTypeId=0, .address=46 }, { .id=6, .name="Moving Head 3", .deviceTypeId=0, .address=46 },
{ .id=7, .name="Moving Head 4", .lightTypeId=0, .address=49 }, { .id=7, .name="Moving Head 4", .deviceTypeId=0, .address=49 },
{ .id=8, .name="Test 1", .lightTypeId=2, .address=70 }, { .id=8, .name="Test 1", .deviceTypeId=2, .address=70 },
{ .id=9, .name="Test 2", .lightTypeId=2, .address=72 }, { .id=9, .name="Test 2", .deviceTypeId=2, .address=72 },
{ .id=10, .name="Nebelmaschine", .lightTypeId=3, .address=80 } { .id=10, .name="Nebelmaschine", .deviceTypeId=3, .address=80 }
} }
} }
{ {

View File

@ -10,7 +10,7 @@
namespace hilfe { namespace hilfe {
Q_NAMESPACE Q_NAMESPACE
enum class LightTypeRegisterType enum class DeviceTypeRegisterType
{ {
Dummy, Dummy,
Dimmer, Dimmer,
@ -21,43 +21,43 @@ enum class LightTypeRegisterType
Strobo, Strobo,
Shutter Shutter
}; };
Q_ENUM_NS(LightTypeRegisterType) Q_ENUM_NS(DeviceTypeRegisterType)
} // namespace hilfe } // namespace hilfe
Q_DECLARE_METATYPE(hilfe::LightTypeRegisterType) Q_DECLARE_METATYPE(hilfe::DeviceTypeRegisterType)
using LightTypeRegisterType = hilfe::LightTypeRegisterType; using DeviceTypeRegisterType = hilfe::DeviceTypeRegisterType;
struct LightTypeRegisterConfig struct DeviceTypeRegisterConfig
{ {
LightTypeRegisterType type; DeviceTypeRegisterType type;
}; };
struct LightTypeConfig struct DeviceTypeConfig
{ {
int id; int id;
QString name; QString name;
std::vector<LightTypeRegisterConfig> registers; std::vector<DeviceTypeRegisterConfig> registers;
}; };
class LightTypesContainer : public std::vector<LightTypeConfig> class DeviceTypesContainer : public std::vector<DeviceTypeConfig>
{ {
using base_t = std::vector<LightTypeConfig>; using base_t = std::vector<DeviceTypeConfig>;
public: public:
using base_t::base_t; using base_t::base_t;
LightTypeConfig *findById(int id) DeviceTypeConfig *findById(int id)
{ {
auto iter = std::find_if(std::begin(*this), std::end(*this), auto iter = std::find_if(std::begin(*this), std::end(*this),
[&id](const LightTypeConfig &lightType){ return lightType.id == id; }); [&id](const DeviceTypeConfig &deviceType){ return deviceType.id == id; });
return iter != std::end(*this) ? &*iter : nullptr; return iter != std::end(*this) ? &*iter : nullptr;
} }
const LightTypeConfig *findById(int id) const const DeviceTypeConfig *findById(int id) const
{ {
auto iter = std::find_if(std::begin(*this), std::end(*this), auto iter = std::find_if(std::begin(*this), std::end(*this),
[&id](const LightTypeConfig &lightType){ return lightType.id == id; }); [&id](const DeviceTypeConfig &deviceType){ return deviceType.id == id; });
return iter != std::end(*this) ? &*iter : nullptr; return iter != std::end(*this) ? &*iter : nullptr;
} }
}; };
@ -66,13 +66,13 @@ struct LightConfig
{ {
int id; int id;
QString name; QString name;
int lightTypeId; int deviceTypeId;
int address; int address;
QVector3D position; QVector3D position;
}; };
struct LightProject struct LightProject
{ {
LightTypesContainer lightTypes; DeviceTypesContainer deviceTypes;
std::vector<LightConfig> lights; std::vector<LightConfig> devices;
}; };