Don't add new entries to EntryModel when in search mode.

Only allow moving entries from one group to the other.
This commit is contained in:
Felix Geyer 2012-07-21 18:19:40 +02:00
parent f6e1af30b3
commit 33b4cd8636
5 changed files with 21 additions and 11 deletions

View file

@ -452,7 +452,7 @@ void Group::addEntry(Entry* entry)
} }
Q_EMIT modified(); Q_EMIT modified();
Q_EMIT entryAdded(); Q_EMIT entryAdded(entry);
} }
void Group::removeEntry(Entry* entry) void Group::removeEntry(Entry* entry)
@ -467,7 +467,7 @@ void Group::removeEntry(Entry* entry)
} }
m_entries.removeAll(entry); m_entries.removeAll(entry);
Q_EMIT modified(); Q_EMIT modified();
Q_EMIT entryRemoved(); Q_EMIT entryRemoved(entry);
} }
void Group::recSetDatabase(Database* db) void Group::recSetDatabase(Database* db)

View file

@ -104,9 +104,9 @@ Q_SIGNALS:
void moved(); void moved();
void entryAboutToAdd(Entry* entry); void entryAboutToAdd(Entry* entry);
void entryAdded(); void entryAdded(Entry* entry);
void entryAboutToRemove(Entry* entry); void entryAboutToRemove(Entry* entry);
void entryRemoved(); void entryRemoved(Entry* entry);
void entryDataChanged(Entry* entry); void entryDataChanged(Entry* entry);

View file

@ -55,7 +55,9 @@ void EntryModel::setGroup(Group* group)
severConnections(); severConnections();
m_group = group; m_group = group;
m_allGroups.clear();
m_entries = group->entries(); m_entries = group->entries();
m_orgEntries.clear();
makeConnections(group); makeConnections(group);
@ -72,6 +74,7 @@ void EntryModel::setEntries(const QList<Entry*>& entries)
m_group = Q_NULLPTR; m_group = Q_NULLPTR;
m_allGroups.clear(); m_allGroups.clear();
m_entries = entries; m_entries = entries;
m_orgEntries = entries;
if (entries.count() > 0) { if (entries.count() > 0) {
m_allGroups = entries.at(0)->group()->database()->rootGroup()->groupsRecursive(true); 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) void EntryModel::entryAboutToAdd(Entry* entry)
{ {
Q_UNUSED(entry); if (!m_group && !m_orgEntries.contains(entry)) {
return;
}
beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size()); beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size());
if (!m_group) { 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) { if (m_group) {
m_entries = m_group->entries(); m_entries = m_group->entries();
} }
@ -268,8 +277,8 @@ void EntryModel::severConnections()
void EntryModel::makeConnections(const Group* group) void EntryModel::makeConnections(const Group* group)
{ {
connect(group, SIGNAL(entryAboutToAdd(Entry*)), SLOT(entryAboutToAdd(Entry*))); 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(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*))); connect(group, SIGNAL(entryDataChanged(Entry*)), SLOT(entryDataChanged(Entry*)));
} }

View file

@ -54,7 +54,7 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void entryAboutToAdd(Entry* entry); void entryAboutToAdd(Entry* entry);
void entryAdded(); void entryAdded(Entry* entry);
void entryAboutToRemove(Entry* entry); void entryAboutToRemove(Entry* entry);
void entryRemoved(); void entryRemoved();
void entryDataChanged(Entry* entry); void entryDataChanged(Entry* entry);
@ -65,6 +65,7 @@ private:
Group* m_group; Group* m_group;
QList<Entry*> m_entries; QList<Entry*> m_entries;
QList<Entry*> m_orgEntries;
QList<const Group*> m_allGroups; QList<const Group*> m_allGroups;
}; };

View file

@ -271,7 +271,7 @@ void TestGroup::testDeleteSignals()
Entry* entry = new Entry(); Entry* entry = new Entry();
entry->setGroup(group); entry->setGroup(group);
QSignalSpy spyEntryAboutToRemove(group, SIGNAL(entryAboutToRemove(Entry*))); QSignalSpy spyEntryAboutToRemove(group, SIGNAL(entryAboutToRemove(Entry*)));
QSignalSpy spyEntryRemoved(group, SIGNAL(entryRemoved())); QSignalSpy spyEntryRemoved(group, SIGNAL(entryRemoved(Entry*)));
delete entry; delete entry;
QVERIFY(group->entries().isEmpty()); QVERIFY(group->entries().isEmpty());
@ -286,7 +286,7 @@ void TestGroup::testDeleteSignals()
Entry* entry2 = new Entry(); Entry* entry2 = new Entry();
entry2->setGroup(group2); entry2->setGroup(group2);
QSignalSpy spyEntryAboutToRemove2(group2, SIGNAL(entryAboutToRemove(Entry*))); QSignalSpy spyEntryAboutToRemove2(group2, SIGNAL(entryAboutToRemove(Entry*)));
QSignalSpy spyEntryRemoved2(group2, SIGNAL(entryRemoved())); QSignalSpy spyEntryRemoved2(group2, SIGNAL(entryRemoved(Entry*)));
delete group2; delete group2;
QCOMPARE(spyEntryAboutToRemove2.count(), 0); QCOMPARE(spyEntryAboutToRemove2.count(), 0);