diff --git a/src/core/Group.cpp b/src/core/Group.cpp index e867a45bb..0f154c027 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -452,7 +452,7 @@ void Group::addEntry(Entry* entry) } Q_EMIT modified(); - Q_EMIT entryAdded(); + Q_EMIT entryAdded(entry); } void Group::removeEntry(Entry* entry) @@ -467,7 +467,7 @@ void Group::removeEntry(Entry* entry) } m_entries.removeAll(entry); Q_EMIT modified(); - Q_EMIT entryRemoved(); + Q_EMIT entryRemoved(entry); } void Group::recSetDatabase(Database* db) diff --git a/src/core/Group.h b/src/core/Group.h index 2ce447b74..1ca543d91 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -104,9 +104,9 @@ Q_SIGNALS: void moved(); void entryAboutToAdd(Entry* entry); - void entryAdded(); + void entryAdded(Entry* entry); void entryAboutToRemove(Entry* entry); - void entryRemoved(); + void entryRemoved(Entry* entry); void entryDataChanged(Entry* entry); diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index c71e19638..a4452d68b 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -55,7 +55,9 @@ void EntryModel::setGroup(Group* group) severConnections(); m_group = group; + m_allGroups.clear(); m_entries = group->entries(); + m_orgEntries.clear(); makeConnections(group); @@ -72,6 +74,7 @@ void EntryModel::setEntries(const QList& entries) m_group = Q_NULLPTR; m_allGroups.clear(); m_entries = entries; + m_orgEntries = entries; if (entries.count() > 0) { m_allGroups = entries.at(0)->group()->database()->rootGroup()->groupsRecursive(true); @@ -215,7 +218,9 @@ QMimeData* EntryModel::mimeData(const QModelIndexList& indexes) const void EntryModel::entryAboutToAdd(Entry* entry) { - Q_UNUSED(entry); + if (!m_group && !m_orgEntries.contains(entry)) { + return; + } beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size()); if (!m_group) { @@ -223,8 +228,12 @@ void EntryModel::entryAboutToAdd(Entry* entry) } } -void EntryModel::entryAdded() +void EntryModel::entryAdded(Entry* entry) { + if (!m_group && !m_orgEntries.contains(entry)) { + return; + } + if (m_group) { m_entries = m_group->entries(); } @@ -268,8 +277,8 @@ void EntryModel::severConnections() void EntryModel::makeConnections(const Group* group) { connect(group, SIGNAL(entryAboutToAdd(Entry*)), SLOT(entryAboutToAdd(Entry*))); - connect(group, SIGNAL(entryAdded()), SLOT(entryAdded())); + connect(group, SIGNAL(entryAdded(Entry*)), SLOT(entryAdded(Entry*))); connect(group, SIGNAL(entryAboutToRemove(Entry*)), SLOT(entryAboutToRemove(Entry*))); - connect(group, SIGNAL(entryRemoved()), SLOT(entryRemoved())); + connect(group, SIGNAL(entryRemoved(Entry*)), SLOT(entryRemoved())); connect(group, SIGNAL(entryDataChanged(Entry*)), SLOT(entryDataChanged(Entry*))); } diff --git a/src/gui/entry/EntryModel.h b/src/gui/entry/EntryModel.h index 4c718897d..a5edcddb0 100644 --- a/src/gui/entry/EntryModel.h +++ b/src/gui/entry/EntryModel.h @@ -54,7 +54,7 @@ public Q_SLOTS: private Q_SLOTS: void entryAboutToAdd(Entry* entry); - void entryAdded(); + void entryAdded(Entry* entry); void entryAboutToRemove(Entry* entry); void entryRemoved(); void entryDataChanged(Entry* entry); @@ -65,6 +65,7 @@ private: Group* m_group; QList m_entries; + QList m_orgEntries; QList m_allGroups; }; diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 8a92b3701..a91b5a7b9 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -271,7 +271,7 @@ void TestGroup::testDeleteSignals() Entry* entry = new Entry(); entry->setGroup(group); QSignalSpy spyEntryAboutToRemove(group, SIGNAL(entryAboutToRemove(Entry*))); - QSignalSpy spyEntryRemoved(group, SIGNAL(entryRemoved())); + QSignalSpy spyEntryRemoved(group, SIGNAL(entryRemoved(Entry*))); delete entry; QVERIFY(group->entries().isEmpty()); @@ -286,7 +286,7 @@ void TestGroup::testDeleteSignals() Entry* entry2 = new Entry(); entry2->setGroup(group2); QSignalSpy spyEntryAboutToRemove2(group2, SIGNAL(entryAboutToRemove(Entry*))); - QSignalSpy spyEntryRemoved2(group2, SIGNAL(entryRemoved())); + QSignalSpy spyEntryRemoved2(group2, SIGNAL(entryRemoved(Entry*))); delete group2; QCOMPARE(spyEntryAboutToRemove2.count(), 0);