mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-23 21:21:08 -05:00
Clean up group deletion.
This commit is contained in:
parent
cc8d6424e2
commit
5dc21a191b
@ -35,22 +35,22 @@ Group::Group()
|
|||||||
m_searchingEnabled = Inherit;
|
m_searchingEnabled = Inherit;
|
||||||
|
|
||||||
m_updateTimeinfo = true;
|
m_updateTimeinfo = true;
|
||||||
m_emitSignals = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Group::~Group()
|
Group::~Group()
|
||||||
{
|
{
|
||||||
cleanupParent();
|
cleanupParent();
|
||||||
m_emitSignals = false;
|
this->blockSignals(true);
|
||||||
if (m_db && m_parent) {
|
if (m_db && m_parent) {
|
||||||
|
|
||||||
QList<Entry*> entries = m_entries;
|
QList<Entry*> entries = m_entries;
|
||||||
Q_FOREACH (Entry* entry, entries) {
|
Q_FOREACH (Entry* entry, entries) {
|
||||||
|
entry->blockSignals(true);
|
||||||
delete entry;
|
delete entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Group*> children = m_children;
|
QList<Group*> children = m_children;
|
||||||
Q_FOREACH (Group* group, children) {
|
Q_FOREACH (Group* group, children) {
|
||||||
|
group->blockSignals(true);
|
||||||
delete group;
|
delete group;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,11 +85,6 @@ void Group::setUpdateTimeinfo(bool value) {
|
|||||||
m_updateTimeinfo = value;
|
m_updateTimeinfo = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Group::emitSignals()
|
|
||||||
{
|
|
||||||
return m_emitSignals;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uuid Group::uuid() const
|
Uuid Group::uuid() const
|
||||||
{
|
{
|
||||||
return m_uuid;
|
return m_uuid;
|
||||||
@ -367,19 +362,15 @@ void Group::addEntry(Entry *entry)
|
|||||||
|
|
||||||
void Group::removeEntry(Entry* entry)
|
void Group::removeEntry(Entry* entry)
|
||||||
{
|
{
|
||||||
if (m_emitSignals) {
|
Q_EMIT entryAboutToRemove(entry);
|
||||||
Q_EMIT entryAboutToRemove(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
entry->disconnect(this);
|
entry->disconnect(this);
|
||||||
if (m_db) {
|
if (m_db) {
|
||||||
entry->disconnect(m_db);
|
entry->disconnect(m_db);
|
||||||
}
|
}
|
||||||
m_entries.removeAll(entry);
|
m_entries.removeAll(entry);
|
||||||
if (m_emitSignals) {
|
Q_EMIT modified();
|
||||||
Q_EMIT modified();
|
Q_EMIT entryRemoved();
|
||||||
Q_EMIT entryRemoved();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Group::recSetDatabase(Database* db)
|
void Group::recSetDatabase(Database* db)
|
||||||
@ -417,14 +408,10 @@ void Group::recSetDatabase(Database* db)
|
|||||||
void Group::cleanupParent()
|
void Group::cleanupParent()
|
||||||
{
|
{
|
||||||
if (m_parent) {
|
if (m_parent) {
|
||||||
if (m_parent->emitSignals()) {
|
Q_EMIT aboutToRemove(this);
|
||||||
Q_EMIT aboutToRemove(this);
|
|
||||||
}
|
|
||||||
m_parent->m_children.removeAll(this);
|
m_parent->m_children.removeAll(this);
|
||||||
if (m_parent->emitSignals()) {
|
Q_EMIT modified();
|
||||||
Q_EMIT modified();
|
Q_EMIT removed();
|
||||||
Q_EMIT removed();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ public:
|
|||||||
QList<Entry*> entries();
|
QList<Entry*> entries();
|
||||||
const QList<Entry*>& entries() const;
|
const QList<Entry*>& entries() const;
|
||||||
QList<Entry*> entriesRecursive(bool includeHistoryItems = false);
|
QList<Entry*> entriesRecursive(bool includeHistoryItems = false);
|
||||||
bool emitSignals();
|
|
||||||
void addDeletedObject(const DeletedObject& delObj);
|
void addDeletedObject(const DeletedObject& delObj);
|
||||||
|
|
||||||
|
|
||||||
@ -126,7 +125,6 @@ private:
|
|||||||
QPixmapCache::Key m_pixmapCacheKey;
|
QPixmapCache::Key m_pixmapCacheKey;
|
||||||
|
|
||||||
bool m_updateTimeinfo;
|
bool m_updateTimeinfo;
|
||||||
bool m_emitSignals;
|
|
||||||
|
|
||||||
friend void Database::setRootGroup(Group* group);
|
friend void Database::setRootGroup(Group* group);
|
||||||
friend Entry::~Entry();
|
friend Entry::~Entry();
|
||||||
|
@ -175,6 +175,20 @@ void TestGroup::testDeleteSignals()
|
|||||||
QCOMPARE(spyEntryAboutToRemove.count(), 1);
|
QCOMPARE(spyEntryAboutToRemove.count(), 1);
|
||||||
QCOMPARE(spyEntryRemoved.count(), 1);
|
QCOMPARE(spyEntryRemoved.count(), 1);
|
||||||
delete group;
|
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)
|
KEEPASSX_QTEST_CORE_MAIN(TestGroup)
|
||||||
|
Loading…
Reference in New Issue
Block a user