mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Possibly fix crash when room is cleared on event delegate
This commit is contained in:
parent
7982c2bd75
commit
81cf29f924
1 changed files with 55 additions and 44 deletions
|
@ -162,10 +162,13 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj)
|
||||||
|
|
||||||
// setInitialProperties(rolesToSet);
|
// setInitialProperties(rolesToSet);
|
||||||
|
|
||||||
auto update =
|
auto update = [this, obj, roleToPropIdx = std::move(roleToPropIdx)](
|
||||||
[this, obj, roleToPropIdx = std::move(roleToPropIdx)](const QList<int> &changedRoles) {
|
const QList<int> &changedRoles, TimelineModel *room) {
|
||||||
|
if (!room)
|
||||||
|
return;
|
||||||
|
|
||||||
if (changedRoles.empty() || changedRoles.contains(TimelineModel::Roles::Type)) {
|
if (changedRoles.empty() || changedRoles.contains(TimelineModel::Roles::Type)) {
|
||||||
int type = chooser.room_
|
int type = room
|
||||||
->dataById(currentId,
|
->dataById(currentId,
|
||||||
TimelineModel::Roles::Type,
|
TimelineModel::Roles::Type,
|
||||||
forReply ? chooser.eventId_ : QString())
|
forReply ? chooser.eventId_ : QString())
|
||||||
|
@ -195,8 +198,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto mo = obj->metaObject();
|
auto mo = obj->metaObject();
|
||||||
chooser.room_->multiData(
|
room->multiData(currentId, forReply ? chooser.eventId_ : QString(), rolesToRequest);
|
||||||
currentId, forReply ? chooser.eventId_ : QString(), rolesToRequest);
|
|
||||||
|
|
||||||
Qt::beginPropertyUpdateGroup();
|
Qt::beginPropertyUpdateGroup();
|
||||||
for (const auto &role : rolesToRequest) {
|
for (const auto &role : rolesToRequest) {
|
||||||
|
@ -211,18 +213,27 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj)
|
||||||
chooser.room_,
|
chooser.room_,
|
||||||
&QAbstractItemModel::dataChanged,
|
&QAbstractItemModel::dataChanged,
|
||||||
obj,
|
obj,
|
||||||
[row, update](const QModelIndex &topLeft,
|
[row, update, room = chooser.room_](const QModelIndex &topLeft,
|
||||||
const QModelIndex &bottomRight,
|
const QModelIndex &bottomRight,
|
||||||
const QList<int> &changedRoles) {
|
const QList<int> &changedRoles) {
|
||||||
if (row < topLeft.row() || row > bottomRight.row())
|
if (row < topLeft.row() || row > bottomRight.row())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
update(changedRoles);
|
update(changedRoles, room);
|
||||||
},
|
},
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
connect(&this->chooser, &EventDelegateChooser::destroyed, obj, [connection]() {
|
connect(
|
||||||
QObject::disconnect(connection);
|
&this->chooser,
|
||||||
});
|
&EventDelegateChooser::destroyed,
|
||||||
|
obj,
|
||||||
|
[connection]() { QObject::disconnect(connection); },
|
||||||
|
Qt::SingleShotConnection);
|
||||||
|
connect(
|
||||||
|
&this->chooser,
|
||||||
|
&EventDelegateChooser::roomChanged,
|
||||||
|
obj,
|
||||||
|
[connection]() { QObject::disconnect(connection); },
|
||||||
|
Qt::SingleShotConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue