More model improvements (synchronization in DeviceTypesModel)
This commit is contained in:
@ -27,7 +27,10 @@ ColumnLayout {
|
||||
Layout.maximumWidth: 300
|
||||
Layout.fillHeight: true
|
||||
|
||||
model: deviceTypesModel
|
||||
model: DeviceTypesModel {
|
||||
id: deviceTypesModel
|
||||
controller: __controller
|
||||
}
|
||||
|
||||
onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (deviceTypesModel.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); }
|
||||
onRemoveClicked: (index) => {
|
||||
|
@ -3,6 +3,8 @@ import QtQuick.Controls
|
||||
import QtQuick.Controls.Material
|
||||
import QtQuick.Layouts
|
||||
|
||||
import com.büro
|
||||
|
||||
ColumnLayout {
|
||||
Label {
|
||||
text: qsTr("Devices Settings")
|
||||
@ -83,7 +85,9 @@ ColumnLayout {
|
||||
ComboBox {
|
||||
id: deviceTypeCombobox
|
||||
Layout.fillWidth: true
|
||||
model: deviceTypesModel
|
||||
model: DeviceTypesModel {
|
||||
controller: __controller
|
||||
}
|
||||
textRole: "name"
|
||||
valueRole: "id"
|
||||
currentIndex: listView.currentData ? deviceTypeCombobox.indexOfValue(listView.currentData.deviceTypeId) : -1
|
||||
|
@ -22,11 +22,6 @@ ApplicationWindow {
|
||||
property int masterWhite
|
||||
property int masterStrobo
|
||||
|
||||
DeviceTypesModel {
|
||||
id: deviceTypesModel
|
||||
controller: __controller
|
||||
}
|
||||
|
||||
DevicesModel {
|
||||
id: devicesModel
|
||||
controller: __controller
|
||||
|
@ -15,7 +15,29 @@ void DeviceTypesModel::setController(DmxController *controller)
|
||||
return;
|
||||
|
||||
beginResetModel();
|
||||
|
||||
if (m_controller)
|
||||
{
|
||||
disconnect(m_controller, &DmxController::deviceTypeInserted,
|
||||
this, &DeviceTypesModel::otherDeviceTypeInserted);
|
||||
disconnect(m_controller, &DmxController::deviceTypeRemoved,
|
||||
this, &DeviceTypesModel::otherDeviceTypeRemoved);
|
||||
disconnect(m_controller, &DmxController::deviceTypeNameChanged,
|
||||
this, &DeviceTypesModel::otherDeviceTypeNameChanged);
|
||||
}
|
||||
|
||||
m_controller = controller;
|
||||
|
||||
if (m_controller)
|
||||
{
|
||||
connect(m_controller, &DmxController::deviceTypeInserted,
|
||||
this, &DeviceTypesModel::otherDeviceTypeInserted);
|
||||
connect(m_controller, &DmxController::deviceTypeRemoved,
|
||||
this, &DeviceTypesModel::otherDeviceTypeRemoved);
|
||||
connect(m_controller, &DmxController::deviceTypeNameChanged,
|
||||
this, &DeviceTypesModel::otherDeviceTypeNameChanged);
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
emit controllerChanged(m_controller);
|
||||
}
|
||||
@ -160,6 +182,13 @@ bool DeviceTypesModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
}
|
||||
deviceType.name = value.toString();
|
||||
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
|
||||
|
||||
disconnect(m_controller, &DmxController::deviceTypeNameChanged,
|
||||
this, &DeviceTypesModel::otherDeviceTypeNameChanged);
|
||||
emit m_controller->deviceTypeNameChanged(index.row(), deviceType.name);
|
||||
connect(m_controller, &DmxController::deviceTypeNameChanged,
|
||||
this, &DeviceTypesModel::otherDeviceTypeNameChanged);
|
||||
|
||||
return true;
|
||||
case IdRole:
|
||||
if (value.userType() != QMetaType::Int)
|
||||
@ -221,6 +250,12 @@ bool DeviceTypesModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
iter = deviceTypes.insert(iter, DeviceTypeConfig{ .id=id++, .name="<neu>" }) + 1;
|
||||
endInsertRows();
|
||||
|
||||
disconnect(m_controller, &DmxController::deviceTypeInserted,
|
||||
this, &DeviceTypesModel::otherDeviceTypeInserted);
|
||||
emit m_controller->deviceTypeInserted(row, row+count-1);
|
||||
connect(m_controller, &DmxController::deviceTypeInserted,
|
||||
this, &DeviceTypesModel::otherDeviceTypeInserted);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -264,9 +299,51 @@ bool DeviceTypesModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
deviceTypes.erase(begin, end);
|
||||
endRemoveRows();
|
||||
|
||||
disconnect(m_controller, &DmxController::deviceTypeRemoved,
|
||||
this, &DeviceTypesModel::otherDeviceTypeRemoved);
|
||||
emit m_controller->deviceTypeRemoved(row, row+count-1);
|
||||
connect(m_controller, &DmxController::deviceTypeRemoved,
|
||||
this, &DeviceTypesModel::otherDeviceTypeRemoved);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeviceTypesModel::otherDeviceTypeInserted(int first, int last)
|
||||
{
|
||||
if (!m_controller)
|
||||
{
|
||||
qWarning() << "hilfe" << __LINE__;
|
||||
return;
|
||||
}
|
||||
|
||||
beginInsertRows({}, first, last);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void DeviceTypesModel::otherDeviceTypeRemoved(int first, int last)
|
||||
{
|
||||
if (!m_controller)
|
||||
{
|
||||
qWarning() << "hilfe" << __LINE__;
|
||||
return;
|
||||
}
|
||||
|
||||
beginRemoveRows({}, first, last);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void DeviceTypesModel::otherDeviceTypeNameChanged(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 registerDenShit()
|
||||
{
|
||||
|
@ -28,6 +28,11 @@ public:
|
||||
signals:
|
||||
void controllerChanged(DmxController *controller);
|
||||
|
||||
private slots:
|
||||
void otherDeviceTypeInserted(int first, int last);
|
||||
void otherDeviceTypeRemoved(int first, int last);
|
||||
void otherDeviceTypeNameChanged(int row, const QString &name);
|
||||
|
||||
private:
|
||||
DmxController *m_controller{};
|
||||
};
|
||||
|
@ -30,6 +30,11 @@ public:
|
||||
signals:
|
||||
void performanceChanged(int performance);
|
||||
|
||||
void deviceTypeInserted(int first, int last);
|
||||
void deviceTypeRemoved(int first, int last);
|
||||
void deviceTypeNameChanged(int index, const QString &name);
|
||||
void deviceTypeIconNameChanged(int index, const QString &iconName);
|
||||
|
||||
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);
|
||||
|
Reference in New Issue
Block a user