renamed register groups to presets

This commit is contained in:
2023-02-22 23:18:09 +01:00
parent 0692669550
commit bbb3ccd0db
14 changed files with 470 additions and 470 deletions

View File

@ -24,9 +24,9 @@ qt_add_executable(appscheincommander
lightproject.h lightproject.cpp
devicesmodel.h devicesmodel.cpp
devicetyperegistersmodel.h devicetyperegistersmodel.cpp
registergroupsmodel.h registergroupsmodel.cpp
presetsmodel.h presetsmodel.cpp
deviceregistervaluehelper.h deviceregistervaluehelper.cpp
registergroupmodel.h registergroupmodel.cpp
presetmodel.h presetmodel.cpp
projectloader.h projectloader.cpp
scheincommandersettings.h scheincommandersettings.cpp
iconutils.h iconutils.cpp
@ -53,7 +53,7 @@ qt_add_qml_module(appscheincommander
Vector3DField.qml
DmxSlider.qml
StatusBar.qml
RegisterGroupsSettingsPage.qml
PresetsSettingsPage.qml
RegistersSettingsItem.qml
IconComboBox.qml
IconsModel.qml

View File

@ -32,7 +32,7 @@ Item {
flow: Flow.TopToBottom
Repeater {
model: RegisterGroupsModel {
model: PresetsModel {
controller: __controller
}
@ -41,7 +41,7 @@ Item {
text: model.name
}
DmxSlider {
onValueChanged: __controller.setRegisterGroupSlider(model.id, value);
onValueChanged: __controller.setPresetSlider(model.id, value);
}
}
}

View File

@ -9,7 +9,7 @@ ColumnLayout {
property bool needsRegler: true
Label {
text: qsTr("Register Groups Settings")
text: qsTr("Presets Settings")
}
RowLayout {
//Layout.fillWidth: true
@ -22,7 +22,7 @@ ColumnLayout {
Layout.maximumWidth: 300
Layout.fillHeight: true
model: RegisterGroupsModel {
model: PresetsModel {
id: model
controller: __controller
}
@ -90,19 +90,19 @@ ColumnLayout {
columns: 3
RegisterGroupModel {
id: registerGroupModel
PresetModel {
id: presetModel
controller: __controller
registerGroupId: listView.currentData ? listView.currentData.id : -1
presetId: listView.currentData ? listView.currentData.id : -1
}
Button {
text: qsTr('Auf Schieberegler\nunten kopieren');
onPressed: registerGroupModel.copyToFaders()
onPressed: presetModel.copyToFaders()
}
Button {
text: qsTr('Von Schieberegler\nunten kopieren');
onPressed: registerGroupModel.copyFromFaders()
onPressed: presetModel.copyFromFaders()
}
Item {
Layout.rowSpan: 2
@ -110,11 +110,11 @@ ColumnLayout {
}
Button {
text: qsTr('Alle auf\n0 setzen');
onPressed: registerGroupModel.setAllFadersLow()
onPressed: presetModel.setAllFadersLow()
}
Button {
text: qsTr('Alle auf\nMaximum setzen');
onPressed: registerGroupModel.setAllFadersMax()
onPressed: presetModel.setAllFadersMax()
}
RowLayout {
Layout.columnSpan: 3
@ -147,7 +147,7 @@ ColumnLayout {
Button {
text: qsTr('Set')
onPressed: registerGroupModel.setPattern(nSpinBox.value, kSpinBox.value, registerTypeComboBox.currentValue, valueSlider.value)
onPressed: presetModel.setPattern(nSpinBox.value, kSpinBox.value, registerTypeComboBox.currentValue, valueSlider.value)
}
}
}

View File

@ -46,17 +46,17 @@ Item {
Button {
id: button2
text: qsTr("Register\nGroups")
text: qsTr("Presets")
Layout.preferredWidth: 100
Layout.preferredHeight: 100
onClicked: stackview.push(registerGroupsSettingsPage)
onClicked: stackview.push(presetsSettingsPage)
Component {
id: registerGroupsSettingsPage
id: presetsSettingsPage
RegisterGroupsSettingsPage {
PresetsSettingsPage {
}
}
}

View File

@ -373,9 +373,9 @@ bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
emit m_controller->sliderStatesChanged(sliderStates);
}
for (auto &registerGroup : m_controller->lightProject().registerGroups)
for (auto &preset : m_controller->lightProject().presets)
{
auto &sliderStates = registerGroup.sliders;
auto &sliderStates = preset.sliders;
if (sliderStates.size() > row)
{
sliderStates.insert(std::begin(sliderStates) + row, count, {});
@ -446,9 +446,9 @@ bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
emit m_controller->sliderStatesChanged(sliderStates);
}
for (auto &registerGroup : m_controller->lightProject().registerGroups)
for (auto &preset : m_controller->lightProject().presets)
{
if (auto &sliderStates = registerGroup.sliders; sliderStates.size() > row)
if (auto &sliderStates = preset.sliders; sliderStates.size() > row)
{
auto begin = std::begin(sliderStates) + row;
auto end = begin + std::min<size_t>(count, sliderStates.size() - row + count);

View File

@ -159,7 +159,7 @@ DmxController::DmxController(ScheinCommanderSettings &settings, QObject *parent)
// { .id=18, .name="Moving Head 4", .deviceTypeId=0, .address=163 },
// { .id=19, .name="Nebelmaschine", .deviceTypeId=3, .address=179 }
},
.registerGroups {
.presets {
{ .id=0, .name="Alle Dimmer" },
{ .id=1, .name="Alle Roten" },
{ .id=2, .name="Alle Grünen" },
@ -300,24 +300,24 @@ bool DmxController::saveProject(const QUrl &url)
return saveProject(url.toLocalFile());
}
void DmxController::setRegisterGroupSlider(int registerGroupId, quint8 value)
void DmxController::setPresetSlider(int presetId, quint8 value)
{
const auto registerGroupPtr = m_lightProject.registerGroups.findById(registerGroupId);
if (!registerGroupPtr)
const auto presetPtr = m_lightProject.presets.findById(presetId);
if (!presetPtr)
{
qWarning() << "hilfe" << __LINE__;
return;
}
const auto index = registerGroupPtr - &*std::cbegin(m_lightProject.registerGroups);
const auto index = presetPtr - &*std::cbegin(m_lightProject.presets);
{
QMutexLocker locker{&m_mutex};
if (index >= m_registerGroupStates.size())
m_registerGroupStates.resize(index + 1);
if (index >= m_presetStates.size())
m_presetStates.resize(index + 1);
m_registerGroupStates[index] = value;
m_presetStates[index] = value;
}
}
@ -403,17 +403,17 @@ void DmxController::sendDmxBuffer()
apply(m_sliderStates, 255);
auto iter = std::cbegin(m_registerGroupStates);
for (const auto &registerGroup : m_lightProject.registerGroups)
auto iter = std::cbegin(m_presetStates);
for (const auto &preset : m_lightProject.presets)
{
if (iter == std::cend(m_registerGroupStates))
if (iter == std::cend(m_presetStates))
break;
if (!*iter)
{
iter++;
continue;
}
apply(registerGroup.sliders, *iter);
apply(preset.sliders, *iter);
iter++;
}
}

View File

@ -27,9 +27,9 @@ public:
Q_INVOKABLE bool saveProject(const QString &name);
Q_INVOKABLE bool saveProject(const QUrl &url);
Q_INVOKABLE void setRegisterGroupSlider(int registerGroupId, quint8 value);
std::vector<quint8> &registerGroupStates() { return m_registerGroupStates; }
const std::vector<quint8> &registerGroupStates() const { return m_registerGroupStates; }
Q_INVOKABLE void setPresetSlider(int presetId, quint8 value);
std::vector<quint8> &presetStates() { return m_presetStates; }
const std::vector<quint8> &presetStates() const { return m_presetStates; }
LightProject &lightProject() { return m_lightProject; }
const LightProject &lightProject() const { return m_lightProject; }
@ -68,9 +68,9 @@ signals:
void deviceAddressChanged(int row, int address);
void devicePositionChanged(int row, const QVector3D &position);
void registerGroupInserted(int first, int last);
void registerGroupRemoved(int first, int last);
void registerGroupNameChanged(int row, const QString &name);
void presetInserted(int first, int last);
void presetRemoved(int first, int last);
void presetNameChanged(int row, const QString &name);
void sliderStatesChanged(const sliders_state_t &sliderStates);
@ -89,7 +89,7 @@ private:
LightProject m_lightProject;
QMutex m_mutex;
sliders_state_t m_sliderStates;
std::vector<quint8> m_registerGroupStates;
std::vector<quint8> m_presetStates;
QDateTime m_lastInfo;
int m_counter;

View File

@ -113,31 +113,31 @@ public:
using sliders_state_t = std::vector<std::vector<quint8>>;
struct RegisterGroupConfig
struct PresetConfig
{
int id;
QString name;
sliders_state_t sliders;
};
class RegisterGroupsContainer : public std::vector<RegisterGroupConfig>
class PresetsContainer : public std::vector<PresetConfig>
{
using base_t = std::vector<RegisterGroupConfig>;
using base_t = std::vector<PresetConfig>;
public:
using base_t::base_t;
RegisterGroupConfig *findById(int id)
PresetConfig *findById(int id)
{
auto iter = std::find_if(std::begin(*this), std::end(*this),
[&id](const RegisterGroupConfig &registerGroup){ return registerGroup.id == id; });
[&id](const PresetConfig &preset){ return preset.id == id; });
return iter != std::end(*this) ? &*iter : nullptr;
}
const RegisterGroupConfig *findById(int id) const
const PresetConfig *findById(int id) const
{
auto iter = std::find_if(std::begin(*this), std::end(*this),
[&id](const RegisterGroupConfig &registerGroup){ return registerGroup.id == id; });
[&id](const PresetConfig &preset){ return preset.id == id; });
return iter != std::end(*this) ? &*iter : nullptr;
}
};
@ -146,5 +146,5 @@ struct LightProject
{
DeviceTypesContainer deviceTypes;
DevicesContainer devices;
RegisterGroupsContainer registerGroups;
PresetsContainer presets;
};

View File

@ -1,43 +1,43 @@
#include "registergroupmodel.h"
#include "presetmodel.h"
#include <QDebug>
#include <QCoreApplication>
#include <QQmlEngine>
#include <QMutexLocker>
void RegisterGroupModel::setController(DmxController *controller)
void PresetModel::setController(DmxController *controller)
{
if (m_controller == controller)
return;
if (m_controller)
{
// disconnect(m_controller, &DmxController::registerGroupInserted,
// this, &RegisterGroupsModel::otherRegisterGroupInserted);
// disconnect(m_controller, &DmxController::presetInserted,
// this, &PresetsModel::otherPresetInserted);
}
m_controller = controller;
if (m_controller)
{
// connect(m_controller, &DmxController::registerGroupInserted,
// this, &RegisterGroupsModel::otherRegisterGroupInserted);
// connect(m_controller, &DmxController::presetInserted,
// this, &PresetsModel::otherPresetInserted);
}
emit controllerChanged(m_controller);
}
void RegisterGroupModel::setRegisterGroupId(int registerGroupId)
void PresetModel::setPresetId(int presetId)
{
if (m_registerGroupId == registerGroupId)
if (m_presetId == presetId)
return;
m_registerGroupId = registerGroupId;
m_presetId = presetId;
emit registerGroupIdChanged(m_registerGroupId);
emit presetIdChanged(m_presetId);
}
void RegisterGroupModel::copyFromFaders()
void PresetModel::copyFromFaders()
{
if (!m_controller)
{
@ -45,28 +45,28 @@ void RegisterGroupModel::copyFromFaders()
return;
}
if (m_registerGroupId == -1)
if (m_presetId == -1)
{
qDebug() << "hilfe" << __LINE__;
return;
}
auto registerGroupPtr = m_controller->lightProject().registerGroups.findById(m_registerGroupId);
if (!registerGroupPtr)
auto presetPtr = m_controller->lightProject().presets.findById(m_presetId);
if (!presetPtr)
{
qDebug() << "hilfe" << __LINE__;
return;
}
auto &registerGroup = *registerGroupPtr;
auto &preset = *presetPtr;
{
QMutexLocker locker{&m_controller->mutex()};
registerGroup.sliders = m_controller->sliderStates();
preset.sliders = m_controller->sliderStates();
}
}
void RegisterGroupModel::copyToFaders()
void PresetModel::copyToFaders()
{
if (!m_controller)
{
@ -74,25 +74,25 @@ void RegisterGroupModel::copyToFaders()
return;
}
if (m_registerGroupId == -1)
if (m_presetId == -1)
{
qDebug() << "hilfe" << __LINE__;
return;
}
const auto registerGroupPtr = m_controller->lightProject().registerGroups.findById(m_registerGroupId);
if (!registerGroupPtr)
const auto presetPtr = m_controller->lightProject().presets.findById(m_presetId);
if (!presetPtr)
{
qDebug() << "hilfe" << __LINE__;
return;
}
const auto &registerGroup = *registerGroupPtr;
const auto &preset = *presetPtr;
m_controller->setSliderStates(registerGroup.sliders);
m_controller->setSliderStates(preset.sliders);
}
void RegisterGroupModel::setAllFadersLow()
void PresetModel::setAllFadersLow()
{
if (!m_controller)
{
@ -130,7 +130,7 @@ void RegisterGroupModel::setAllFadersLow()
m_controller->setSliderStates(std::move(sliderStates));
}
void RegisterGroupModel::setAllFadersMax()
void PresetModel::setAllFadersMax()
{
if (!m_controller)
{
@ -168,7 +168,7 @@ void RegisterGroupModel::setAllFadersMax()
m_controller->setSliderStates(std::move(sliderStates));
}
void RegisterGroupModel::setPattern(int n, int k, DeviceTypeRegisterType registerType, quint8 value)
void PresetModel::setPattern(int n, int k, DeviceTypeRegisterType registerType, quint8 value)
{
if (!m_controller)
{
@ -212,7 +212,7 @@ void RegisterGroupModel::setPattern(int n, int k, DeviceTypeRegisterType registe
namespace {
void registrierDenShit()
{
qmlRegisterType<RegisterGroupModel>("scheincommander", 1, 0, "RegisterGroupModel");
qmlRegisterType<PresetModel>("scheincommander", 1, 0, "PresetModel");
}
}
Q_COREAPP_STARTUP_FUNCTION(registrierDenShit)

View File

@ -4,11 +4,11 @@
#include "dmxcontroller.h"
class RegisterGroupModel : public QObject
class PresetModel : public QObject
{
Q_OBJECT
Q_PROPERTY(DmxController* controller READ controller WRITE setController NOTIFY controllerChanged)
Q_PROPERTY(int registerGroupId READ registerGroupId WRITE setRegisterGroupId NOTIFY registerGroupIdChanged)
Q_PROPERTY(int presetId READ presetId WRITE setPresetId NOTIFY presetIdChanged)
public:
using QObject::QObject;
@ -17,8 +17,8 @@ public:
const DmxController *controller() const { return m_controller; }
void setController(DmxController *controller);
int registerGroupId() const { return m_registerGroupId; }
void setRegisterGroupId(int registerGroupId);
int presetId() const { return m_presetId; }
void setPresetId(int presetId);
Q_INVOKABLE void copyFromFaders();
Q_INVOKABLE void copyToFaders();
@ -28,9 +28,9 @@ public:
signals:
void controllerChanged(DmxController *controller);
void registerGroupIdChanged(int registerGroupId);
void presetIdChanged(int presetId);
private:
DmxController *m_controller{};
int m_registerGroupId{-1};
int m_presetId{-1};
};

373
presetsmodel.cpp Normal file
View File

@ -0,0 +1,373 @@
#include "presetsmodel.h"
#include <algorithm>
#include <QDebug>
#include <QCoreApplication>
#include <QQmlEngine>
#include <QMutexLocker>
enum {
IdRole = Qt::UserRole,
};
void PresetsModel::setController(DmxController *controller)
{
if (m_controller == controller)
return;
beginResetModel();
if (m_controller)
{
disconnect(m_controller, &DmxController::presetInserted,
this, &PresetsModel::otherPresetInserted);
disconnect(m_controller, &DmxController::presetRemoved,
this, &PresetsModel::otherPresetRemoved);
disconnect(m_controller, &DmxController::presetNameChanged,
this, &PresetsModel::otherPresetNameChanged);
}
m_controller = controller;
if (m_controller)
{
connect(m_controller, &DmxController::presetInserted,
this, &PresetsModel::otherPresetInserted);
connect(m_controller, &DmxController::presetRemoved,
this, &PresetsModel::otherPresetRemoved);
connect(m_controller, &DmxController::presetNameChanged,
this, &PresetsModel::otherPresetNameChanged);
}
endResetModel();
emit controllerChanged(m_controller);
}
int PresetsModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return -1;
}
if (!m_controller)
return 0;
const auto &presets = m_controller->lightProject().presets;
return presets.size();
}
QVariant PresetsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
{
qWarning() << "hilfe" << __LINE__;
return {};
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return {};
}
const auto &presets = m_controller->lightProject().presets;
if (index.row() < 0 || index.row() >= presets.size())
{
qWarning() << "hilfe" << __LINE__;
return {};
}
if (index.column() != 0)
{
qWarning() << "hilfe" << __LINE__;
return {};
}
const auto &preset = presets.at(index.row());
switch (role)
{
case Qt::DisplayRole:
case Qt::EditRole: return preset.name;
case IdRole: return preset.id;
}
return {};
}
QMap<int, QVariant> PresetsModel::itemData(const QModelIndex &index) const
{
if (!index.isValid())
{
qWarning() << "hilfe" << __LINE__;
return {};
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return {};
}
const auto &presets = m_controller->lightProject().presets;
if (index.row() < 0 || index.row() >= presets.size())
{
qWarning() << "hilfe" << __LINE__;
return {};
}
if (index.column() != 0)
{
qWarning() << "hilfe" << __LINE__;
return {};
}
const auto &preset = presets.at(index.row());
return {
{ Qt::DisplayRole, preset.name },
{ IdRole, preset.id }
};
}
QHash<int, QByteArray> PresetsModel::roleNames() const
{
return {
{ Qt::DisplayRole, "name" },
{ IdRole, "id" }
};
}
bool PresetsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto &presets = m_controller->lightProject().presets;
if (index.row() < 0 || index.row() >= presets.size())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (index.column() != 0)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto &preset = presets.at(index.row());
switch (role)
{
case Qt::DisplayRole:
case Qt::EditRole:
if (value.userType() != QMetaType::QString)
{
qWarning() << "hilfe" << __LINE__ << value.userType();
return false;
}
preset.name = value.toString();
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
disconnect(m_controller, &DmxController::presetNameChanged,
this, &PresetsModel::otherPresetNameChanged);
emit m_controller->presetNameChanged(index.row(), preset.name);
connect(m_controller, &DmxController::presetNameChanged,
this, &PresetsModel::otherPresetNameChanged);
return true;
case IdRole:
// if (value.userType() != QMetaType::Int)
// {
// qWarning() << "hilfe" << __LINE__ << value.userType();
// return false;
// }
// preset.id = value.toInt();
// emit dataChanged(index, index, { IdRole });
// return true;
qWarning() << "hilfe" << __LINE__;
return false;
default:
qWarning() << "hilfe" << __LINE__;
return false;
}
}
bool PresetsModel::insertRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto &presets = m_controller->lightProject().presets;
if (row < 0)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (row > presets.size())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto max_iter = std::max_element(std::cbegin(presets), std::cend(presets), [](const auto &l, const auto &r){ return l.id < r.id; });
auto id = max_iter != std::cend(presets) ? max_iter->id + 1 : 0;
beginInsertRows({}, row, row+count-1);
{
QMutexLocker locker{&m_controller->mutex()};
{
auto iter = std::begin(presets) + row;
for (auto i = 0; i < count; i++)
iter = presets.insert(iter, PresetConfig{ .id=id++, .name="<neu>" }) + 1;
}
if (auto &presetStates = m_controller->presetStates(); presetStates.size() > row)
{
presetStates.insert(std::begin(presetStates) + row, count, {});
// emit m_controller->presetStatesChanged(presetStates);
}
}
endInsertRows();
disconnect(m_controller, &DmxController::presetInserted,
this, &PresetsModel::otherPresetInserted);
emit m_controller->presetInserted(row, row+count-1);
connect(m_controller, &DmxController::presetInserted,
this, &PresetsModel::otherPresetInserted);
return true;
}
bool PresetsModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto &presets = m_controller->lightProject().presets;
if (row < 0)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (row >= presets.size())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (row + count > presets.size())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
beginRemoveRows({}, row, row+count-1);
{
QMutexLocker locker{&m_controller->mutex()};
{
auto begin = std::begin(presets) + row;
auto end = begin + count;
presets.erase(begin, end);
}
if (auto &presetStates = m_controller->presetStates(); presetStates.size() > row)
{
auto begin = std::begin(presetStates) + row;
auto end = begin + std::min<size_t>(count, presetStates.size() - row + count);
presetStates.erase(begin, end);
//emit m_controller->presetStatesChanged(presetStates);
}
}
endRemoveRows();
disconnect(m_controller, &DmxController::presetRemoved,
this, &PresetsModel::otherPresetRemoved);
emit m_controller->presetRemoved(row, row+count-1);
connect(m_controller, &DmxController::presetRemoved,
this, &PresetsModel::otherPresetRemoved);
return true;
}
void PresetsModel::otherPresetInserted(int first, int last)
{
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return;
}
beginInsertRows({}, first, last);
endInsertRows();
}
void PresetsModel::otherPresetRemoved(int first, int last)
{
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return;
}
beginRemoveRows({}, first, last);
endRemoveRows();
}
void PresetsModel::otherPresetNameChanged(int row, const QString &name)
{
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return;
}
const auto index = this->index(row);
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
}
namespace {
void registrierDenShit()
{
qmlRegisterType<PresetsModel>("scheincommander", 1, 0, "PresetsModel");
}
}
Q_COREAPP_STARTUP_FUNCTION(registrierDenShit)

View File

@ -4,7 +4,7 @@
#include "dmxcontroller.h"
class RegisterGroupsModel : public QAbstractListModel
class PresetsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(DmxController* controller READ controller WRITE setController NOTIFY controllerChanged)
@ -29,9 +29,9 @@ signals:
void controllerChanged(DmxController *controller);
private slots:
void otherRegisterGroupInserted(int first, int last);
void otherRegisterGroupRemoved(int first, int last);
void otherRegisterGroupNameChanged(int row, const QString &name);
void otherPresetInserted(int first, int last);
void otherPresetRemoved(int first, int last);
void otherPresetNameChanged(int row, const QString &name);
private:
DmxController *m_controller{};

View File

@ -21,7 +21,7 @@ concept Listific = is_specialization_t<T, std::list>::value ||
is_specialization_t<T, std::vector>::value ||
std::same_as<T, DeviceTypesContainer> ||
std::same_as<T, DevicesContainer> ||
std::same_as<T, RegisterGroupsContainer>;
std::same_as<T, PresetsContainer>;
template<typename T>
concept OtherLoadableFromArray = std::same_as<T, QVector3D>;
@ -34,7 +34,7 @@ concept LoadableFromObject = std::same_as<T, LightProject> ||
std::same_as<T, DeviceConfig> ||
std::same_as<T, DeviceTypeConfig> ||
std::same_as<T, DeviceTypeRegisterConfig> ||
std::same_as<T, RegisterGroupConfig>;
std::same_as<T, PresetConfig>;
template<typename T>
concept JsonNumber = (std::integral<T> && !std::same_as<T, bool> && !std::is_enum_v<T>) ||
@ -161,10 +161,10 @@ std::expected<T, QString> load(const QJsonObject &json) {
return std::unexpected(QString("devices: %1").arg(devices.error()));
}
if (auto registerGroups = loadIfExists<decltype(lp.registerGroups)>(json, "registerGroups"); registerGroups) {
lp.registerGroups = std::move(registerGroups.value());
if (auto presets = loadIfExists<decltype(lp.presets)>(json, "presets"); presets) {
lp.presets = std::move(presets.value());
} else {
return std::unexpected(QString("registerGroups: %1").arg(registerGroups.error()));
return std::unexpected(QString("presets: %1").arg(presets.error()));
}
return lp;
@ -245,9 +245,9 @@ std::expected<T, QString> load(const QJsonObject &json) {
return dc;
}
template<std::same_as<RegisterGroupConfig> T>
template<std::same_as<PresetConfig> T>
std::expected<T, QString> load(const QJsonObject &json) {
RegisterGroupConfig rgc;
PresetConfig rgc;
if (auto val = loadIfExists<decltype(rgc.id)>(json, "id"); val) {
rgc.id = val.value();
} else {
@ -392,7 +392,7 @@ std::expected<QJsonObject, QString> save(const T &val) {
return json;
}
template<std::same_as<RegisterGroupConfig> T>
template<std::same_as<PresetConfig> T>
std::expected<QJsonObject, QString> save(const T &val) {
QJsonObject json;
if (auto id = save<decltype(val.id)>(val.id); id) {
@ -446,10 +446,10 @@ std::expected<QJsonObject, QString> save(const T &val) {
return std::unexpected(QString("devices: %1").arg(devices.error()));
}
if (auto registerGroups = save<decltype(val.registerGroups)>(val.registerGroups); registerGroups) {
json["registerGroups"] = registerGroups.value();
if (auto presets = save<decltype(val.presets)>(val.presets); presets) {
json["presets"] = presets.value();
} else {
return std::unexpected(QString("registerGroups: %1").arg(registerGroups.error()));
return std::unexpected(QString("presets: %1").arg(presets.error()));
}
return json;

View File

@ -1,373 +0,0 @@
#include "registergroupsmodel.h"
#include <algorithm>
#include <QDebug>
#include <QCoreApplication>
#include <QQmlEngine>
#include <QMutexLocker>
enum {
IdRole = Qt::UserRole,
};
void RegisterGroupsModel::setController(DmxController *controller)
{
if (m_controller == controller)
return;
beginResetModel();
if (m_controller)
{
disconnect(m_controller, &DmxController::registerGroupInserted,
this, &RegisterGroupsModel::otherRegisterGroupInserted);
disconnect(m_controller, &DmxController::registerGroupRemoved,
this, &RegisterGroupsModel::otherRegisterGroupRemoved);
disconnect(m_controller, &DmxController::registerGroupNameChanged,
this, &RegisterGroupsModel::otherRegisterGroupNameChanged);
}
m_controller = controller;
if (m_controller)
{
connect(m_controller, &DmxController::registerGroupInserted,
this, &RegisterGroupsModel::otherRegisterGroupInserted);
connect(m_controller, &DmxController::registerGroupRemoved,
this, &RegisterGroupsModel::otherRegisterGroupRemoved);
connect(m_controller, &DmxController::registerGroupNameChanged,
this, &RegisterGroupsModel::otherRegisterGroupNameChanged);
}
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 &registerGroups = 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 &registerGroups = 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 &registerGroup = registerGroups.at(index.row());
switch (role)
{
case Qt::DisplayRole:
case Qt::EditRole: return registerGroup.name;
case IdRole: return registerGroup.id;
}
return {};
}
QMap<int, QVariant> RegisterGroupsModel::itemData(const QModelIndex &index) const
{
if (!index.isValid())
{
qWarning() << "hilfe" << __LINE__;
return {};
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return {};
}
const auto &registerGroups = 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 &registerGroup = registerGroups.at(index.row());
return {
{ Qt::DisplayRole, registerGroup.name },
{ IdRole, registerGroup.id }
};
}
QHash<int, QByteArray> RegisterGroupsModel::roleNames() const
{
return {
{ Qt::DisplayRole, "name" },
{ IdRole, "id" }
};
}
bool RegisterGroupsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto &registerGroups = m_controller->lightProject().registerGroups;
if (index.row() < 0 || index.row() >= registerGroups.size())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (index.column() != 0)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto &registerGroup = registerGroups.at(index.row());
switch (role)
{
case Qt::DisplayRole:
case Qt::EditRole:
if (value.userType() != QMetaType::QString)
{
qWarning() << "hilfe" << __LINE__ << value.userType();
return false;
}
registerGroup.name = value.toString();
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
disconnect(m_controller, &DmxController::registerGroupNameChanged,
this, &RegisterGroupsModel::otherRegisterGroupNameChanged);
emit m_controller->registerGroupNameChanged(index.row(), registerGroup.name);
connect(m_controller, &DmxController::registerGroupNameChanged,
this, &RegisterGroupsModel::otherRegisterGroupNameChanged);
return true;
case IdRole:
// if (value.userType() != QMetaType::Int)
// {
// qWarning() << "hilfe" << __LINE__ << value.userType();
// return false;
// }
// registerGroup.id = value.toInt();
// emit dataChanged(index, index, { IdRole });
// return true;
qWarning() << "hilfe" << __LINE__;
return false;
default:
qWarning() << "hilfe" << __LINE__;
return false;
}
}
bool RegisterGroupsModel::insertRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto &registerGroups = m_controller->lightProject().registerGroups;
if (row < 0)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (row > registerGroups.size())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto max_iter = std::max_element(std::cbegin(registerGroups), std::cend(registerGroups), [](const auto &l, const auto &r){ return l.id < r.id; });
auto id = max_iter != std::cend(registerGroups) ? max_iter->id + 1 : 0;
beginInsertRows({}, row, row+count-1);
{
QMutexLocker locker{&m_controller->mutex()};
{
auto iter = std::begin(registerGroups) + row;
for (auto i = 0; i < count; i++)
iter = registerGroups.insert(iter, RegisterGroupConfig{ .id=id++, .name="<neu>" }) + 1;
}
if (auto &registerGroupStates = m_controller->registerGroupStates(); registerGroupStates.size() > row)
{
registerGroupStates.insert(std::begin(registerGroupStates) + row, count, {});
// emit m_controller->registerGroupStatesChanged(registerGroupStates);
}
}
endInsertRows();
disconnect(m_controller, &DmxController::registerGroupInserted,
this, &RegisterGroupsModel::otherRegisterGroupInserted);
emit m_controller->registerGroupInserted(row, row+count-1);
connect(m_controller, &DmxController::registerGroupInserted,
this, &RegisterGroupsModel::otherRegisterGroupInserted);
return true;
}
bool RegisterGroupsModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
auto &registerGroups = m_controller->lightProject().registerGroups;
if (row < 0)
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (row >= registerGroups.size())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
if (row + count > registerGroups.size())
{
qWarning() << "hilfe" << __LINE__;
return false;
}
beginRemoveRows({}, row, row+count-1);
{
QMutexLocker locker{&m_controller->mutex()};
{
auto begin = std::begin(registerGroups) + row;
auto end = begin + count;
registerGroups.erase(begin, end);
}
if (auto &registerGroupStates = m_controller->registerGroupStates(); registerGroupStates.size() > row)
{
auto begin = std::begin(registerGroupStates) + row;
auto end = begin + std::min<size_t>(count, registerGroupStates.size() - row + count);
registerGroupStates.erase(begin, end);
//emit m_controller->registerGroupStatesChanged(registerGroupStates);
}
}
endRemoveRows();
disconnect(m_controller, &DmxController::registerGroupRemoved,
this, &RegisterGroupsModel::otherRegisterGroupRemoved);
emit m_controller->registerGroupRemoved(row, row+count-1);
connect(m_controller, &DmxController::registerGroupRemoved,
this, &RegisterGroupsModel::otherRegisterGroupRemoved);
return true;
}
void RegisterGroupsModel::otherRegisterGroupInserted(int first, int last)
{
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return;
}
beginInsertRows({}, first, last);
endInsertRows();
}
void RegisterGroupsModel::otherRegisterGroupRemoved(int first, int last)
{
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return;
}
beginRemoveRows({}, first, last);
endRemoveRows();
}
void RegisterGroupsModel::otherRegisterGroupNameChanged(int row, const QString &name)
{
if (!m_controller)
{
qWarning() << "hilfe" << __LINE__;
return;
}
const auto index = this->index(row);
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
}
namespace {
void registrierDenShit()
{
qmlRegisterType<RegisterGroupsModel>("scheincommander", 1, 0, "RegisterGroupsModel");
}
}
Q_COREAPP_STARTUP_FUNCTION(registrierDenShit)