Update the right index when removing.

This commit is contained in:
Adam Treat 2023-05-02 11:26:21 -04:00
parent f13f4f4700
commit f4f27fc38f

View File

@ -99,7 +99,9 @@ public:
Q_ASSERT(nextChat);
setCurrentChat(nextChat);
}
beginRemoveRows(QModelIndex(), index, index);
const int newIndex = m_chats.indexOf(chat);
beginRemoveRows(QModelIndex(), newIndex, newIndex);
m_chats.removeAll(chat);
endRemoveRows();
delete chat;
@ -167,6 +169,15 @@ private Q_SLOTS:
emit dataChanged(index, index, {NameRole});
}
void printChats()
{
for (auto c : m_chats) {
qDebug() << c->name()
<< (c == m_currentChat ? "currentChat: true" : "currentChat: false")
<< (c == m_newChat ? "newChat: true" : "newChat: false");
}
}
private:
Chat* m_newChat;
Chat* m_currentChat;