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