Make sure we don't add entries/groups multiple times to the drag'n'drop data.

This commit is contained in:
Felix Geyer 2013-04-07 11:47:50 +02:00
parent ef46b3e8ad
commit 91868969ca
2 changed files with 19 additions and 2 deletions

View File

@ -211,12 +211,20 @@ QMimeData* EntryModel::mimeData(const QModelIndexList& indexes) const
QByteArray encoded;
QDataStream stream(&encoded, QIODevice::WriteOnly);
QSet<Entry*> seenEntries;
for (int i = 0; i < indexes.size(); i++) {
if (!indexes[i].isValid()) {
continue;
}
Entry* entry = entryFromIndex(indexes[i]);
stream << entry->group()->database()->uuid() << entry->uuid();
if (!seenEntries.contains(entry)) {
// make sure we don't add entries multiple times when we get indexes
// with the same row but different columns
stream << entry->group()->database()->uuid() << entry->uuid();
seenEntries.insert(entry);
}
}
data->setData(mimeTypes().first(), encoded);

View File

@ -297,11 +297,20 @@ QMimeData* GroupModel::mimeData(const QModelIndexList& indexes) const
QByteArray encoded;
QDataStream stream(&encoded, QIODevice::WriteOnly);
QSet<Group*> seenGroups;
for (int i = 0; i < indexes.size(); i++) {
if (!indexes[i].isValid()) {
continue;
}
stream << m_db->uuid() << groupFromIndex(indexes[i])->uuid();
Group* group = groupFromIndex(indexes[i]);
if (!seenGroups.contains(group)) {
// make sure we don't add groups multiple times when we get indexes
// with the same row but different columns
stream << m_db->uuid() << group->uuid();
seenGroups.insert(group);
}
}
data->setData(mimeTypes().first(), encoded);