From eaa363d8c032fc5513d4566d72f249a6e4e9d293 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Thu, 22 Sep 2022 08:40:23 -0400 Subject: Fix crash when deleting items in recycle bin while searching (#8117) * Fix #8099 * Clean up code that connects groups to the entry view. Instead of connecting ALL groups from ALL databases, we only need to connect the groups that entries actually belong to. This solves the bug and also reduces overhead. --- src/gui/entry/EntryModel.cpp | 20 ++++---------------- src/gui/entry/EntryModel.h | 3 ++- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index 2a125a881..97d671e58 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -85,25 +85,13 @@ void EntryModel::setEntries(const QList& entries) m_entries = entries; m_orgEntries = entries; - QSet databases; - - for (Entry* entry : asConst(m_entries)) { - databases.insert(entry->group()->database()); - } - - for (Database* db : asConst(databases)) { - Q_ASSERT(db); - const QList groupList = db->rootGroup()->groupsRecursive(true); - for (const Group* group : groupList) { - m_allGroups.append(group); - } - - if (db->metadata()->recycleBin()) { - m_allGroups.removeOne(db->metadata()->recycleBin()); + for (const auto entry : asConst(m_entries)) { + if (entry->group()) { + m_allGroups.insert(entry->group()); } } - for (const Group* group : asConst(m_allGroups)) { + for (const auto group : m_allGroups) { makeConnections(group); } diff --git a/src/gui/entry/EntryModel.h b/src/gui/entry/EntryModel.h index cd34da7d4..8e79be384 100644 --- a/src/gui/entry/EntryModel.h +++ b/src/gui/entry/EntryModel.h @@ -20,6 +20,7 @@ #include #include +#include #include "core/Config.h" @@ -87,7 +88,7 @@ private: Group* m_group; QList m_entries; QList m_orgEntries; - QList m_allGroups; + QSet m_allGroups; const QString HiddenContentDisplay; const Qt::DateFormat DateFormat; -- cgit v1.2.3