Model improvements (synchronization)
This commit is contained in:
@@ -12,8 +12,31 @@ void DeviceTypeRegistersModel::setController(DmxController *controller)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
|
if (m_controller)
|
||||||
|
{
|
||||||
|
disconnect(m_controller, &DmxController::deviceTypeRegisterInserted,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterInserted);
|
||||||
|
disconnect(m_controller, &DmxController::deviceTypeRegisterRemoved,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterRemoved);
|
||||||
|
disconnect(m_controller, &DmxController::deviceTypeRegisterTypeChanged,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterTypeChanged);
|
||||||
|
}
|
||||||
|
|
||||||
m_controller = controller;
|
m_controller = controller;
|
||||||
|
|
||||||
|
if (m_controller)
|
||||||
|
{
|
||||||
|
connect(m_controller, &DmxController::deviceTypeRegisterInserted,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterInserted);
|
||||||
|
connect(m_controller, &DmxController::deviceTypeRegisterRemoved,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterRemoved);
|
||||||
|
connect(m_controller, &DmxController::deviceTypeRegisterTypeChanged,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterTypeChanged);
|
||||||
|
}
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
emit controllerChanged(m_controller);
|
emit controllerChanged(m_controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,26 +195,26 @@ bool DeviceTypeRegistersModel::setData(const QModelIndex &index, const QVariant
|
|||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
{
|
{
|
||||||
qWarning() << "hilfe" << __LINE__;
|
qWarning() << "hilfe" << __LINE__;
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_controller)
|
if (!m_controller)
|
||||||
{
|
{
|
||||||
qWarning() << "hilfe" << __LINE__;
|
qWarning() << "hilfe" << __LINE__;
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_deviceTypeId == -1)
|
if (m_deviceTypeId == -1)
|
||||||
{
|
{
|
||||||
qWarning() << "hilfe" << __LINE__;
|
qWarning() << "hilfe" << __LINE__;
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
|
auto deviceTypePtr = m_controller->lightProject().deviceTypes.findById(m_deviceTypeId);
|
||||||
if (!deviceTypePtr)
|
if (!deviceTypePtr)
|
||||||
{
|
{
|
||||||
qWarning() << "hilfe" << __LINE__;
|
qWarning() << "hilfe" << __LINE__;
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &deviceType = *deviceTypePtr;
|
auto &deviceType = *deviceTypePtr;
|
||||||
@@ -199,20 +222,35 @@ bool DeviceTypeRegistersModel::setData(const QModelIndex &index, const QVariant
|
|||||||
if (index.row() < 0 || index.row() >= deviceType.registers.size())
|
if (index.row() < 0 || index.row() >= deviceType.registers.size())
|
||||||
{
|
{
|
||||||
qWarning() << "hilfe" << __LINE__;
|
qWarning() << "hilfe" << __LINE__;
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index.column() != 0)
|
if (index.column() != 0)
|
||||||
{
|
{
|
||||||
qWarning() << "hilfe" << __LINE__;
|
qWarning() << "hilfe" << __LINE__;
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &deviceTypeRegister = deviceType.registers.at(index.row());
|
auto &deviceTypeRegister = deviceType.registers.at(index.row());
|
||||||
|
|
||||||
|
switch (role)
|
||||||
|
{
|
||||||
|
case Qt::EditRole:
|
||||||
deviceTypeRegister.type = value.value<DeviceTypeRegisterType>();
|
deviceTypeRegister.type = value.value<DeviceTypeRegisterType>();
|
||||||
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
|
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
|
||||||
|
|
||||||
|
disconnect(m_controller, &DmxController::deviceTypeRegisterTypeChanged,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterTypeChanged);
|
||||||
|
emit m_controller->deviceTypeRegisterTypeChanged(deviceType, index.row(), deviceTypeRegister.type);
|
||||||
|
connect(m_controller, &DmxController::deviceTypeRegisterTypeChanged,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterTypeChanged);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
qWarning() << "hilfe" << __LINE__;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceTypeRegistersModel::insertRows(int row, int count, const QModelIndex &parent)
|
bool DeviceTypeRegistersModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||||
@@ -258,6 +296,12 @@ bool DeviceTypeRegistersModel::insertRows(int row, int count, const QModelIndex
|
|||||||
iter = registers.insert(iter, DeviceTypeRegisterConfig{ .type = DeviceTypeRegisterType::Dummy }) + 1;
|
iter = registers.insert(iter, DeviceTypeRegisterConfig{ .type = DeviceTypeRegisterType::Dummy }) + 1;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
|
disconnect(m_controller, &DmxController::deviceTypeRegisterInserted,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterInserted);
|
||||||
|
emit m_controller->deviceTypeRegisterInserted(deviceType, row, row+count-1);
|
||||||
|
connect(m_controller, &DmxController::deviceTypeRegisterInserted,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterInserted);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,9 +360,30 @@ bool DeviceTypeRegistersModel::removeRows(int row, int count, const QModelIndex
|
|||||||
registers.erase(begin, end);
|
registers.erase(begin, end);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
|
disconnect(m_controller, &DmxController::deviceTypeRegisterRemoved,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterRemoved);
|
||||||
|
emit m_controller->deviceTypeRegisterRemoved(deviceType, row, row+count-1);
|
||||||
|
connect(m_controller, &DmxController::deviceTypeRegisterRemoved,
|
||||||
|
this, &DeviceTypeRegistersModel::otherDeviceTypeRegisterRemoved);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceTypeRegistersModel::otherDeviceTypeRegisterInserted(const DeviceTypeConfig &deviceType, int first, int last)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceTypeRegistersModel::otherDeviceTypeRegisterRemoved(const DeviceTypeConfig &deviceType, int first, int last)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceTypeRegistersModel::otherDeviceTypeRegisterTypeChanged(const DeviceTypeConfig &deviceType, int index, DeviceTypeRegisterType type)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void registerDenShit()
|
void registerDenShit()
|
||||||
{
|
{
|
||||||
|
@@ -33,6 +33,11 @@ signals:
|
|||||||
void controllerChanged(DmxController *controller);
|
void controllerChanged(DmxController *controller);
|
||||||
void deviceTypeIdChanged(int deviceTypeId);
|
void deviceTypeIdChanged(int deviceTypeId);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void otherDeviceTypeRegisterInserted(const DeviceTypeConfig &deviceType, int first, int last);
|
||||||
|
void otherDeviceTypeRegisterRemoved(const DeviceTypeConfig &deviceType, int first, int last);
|
||||||
|
void otherDeviceTypeRegisterTypeChanged(const DeviceTypeConfig &deviceType, int index, DeviceTypeRegisterType type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DmxController *m_controller{};
|
DmxController *m_controller{};
|
||||||
int m_deviceTypeId{-1};
|
int m_deviceTypeId{-1};
|
||||||
|
@@ -30,6 +30,10 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void performanceChanged(int performance);
|
void performanceChanged(int performance);
|
||||||
|
|
||||||
|
void deviceTypeRegisterInserted(const DeviceTypeConfig &deviceType, int first, int last);
|
||||||
|
void deviceTypeRegisterRemoved(const DeviceTypeConfig &deviceType, int first, int last);
|
||||||
|
void deviceTypeRegisterTypeChanged(const DeviceTypeConfig &deviceType, int index, DeviceTypeRegisterType type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class DmxControllerThread;
|
friend class DmxControllerThread;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user