Preperations for registers in light types

This commit is contained in:
2023-02-15 21:54:26 +01:00
parent 4d471d057c
commit 975b2b7a52
9 changed files with 273 additions and 97 deletions

View File

@@ -3,7 +3,9 @@ cmake_minimum_required(VERSION 3.16)
project(lightcontrol VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
find_package(Qt6 6.2 REQUIRED COMPONENTS SerialPort Quick)
@@ -14,6 +16,7 @@ qt_add_executable(applightcontrol
dmxcontrollerthread.h dmxcontrollerthread.cpp
lightproject.h lightproject.cpp
devicesmodel.h devicesmodel.cpp
devicetyperegistersmodel.h devicetyperegistersmodel.cpp
)
qt_add_qml_module(applightcontrol

View File

@@ -2,6 +2,7 @@
#include <algorithm>
#include <QDebug>
#include <QCoreApplication>
#include <QQmlEngine>
@@ -10,36 +11,15 @@ constexpr auto LightTypeIdRole = Qt::UserRole + 1;
constexpr auto AddressRole = Qt::UserRole + 2;
constexpr auto PositionRole = Qt::UserRole + 3;
DevicesModel::DevicesModel(QObject *parent) :
QAbstractItemModel{parent}
{
}
void DevicesModel::setController(DmxController *controller)
{
if (m_controller != controller)
{
beginResetModel();
m_controller = controller;
endResetModel();
emit controllerChanged(m_controller);
}
}
if (m_controller == controller)
return;
QModelIndex DevicesModel::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return {};
}
return createIndex(row, column, nullptr);
}
QModelIndex DevicesModel::parent(const QModelIndex &child) const
{
return {};
beginResetModel();
m_controller = controller;
endResetModel();
emit controllerChanged(m_controller);
}
int DevicesModel::rowCount(const QModelIndex &parent) const
@@ -56,16 +36,6 @@ int DevicesModel::rowCount(const QModelIndex &parent) const
return m_controller->lightProject().lights.size();
}
int DevicesModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return -1;
}
return 1;
}
QVariant DevicesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
@@ -80,7 +50,8 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
return {};
}
if (index.row() < 0 || index.row() >= m_controller->lightProject().lights.size())
const auto &lights = m_controller->lightProject().lights;
if (index.row() < 0 || index.row() >= lights.size())
{
qWarning() << "hilfe" << __LINE__;
return {};
@@ -92,7 +63,7 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
return {};
}
const auto &light = m_controller->lightProject().lights.at(index.row());
const auto &light = lights.at(index.row());
switch (role)
{
@@ -121,7 +92,8 @@ QMap<int, QVariant> DevicesModel::itemData(const QModelIndex &index) const
return {};
}
if (index.row() < 0 || index.row() >= m_controller->lightProject().lights.size())
const auto &lights = m_controller->lightProject().lights;
if (index.row() < 0 || index.row() >= lights.size())
{
qWarning() << "hilfe" << __LINE__;
return {};
@@ -133,7 +105,7 @@ QMap<int, QVariant> DevicesModel::itemData(const QModelIndex &index) const
return {};
}
const auto &light = m_controller->lightProject().lights.at(index.row());
const auto &light = lights.at(index.row());
return {
{ Qt::DisplayRole, light.name },

View File

@@ -4,22 +4,19 @@
#include "dmxcontroller.h"
class DevicesModel : public QAbstractItemModel
class DevicesModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(DmxController* controller READ controller WRITE setController NOTIFY controllerChanged)
public:
explicit DevicesModel(QObject *parent = nullptr);
using QAbstractListModel::QAbstractListModel;
DmxController *controller() { return m_controller; }
const DmxController *controller() const { return m_controller; }
void setController(DmxController *controller);
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QMap<int, QVariant> itemData(const QModelIndex &index) const override;
QHash<int, QByteArray> roleNames() const override;

View File

@@ -0,0 +1,126 @@
#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;
auto lightType = m_controller->lightProject().lightTypes.findById(m_deviceTypeId);
if (!lightType)
{
qWarning() << "hilfe" << __LINE__;
return 0;
}
return lightType->registers.size();
}
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 {};
}
auto lightType = m_controller->lightProject().lightTypes.findById(m_deviceTypeId);
if (!lightType)
{
qWarning() << "hilfe" << __LINE__;
return {};
}
if (index.row() < 0 || index.row() >= lightType->registers.size())
{
qWarning() << "hilfe" << __LINE__;
return {};
}
if (index.column() != 0)
{
qWarning() << "hilfe" << __LINE__;
return {};
}
const auto &lightTypeRegister = lightType->registers.at(index.row());
switch (role)
{
case Qt::DisplayRole:
{
return QMetaEnum::fromType<LightTypeRegisterType>().valueToKey(std::to_underlying(lightTypeRegister.type));
}
case Qt::EditRole:
return QVariant::fromValue(lightTypeRegister.type);
}
return {};
}
QMap<int, QVariant> DeviceTypeRegistersModel::itemData(const QModelIndex &index) const
{
// TODO
}
QHash<int, QByteArray> DeviceTypeRegistersModel::roleNames() const
{
// TODO
}
namespace {
void registerDenShit()
{
qmlRegisterType<DeviceTypeRegistersModel>("com.büro", 1, 0, "DeviceTypeRegistersModel");
}
}
Q_COREAPP_STARTUP_FUNCTION(registerDenShit)

View File

@@ -0,0 +1,35 @@
#pragma once
#include <QAbstractItemModel>
#include "dmxcontroller.h"
class DeviceTypeRegistersModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(DmxController* controller READ controller WRITE setController NOTIFY controllerChanged)
Q_PROPERTY(int deviceTypeId READ deviceTypeId WRITE setDeviceTypeId NOTIFY deviceTypeIdChanged)
public:
using QAbstractListModel::QAbstractListModel;
DmxController *controller() { return m_controller; }
const DmxController *controller() const { return m_controller; }
void setController(DmxController *controller);
int deviceTypeId() const { return m_deviceTypeId; }
void setDeviceTypeId(int deviceTypeId);
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QMap<int, QVariant> itemData(const QModelIndex &index) const override;
QHash<int, QByteArray> roleNames() const override;
signals:
void controllerChanged(DmxController *controller);
void deviceTypeIdChanged(int deviceTypeId);
private:
DmxController *m_controller{};
int m_deviceTypeId{-1};
};

View File

@@ -1,40 +1,20 @@
#include "devicetypesmodel.h"
#include <QDebug>
#include <QCoreApplication>
#include <QQmlEngine>
constexpr auto IdRole = Qt::UserRole;
DeviceTypesModel::DeviceTypesModel(QObject *parent) :
QAbstractItemModel{parent}
{
}
void DeviceTypesModel::setController(DmxController *controller)
{
if (m_controller != controller)
{
beginResetModel();
m_controller = controller;
endResetModel();
emit controllerChanged(m_controller);
}
}
if (m_controller == controller)
return;
QModelIndex DeviceTypesModel::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return {};
}
return createIndex(row, column, nullptr);
}
QModelIndex DeviceTypesModel::parent(const QModelIndex &child) const
{
return {};
beginResetModel();
m_controller = controller;
endResetModel();
emit controllerChanged(m_controller);
}
int DeviceTypesModel::rowCount(const QModelIndex &parent) const
@@ -51,16 +31,6 @@ int DeviceTypesModel::rowCount(const QModelIndex &parent) const
return m_controller->lightProject().lightTypes.size();
}
int DeviceTypesModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return -1;
}
return 1;
}
QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
@@ -75,7 +45,9 @@ QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const
return {};
}
if (index.row() < 0 || index.row() >= m_controller->lightProject().lightTypes.size())
const auto &lightTypes = m_controller->lightProject().lightTypes;
if (index.row() < 0 || index.row() >= lightTypes.size())
{
qWarning() << "hilfe" << __LINE__;
return {};
@@ -87,7 +59,7 @@ QVariant DeviceTypesModel::data(const QModelIndex &index, int role) const
return {};
}
const auto &lightType = m_controller->lightProject().lightTypes.at(index.row());
const auto &lightType = lightTypes.at(index.row());
switch (role)
{
@@ -113,7 +85,9 @@ QMap<int, QVariant> DeviceTypesModel::itemData(const QModelIndex &index) const
return {};
}
if (index.row() < 0 || index.row() >= m_controller->lightProject().lightTypes.size())
const auto &lightTypes = m_controller->lightProject().lightTypes;
if (index.row() < 0 || index.row() >= lightTypes.size())
{
qWarning() << "hilfe" << __LINE__;
return {};
@@ -125,7 +99,7 @@ QMap<int, QVariant> DeviceTypesModel::itemData(const QModelIndex &index) const
return {};
}
const auto &lightType = m_controller->lightProject().lightTypes.at(index.row());
const auto &lightType = lightTypes.at(index.row());
return {
{ Qt::DisplayRole, lightType.name },

View File

@@ -4,22 +4,19 @@
#include "dmxcontroller.h"
class DeviceTypesModel : public QAbstractItemModel
class DeviceTypesModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(DmxController* controller READ controller WRITE setController NOTIFY controllerChanged)
public:
explicit DeviceTypesModel(QObject *parent = nullptr);
using QAbstractListModel::QAbstractListModel;
DmxController *controller() { return m_controller; }
const DmxController *controller() const { return m_controller; }
void setController(DmxController *controller);
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QMap<int, QVariant> itemData(const QModelIndex &index) const override;
QHash<int, QByteArray> roleNames() const override;

View File

@@ -12,10 +12,31 @@ DmxController::DmxController(QObject *parent) :
m_counter{},
m_lightProject {
.lightTypes {
{ .id=0, .name="Stairville MH-X50+" },
{ .id=1, .name="RGBW Strahler" },
{ .id=2, .name="RGB Strahler" },
{ .id=3, .name="Nebelmaschine" }
{
.id=0,
.name="Stairville MH-X50+"
},
{
.id=1,
.name="RGBW Strahler",
.registers {
LightTypeRegisterConfig { .type = LightTypeRegisterType::Dimmer },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Red },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Green },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Blue },
LightTypeRegisterConfig { .type = LightTypeRegisterType::White },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Strobo },
LightTypeRegisterConfig { .type = LightTypeRegisterType::Dummy }
}
},
{
.id=2,
.name="RGB Strahler"
},
{
.id=3,
.name="Nebelmaschine"
}
},
.lights {
{ .id=0, .name="Lampe 1", .lightTypeId=1, .address=32, .position{1,0,0} },

View File

@@ -1,14 +1,65 @@
#pragma once
#include <vector>
#include <algorithm>
#include <QString>
#include <QVector3D>
#include <QMetaEnum>
#include <QMetaType>
namespace hilfe {
Q_NAMESPACE
enum class LightTypeRegisterType
{
Dummy,
Dimmer,
Red,
Green,
Blue,
White,
Strobo,
Shutter
};
Q_ENUM_NS(LightTypeRegisterType)
} // namespace hilfe
Q_DECLARE_METATYPE(hilfe::LightTypeRegisterType)
using LightTypeRegisterType = hilfe::LightTypeRegisterType;
struct LightTypeRegisterConfig
{
LightTypeRegisterType type;
};
struct LightTypeConfig
{
int id;
QString name;
std::vector<LightTypeRegisterConfig> registers;
};
class LightTypesContainer : public std::vector<LightTypeConfig>
{
using base_t = std::vector<LightTypeConfig>;
public:
using base_t::base_t;
LightTypeConfig *findById(int id)
{
auto iter = std::find_if(std::begin(*this), std::end(*this),
[&id](const LightTypeConfig &lightType){ return lightType.id == id; });
return iter != std::end(*this) ? &*iter : nullptr;
}
const LightTypeConfig *findById(int id) const
{
auto iter = std::find_if(std::begin(*this), std::end(*this),
[&id](const LightTypeConfig &lightType){ return lightType.id == id; });
return iter != std::end(*this) ? &*iter : nullptr;
}
};
struct LightConfig
@@ -22,6 +73,6 @@ struct LightConfig
struct LightProject
{
std::vector<LightTypeConfig> lightTypes;
LightTypesContainer lightTypes;
std::vector<LightConfig> lights;
};