SpaceChildrenModel: Handle space being deleted
This commit is contained in:
@@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
SpaceChildrenModel::SpaceChildrenModel(QObject *parent)
|
SpaceChildrenModel::SpaceChildrenModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
|
, m_rootItem(new SpaceTreeItem(nullptr))
|
||||||
{
|
{
|
||||||
m_rootItem = new SpaceTreeItem(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpaceChildrenModel::~SpaceChildrenModel()
|
SpaceChildrenModel::~SpaceChildrenModel()
|
||||||
@@ -40,6 +40,12 @@ void SpaceChildrenModel::setSpace(NeoChatRoom *space)
|
|||||||
m_space = space;
|
m_space = space;
|
||||||
Q_EMIT spaceChanged();
|
Q_EMIT spaceChanged();
|
||||||
|
|
||||||
|
refreshModel();
|
||||||
|
|
||||||
|
if (!m_space) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto connection = m_space->connection();
|
auto connection = m_space->connection();
|
||||||
connect(connection, &Quotient::Connection::loadedRoomState, this, [this](Quotient::Room *room) {
|
connect(connection, &Quotient::Connection::loadedRoomState, this, [this](Quotient::Room *room) {
|
||||||
if (m_pendingChildren.contains(room->name())) {
|
if (m_pendingChildren.contains(room->name())) {
|
||||||
@@ -50,8 +56,6 @@ void SpaceChildrenModel::setSpace(NeoChatRoom *space)
|
|||||||
connect(m_space, &Quotient::Room::changed, this, [this]() {
|
connect(m_space, &Quotient::Room::changed, this, [this]() {
|
||||||
refreshModel();
|
refreshModel();
|
||||||
});
|
});
|
||||||
|
|
||||||
refreshModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpaceChildrenModel::loading() const
|
bool SpaceChildrenModel::loading() const
|
||||||
@@ -69,6 +73,10 @@ void SpaceChildrenModel::refreshModel()
|
|||||||
m_currentJobs.clear();
|
m_currentJobs.clear();
|
||||||
|
|
||||||
if (m_space == nullptr) {
|
if (m_space == nullptr) {
|
||||||
|
beginResetModel();
|
||||||
|
delete m_rootItem;
|
||||||
|
m_rootItem = nullptr;
|
||||||
|
endResetModel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ Q_SIGNALS:
|
|||||||
void loadingChanged();
|
void loadingChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NeoChatRoom *m_space = nullptr;
|
QPointer<NeoChatRoom> m_space;
|
||||||
SpaceTreeItem *m_rootItem;
|
SpaceTreeItem *m_rootItem;
|
||||||
|
|
||||||
bool m_loading = false;
|
bool m_loading = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user