From 37e5b6ce8ba572b0f6e3dc067b7f7c99963515b7 Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 30 Oct 2018 23:17:38 +0100 Subject: [PATCH] fix:(chatform): Issue 5115, use QSharedPointer for groupChatForms --- src/widget/widget.cpp | 17 ++++++----------- src/widget/widget.h | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index fd3e414ee..f1ad61848 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -525,10 +525,6 @@ Widget::~Widget() delete form; } - for (auto form : groupChatForms) { - delete form; - } - delete icon; delete profileForm; delete profileInfo; @@ -1155,7 +1151,7 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow) form = chatForms[id]; } else { id = group->getId(); - form = groupChatForms[id]; + form = groupChatForms[id].data(); } bool chatFormIsSet; @@ -1303,7 +1299,7 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog) onAddClicked(); } - auto chatForm = groupChatForms[groupId]; + auto chatForm = groupChatForms[groupId].data(); auto chatroom = groupChatrooms[groupId]; auto groupWidget = dialog->addGroup(chatroom, chatForm); #if (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) @@ -1749,7 +1745,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri const auto targeted = !isSelf && mention; const auto groupId = g->getId(); const auto date = QDateTime::currentDateTime(); - auto form = groupChatForms[groupId]; + auto form = groupChatForms[groupId].data(); if (targeted && !isAction) { form->addAlertMessage(author, message, date, true); @@ -1816,7 +1812,7 @@ void Widget::onGroupPeerAudioPlaying(int groupnumber, int peernumber) return; } - auto form = groupChatForms[g->getId()]; + auto form = groupChatForms[g->getId()].data(); // TODO(sudden6): switch to ToxPk here form->peerAudioPlaying(g->resolvePeerId(peernumber)); } @@ -1851,7 +1847,6 @@ void Widget::removeGroup(Group* g, bool fake) qWarning() << "Tried to remove group" << groupId << "but GroupChatForm doesn't exist"; return; } - delete groupChatFormIt.value(); groupChatForms.erase(groupChatFormIt); delete g; if (contentLayout && contentLayout->mainHead->layout()->isEmpty()) { @@ -1885,7 +1880,7 @@ Group* Widget::createGroup(int groupId) auto form = new GroupChatForm(newgroup); groupWidgets[groupId] = widget; groupChatrooms[groupId] = chatroom; - groupChatForms[groupId] = form; + groupChatForms[groupId] = QSharedPointer(form); contactListWidget->addGroupWidget(widget); widget->updateStatusLight(); @@ -2091,7 +2086,7 @@ void Widget::onGroupSendFailed(int groupId) const auto message = tr("Message failed to send"); const auto curTime = QDateTime::currentDateTime(); - auto form = groupChatForms[g->getId()]; + auto form = groupChatForms[g->getId()].data(); form->addSystemInfoMessage(message, ChatMessage::INFO, curTime); } diff --git a/src/widget/widget.h b/src/widget/widget.h index d90815b48..8db6c6611 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -310,7 +310,7 @@ private: QMap groupWidgets; QMap> groupChatrooms; - QMap groupChatForms; + QMap> groupChatForms; #ifdef Q_OS_MAC QAction* fileMenu;