diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b1782a..82401fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ qt_add_executable(applightcontrol lightproject.h lightproject.cpp devicesmodel.h devicesmodel.cpp devicetyperegistersmodel.h devicetyperegistersmodel.cpp + registergroupsmodel.h registergroupsmodel.cpp ) qt_add_qml_module(applightcontrol diff --git a/DeviceTypeRegisterTypesModel.qml b/DeviceTypeRegisterTypesModel.qml index 79a99e0..622ee58 100644 --- a/DeviceTypeRegisterTypesModel.qml +++ b/DeviceTypeRegisterTypesModel.qml @@ -1,6 +1,6 @@ import QtQuick -import com.büro +import lightcontrol ListModel { ListElement { text: qsTr('Dummy'); value: DeviceTypeRegisterType.Dummy } diff --git a/DeviceTypesSettingsPage.qml b/DeviceTypesSettingsPage.qml index 7707a86..7686488 100644 --- a/DeviceTypesSettingsPage.qml +++ b/DeviceTypesSettingsPage.qml @@ -3,7 +3,7 @@ import QtQuick.Controls import QtQuick.Controls.Material import QtQuick.Layouts -import com.büro 1.0 +import lightcontrol ColumnLayout { Label { diff --git a/DevicesSettingsPage.qml b/DevicesSettingsPage.qml index 8c9011d..9423fce 100644 --- a/DevicesSettingsPage.qml +++ b/DevicesSettingsPage.qml @@ -3,7 +3,7 @@ import QtQuick.Controls import QtQuick.Controls.Material import QtQuick.Layouts -import com.büro +import lightcontrol ColumnLayout { Label { diff --git a/HomePage.qml b/HomePage.qml index 487ac53..0e0944a 100644 --- a/HomePage.qml +++ b/HomePage.qml @@ -2,8 +2,6 @@ import QtQuick import QtQuick.Controls.Material import QtQuick.Layouts -import com.büro 1.0 - Item { id: homePage diff --git a/LightControlWindow.qml b/LightControlWindow.qml index 0d82bef..271fbeb 100644 --- a/LightControlWindow.qml +++ b/LightControlWindow.qml @@ -4,7 +4,7 @@ import QtQuick.Layouts import QtQuick.Window import QtQuick.VirtualKeyboard -import com.büro 1.0 +import lightcontrol ApplicationWindow { id: window diff --git a/LightSliderPane.qml b/LightSliderPane.qml index d0a4167..725ab37 100644 --- a/LightSliderPane.qml +++ b/LightSliderPane.qml @@ -4,7 +4,7 @@ import QtQuick.Layouts import QtQuick.Window import QtQuick.VirtualKeyboard -import com.büro 1.0 +import lightcontrol Pane { property variant light diff --git a/RegisterGroupsSettingsPage.qml b/RegisterGroupsSettingsPage.qml index 332acf2..9da226a 100644 --- a/RegisterGroupsSettingsPage.qml +++ b/RegisterGroupsSettingsPage.qml @@ -3,7 +3,7 @@ import QtQuick.Controls import QtQuick.Controls.Material import QtQuick.Layouts -import com.büro 1.0 +import lightcontrol ColumnLayout { property bool needsRegler: true @@ -21,6 +21,10 @@ ColumnLayout { Layout.preferredWidth: 300 Layout.maximumWidth: 300 Layout.fillHeight: true + + model: RegisterGroupsModel { + controller: __controller + } } ColumnLayout { diff --git a/RegistersSettingsItem.qml b/RegistersSettingsItem.qml index 8a51a24..12ae731 100644 --- a/RegistersSettingsItem.qml +++ b/RegistersSettingsItem.qml @@ -2,7 +2,7 @@ import QtQuick import QtQuick.Controls.Material import QtQuick.Layouts -import com.büro 1.0 +import lightcontrol Pane { property alias deviceTypeId: deviceTypeRegistersModel.deviceTypeId diff --git a/devicesmodel.cpp b/devicesmodel.cpp index e8b409a..e57cecd 100644 --- a/devicesmodel.cpp +++ b/devicesmodel.cpp @@ -6,10 +6,12 @@ #include #include -constexpr auto IdRole = Qt::UserRole; -constexpr auto DeviceTypeIdRole = Qt::UserRole + 1; -constexpr auto AddressRole = Qt::UserRole + 2; -constexpr auto PositionRole = Qt::UserRole + 3; +enum { + IdRole = Qt::UserRole, + DeviceTypeIdRole, + AddressRole, + PositionRole +}; void DevicesModel::setController(DmxController *controller) { @@ -33,7 +35,8 @@ int DevicesModel::rowCount(const QModelIndex &parent) const if (!m_controller) return 0; - return m_controller->lightProject().devices.size(); + const auto &devices = m_controller->lightProject().devices; + return devices.size(); } QVariant DevicesModel::data(const QModelIndex &index, int role) const @@ -291,9 +294,9 @@ bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent) } namespace { -void registerDenShit() +void registrierDenShit() { - qmlRegisterType("com.büro", 1, 0, "DevicesModel"); + qmlRegisterType("lightcontrol", 1, 0, "DevicesModel"); } } -Q_COREAPP_STARTUP_FUNCTION(registerDenShit) +Q_COREAPP_STARTUP_FUNCTION(registrierDenShit) diff --git a/devicesmodel.h b/devicesmodel.h index b4c964c..c0e2133 100644 --- a/devicesmodel.h +++ b/devicesmodel.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "dmxcontroller.h" diff --git a/devicetyperegistersmodel.cpp b/devicetyperegistersmodel.cpp index 627def4..aaec0f1 100644 --- a/devicetyperegistersmodel.cpp +++ b/devicetyperegistersmodel.cpp @@ -65,7 +65,8 @@ int DeviceTypeRegistersModel::rowCount(const QModelIndex &parent) const if (m_deviceTypeId == -1) return 0; - auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + const auto &deviceTypes = m_controller->lightProject().deviceTypes; + auto deviceTypePtr = deviceTypes.findById(m_deviceTypeId); if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; @@ -97,7 +98,8 @@ QVariant DeviceTypeRegistersModel::data(const QModelIndex &index, int role) cons return {}; } - auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + const auto &deviceTypes = m_controller->lightProject().deviceTypes; + auto deviceTypePtr = deviceTypes.findById(m_deviceTypeId); if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; @@ -153,7 +155,8 @@ QMap DeviceTypeRegistersModel::itemData(const QModelIndex &index) return {}; } - auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + const auto &deviceTypes = m_controller->lightProject().deviceTypes; + auto deviceTypePtr = deviceTypes.findById(m_deviceTypeId); if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; @@ -210,7 +213,8 @@ bool DeviceTypeRegistersModel::setData(const QModelIndex &index, const QVariant return false; } - auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + auto &deviceTypes = m_controller->lightProject().deviceTypes; + auto deviceTypePtr = deviceTypes.findById(m_deviceTypeId); if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; @@ -273,7 +277,8 @@ bool DeviceTypeRegistersModel::insertRows(int row, int count, const QModelIndex return false; } - auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + auto &deviceTypes = m_controller->lightProject().deviceTypes; + auto deviceTypePtr = deviceTypes.findById(m_deviceTypeId); if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; @@ -325,7 +330,8 @@ bool DeviceTypeRegistersModel::removeRows(int row, int count, const QModelIndex return false; } - auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId); + auto &deviceTypes = m_controller->lightProject().deviceTypes; + auto deviceTypePtr = deviceTypes.findById(m_deviceTypeId); if (!deviceTypePtr) { qWarning() << "hilfe" << __LINE__; @@ -433,10 +439,10 @@ void DeviceTypeRegistersModel::otherDeviceTypeRegisterTypeChanged(const DeviceTy } namespace { -void registerDenShit() +void registrierDenShit() { - qmlRegisterType("com.büro", 1, 0, "DeviceTypeRegistersModel"); + qmlRegisterType("lightcontrol", 1, 0, "DeviceTypeRegistersModel"); } } -Q_COREAPP_STARTUP_FUNCTION(registerDenShit) +Q_COREAPP_STARTUP_FUNCTION(registrierDenShit) diff --git a/devicetyperegistersmodel.h b/devicetyperegistersmodel.h index 15857c9..9c691a0 100644 --- a/devicetyperegistersmodel.h +++ b/devicetyperegistersmodel.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "dmxcontroller.h" diff --git a/devicetypesmodel.cpp b/devicetypesmodel.cpp index 199be5a..f430c6f 100644 --- a/devicetypesmodel.cpp +++ b/devicetypesmodel.cpp @@ -53,7 +53,8 @@ int DeviceTypesModel::rowCount(const QModelIndex &parent) const if (!m_controller) return 0; - return m_controller->lightProject().deviceTypes.size(); + const auto &deviceTypes = m_controller->lightProject().deviceTypes; + return deviceTypes.size(); } QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const @@ -345,9 +346,9 @@ void DeviceTypesModel::otherDeviceTypeNameChanged(int row, const QString &name) } namespace { -void registerDenShit() +void registrierDenShit() { - qmlRegisterType("com.büro", 1, 0, "DeviceTypesModel"); + qmlRegisterType("lightcontrol", 1, 0, "DeviceTypesModel"); } } -Q_COREAPP_STARTUP_FUNCTION(registerDenShit) +Q_COREAPP_STARTUP_FUNCTION(registrierDenShit) diff --git a/devicetypesmodel.h b/devicetypesmodel.h index 789e7ba..0c05e68 100644 --- a/devicetypesmodel.h +++ b/devicetypesmodel.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "dmxcontroller.h" diff --git a/dmxcontroller.cpp b/dmxcontroller.cpp index 0850806..5bf5d91 100644 --- a/dmxcontroller.cpp +++ b/dmxcontroller.cpp @@ -65,7 +65,7 @@ DmxController::DmxController(QObject *parent) : } }, .devices { - { .id=1, .name="Lampe 1", .deviceTypeId=4, .address=1 }, + { .id=0, .name="Lampe 1", .deviceTypeId=4, .address=1 }, { .id=1, .name="Lampe 2", .deviceTypeId=4, .address=8 }, { .id=2, .name="Lampe 3", .deviceTypeId=4, .address=15 }, { .id=3, .name="Lampe 4", .deviceTypeId=4, .address=22 }, @@ -75,26 +75,40 @@ DmxController::DmxController(QObject *parent) : { .id=7, .name="Lampe 8", .deviceTypeId=4, .address=50 }, { .id=8, .name="Lampe 9", .deviceTypeId=4, .address=57 }, { .id=9, .name="Lampe 10", .deviceTypeId=4, .address=64 }, - { .id=1, .name="Lampe 11", .deviceTypeId=4, .address=71 }, - { .id=1, .name="Lampe 12", .deviceTypeId=4, .address=78 }, - { .id=2, .name="Lampe 13", .deviceTypeId=4, .address=85 }, - { .id=0, .name="Test 1", .deviceTypeId=1, .address=95 }, - { .id=15, .name="Test 2", .deviceTypeId=2, .address=120 }, - { .id=11, .name="Moving Head 1", .deviceTypeId=0, .address=150 }, - { .id=12, .name="Moving Head 2", .deviceTypeId=0, .address=160 }, - { .id=13, .name="Moving Head 3", .deviceTypeId=0, .address=170 }, - { .id=14, .name="Moving Head 4", .deviceTypeId=0, .address=180 }, - { .id=0, .name="Nebelmaschine", .deviceTypeId=3, .address=200 } + { .id=10, .name="Lampe 11", .deviceTypeId=4, .address=71 }, + { .id=11, .name="Lampe 12", .deviceTypeId=4, .address=78 }, + { .id=12, .name="Lampe 13", .deviceTypeId=4, .address=85 }, + { .id=13, .name="Test 1", .deviceTypeId=1, .address=95 }, + { .id=14, .name="Test 2", .deviceTypeId=2, .address=120 }, + { .id=15, .name="Moving Head 1", .deviceTypeId=0, .address=150 }, + { .id=16, .name="Moving Head 2", .deviceTypeId=0, .address=160 }, + { .id=17, .name="Moving Head 3", .deviceTypeId=0, .address=170 }, + { .id=18, .name="Moving Head 4", .deviceTypeId=0, .address=180 }, + { .id=19, .name="Nebelmaschine", .deviceTypeId=3, .address=200 } + }, + .registerGroups { + { .id=0, .name="Alle Dimmmer" }, + { .id=1, .name="Alle Roten" }, + { .id=2, .name="Alle Grünen" }, + { .id=3, .name="Alle Blauen" }, + { .id=4, .name="Alle Weißen" }, + { .id=5, .name="Alle Strobo" }, + { .id=6, .name="2n Dimmmer" }, + { .id=7, .name="2n Roten" }, + { .id=8, .name="2n Grünen" }, + { .id=9, .name="2n Blauen" }, + { .id=10, .name="2n Weißen" }, + { .id=11, .name="2n Strobo" }, + { .id=12, .name="2n+1 Dimmmer" }, + { .id=13, .name="2n+1 Roten" }, + { .id=14, .name="2n+1 Grünen" }, + { .id=15, .name="2n+1 Blauen" }, + { .id=16, .name="2n+1 Weißen" }, + { .id=17, .name="2n+1 Strobo" }, } } { std::fill(std::begin(buf), std::end(buf), 0); - - buf[32] = 255; - buf[33] = 255; - buf[34] = 0; - buf[35] = 0; -// buf[36] = 255; } bool DmxController::start() diff --git a/lightproject.cpp b/lightproject.cpp index c98e0ef..adb4507 100644 --- a/lightproject.cpp +++ b/lightproject.cpp @@ -4,9 +4,9 @@ #include namespace { -void registerDenShit() +void registrierDenShit() { - qmlRegisterUncreatableMetaObject(hilfe::staticMetaObject, "com.büro", 1, 0, "DeviceTypeRegisterType", "lass es du depp"); + qmlRegisterUncreatableMetaObject(hilfe::staticMetaObject, "lightcontrol", 1, 0, "DeviceTypeRegisterType", "lass es du depp"); } } -Q_COREAPP_STARTUP_FUNCTION(registerDenShit) +Q_COREAPP_STARTUP_FUNCTION(registrierDenShit) diff --git a/lightproject.h b/lightproject.h index 5157cfc..9d91cdb 100644 --- a/lightproject.h +++ b/lightproject.h @@ -72,8 +72,15 @@ struct LightConfig QVector3D position; }; +struct RegisterGroupConfig +{ + int id; + QString name; +}; + struct LightProject { DeviceTypesContainer deviceTypes; std::vector devices; + std::vector registerGroups; }; diff --git a/registergroupsmodel.cpp b/registergroupsmodel.cpp new file mode 100644 index 0000000..18d6440 --- /dev/null +++ b/registergroupsmodel.cpp @@ -0,0 +1,127 @@ +#include "registergroupsmodel.h" + +#include +#include +#include + +enum { + IdRole = Qt::UserRole, +}; + +void RegisterGroupsModel::setController(DmxController *controller) +{ + if (m_controller == controller) + return; + + beginResetModel(); + m_controller = controller; + endResetModel(); + emit controllerChanged(m_controller); +} + +int RegisterGroupsModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + { + qWarning() << "hilfe" << __LINE__; + return -1; + } + + if (!m_controller) + return 0; + + const auto ®isterGroups = m_controller->lightProject().registerGroups; + return registerGroups.size(); +} + +QVariant RegisterGroupsModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (!m_controller) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + const auto ®isterGroups = m_controller->lightProject().registerGroups; + + if (index.row() < 0 || index.row() >= registerGroups.size()) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (index.column() != 0) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + const auto ®isterGroup = registerGroups.at(index.row()); + + switch (role) + { + case Qt::DisplayRole: + case Qt::EditRole: return registerGroup.name; + case IdRole: return registerGroup.id; + } + + return {}; +} + +QMap RegisterGroupsModel::itemData(const QModelIndex &index) const +{ + if (!index.isValid()) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (!m_controller) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + const auto ®isterGroups = m_controller->lightProject().registerGroups; + + if (index.row() < 0 || index.row() >= registerGroups.size()) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + if (index.column() != 0) + { + qWarning() << "hilfe" << __LINE__; + return {}; + } + + const auto ®isterGroup = registerGroups.at(index.row()); + + return { + { Qt::DisplayRole, registerGroup.name }, + { IdRole, registerGroup.id } + }; +} + +QHash RegisterGroupsModel::roleNames() const +{ + return { + { Qt::DisplayRole, "name" }, + { IdRole, "id" } + }; +} + +namespace { +void registrierDenShit() +{ + qmlRegisterType("lightcontrol", 1, 0, "RegisterGroupsModel"); +} +} +Q_COREAPP_STARTUP_FUNCTION(registrierDenShit) diff --git a/registergroupsmodel.h b/registergroupsmodel.h new file mode 100644 index 0000000..3d806f8 --- /dev/null +++ b/registergroupsmodel.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include "dmxcontroller.h" + +class RegisterGroupsModel : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(DmxController* controller READ controller WRITE setController NOTIFY controllerChanged) + +public: + using QAbstractListModel::QAbstractListModel; + + DmxController *controller() { return m_controller; } + const DmxController *controller() const { return m_controller; } + void setController(DmxController *controller); + + int rowCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + QMap itemData(const QModelIndex &index) const override; + QHash roleNames() const override; + +signals: + void controllerChanged(DmxController *controller); + +private: + DmxController *m_controller{}; +};