Fix popping the page stack when things are deleted

This commit is contained in:
Michael Zanetti 2020-04-11 12:31:26 +02:00
parent 8a256d9bbb
commit 7dd59dd90f
3 changed files with 15 additions and 1 deletions

View File

@ -117,6 +117,7 @@ void Devices::addDevice(Device *device)
emit dataChanged(index(idx), index(idx)); emit dataChanged(index(idx), index(idx));
}); });
emit countChanged(); emit countChanged();
emit thingAdded(device);
} }
void Devices::removeDevice(Device *device) void Devices::removeDevice(Device *device)
@ -124,9 +125,10 @@ void Devices::removeDevice(Device *device)
int index = m_devices.indexOf(device); int index = m_devices.indexOf(device);
beginRemoveRows(QModelIndex(), index, index); beginRemoveRows(QModelIndex(), index, index);
qDebug() << "Devices: removed device" << device->name(); qDebug() << "Devices: removed device" << device->name();
m_devices.removeAt(index); m_devices.takeAt(index)->deleteLater();
endRemoveRows(); endRemoveRows();
emit countChanged(); emit countChanged();
emit thingRemoved(device);
} }
void Devices::clearModel() void Devices::clearModel()

View File

@ -73,6 +73,8 @@ protected:
signals: signals:
void countChanged(); void countChanged();
void thingAdded(Device *device);
void thingRemoved(Device *device);
private: private:
QList<Device *> m_devices; QList<Device *> m_devices;

View File

@ -144,6 +144,16 @@ Page {
} }
} }
Connections {
target: engine.deviceManager.devices
onThingRemoved:{
if (device == root.device) {
print("Device destroyed")
pageStack.pop()
}
}
}
Component { Component {
id: addToGroupDialog id: addToGroupDialog
MeaDialog { MeaDialog {