From 5dc21a191bd9fe49fb499c712d0fa3648784c41e Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sat, 21 Apr 2012 23:31:37 +0200 Subject: [PATCH] Clean up group deletion. --- src/core/Group.cpp | 31 +++++++++---------------------- src/core/Group.h | 2 -- tests/TestGroup.cpp | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 2887efa04..267670dd4 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -35,22 +35,22 @@ Group::Group() m_searchingEnabled = Inherit; m_updateTimeinfo = true; - m_emitSignals = true; } Group::~Group() { cleanupParent(); - m_emitSignals = false; + this->blockSignals(true); if (m_db && m_parent) { - QList entries = m_entries; Q_FOREACH (Entry* entry, entries) { + entry->blockSignals(true); delete entry; } QList children = m_children; Q_FOREACH (Group* group, children) { + group->blockSignals(true); delete group; } @@ -85,11 +85,6 @@ void Group::setUpdateTimeinfo(bool value) { m_updateTimeinfo = value; } -bool Group::emitSignals() -{ - return m_emitSignals; -} - Uuid Group::uuid() const { return m_uuid; @@ -367,19 +362,15 @@ void Group::addEntry(Entry *entry) void Group::removeEntry(Entry* entry) { - if (m_emitSignals) { - Q_EMIT entryAboutToRemove(entry); - } + Q_EMIT entryAboutToRemove(entry); entry->disconnect(this); if (m_db) { entry->disconnect(m_db); } m_entries.removeAll(entry); - if (m_emitSignals) { - Q_EMIT modified(); - Q_EMIT entryRemoved(); - } + Q_EMIT modified(); + Q_EMIT entryRemoved(); } void Group::recSetDatabase(Database* db) @@ -417,14 +408,10 @@ void Group::recSetDatabase(Database* db) void Group::cleanupParent() { if (m_parent) { - if (m_parent->emitSignals()) { - Q_EMIT aboutToRemove(this); - } + Q_EMIT aboutToRemove(this); m_parent->m_children.removeAll(this); - if (m_parent->emitSignals()) { - Q_EMIT modified(); - Q_EMIT removed(); - } + Q_EMIT modified(); + Q_EMIT removed(); } } diff --git a/src/core/Group.h b/src/core/Group.h index 04cd5fa3a..b3f2b6887 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -75,7 +75,6 @@ public: QList entries(); const QList& entries() const; QList entriesRecursive(bool includeHistoryItems = false); - bool emitSignals(); void addDeletedObject(const DeletedObject& delObj); @@ -126,7 +125,6 @@ private: QPixmapCache::Key m_pixmapCacheKey; bool m_updateTimeinfo; - bool m_emitSignals; friend void Database::setRootGroup(Group* group); friend Entry::~Entry(); diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 99ba60778..77adbf280 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -175,6 +175,20 @@ void TestGroup::testDeleteSignals() QCOMPARE(spyEntryAboutToRemove.count(), 1); QCOMPARE(spyEntryRemoved.count(), 1); delete group; + + Database* db2 = new Database(); + Group* groupRoot2 = db2->rootGroup(); + Group* group2 = new Group(); + group2->setParent(groupRoot2); + Entry* entry2 = new Entry(); + entry2->setGroup(group2); + QSignalSpy spyEntryAboutToRemove2(group2, SIGNAL(entryAboutToRemove(Entry*))); + QSignalSpy spyEntryRemoved2(group2, SIGNAL(entryRemoved())); + + delete group2; + QCOMPARE(spyEntryAboutToRemove2.count(), 0); + QCOMPARE(spyEntryRemoved2.count(), 0); + } KEEPASSX_QTEST_CORE_MAIN(TestGroup)