Fix drag'n'drop of multiple entries.

Previously only the first entry was moved.
This commit is contained in:
Felix Geyer 2012-10-21 22:30:28 +02:00
parent 08415bd824
commit caec47b1e5

View file

@ -223,19 +223,21 @@ bool GroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action,
// decode and insert // decode and insert
QByteArray encoded = data->data(isGroup ? types.at(0) : types.at(1)); QByteArray encoded = data->data(isGroup ? types.at(0) : types.at(1));
QDataStream stream(&encoded, QIODevice::ReadOnly); QDataStream stream(&encoded, QIODevice::ReadOnly);
Group* parentGroup = groupFromIndex(parent);
if (isGroup) {
Uuid dbUuid; Uuid dbUuid;
Uuid itemUuid; Uuid groupUuid;
stream >> dbUuid >> itemUuid; stream >> dbUuid >> groupUuid;
Database* db = Database::databaseByUuid(dbUuid); Database* db = Database::databaseByUuid(dbUuid);
if (!db) { if (!db) {
return false; return false;
} }
Group* parentGroup = groupFromIndex(parent); Group* dragGroup = db->resolveGroup(groupUuid);
if (isGroup) {
Group* dragGroup = db->resolveGroup(itemUuid);
if (!dragGroup || !Tools::hasChild(db, dragGroup) || dragGroup == db->rootGroup()) { if (!dragGroup || !Tools::hasChild(db, dragGroup) || dragGroup == db->rootGroup()) {
return false; return false;
} }
@ -251,13 +253,28 @@ bool GroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action,
dragGroup->setParent(parentGroup, row); dragGroup->setParent(parentGroup, row);
} }
else { else {
Entry* dragEntry = db->resolveEntry(itemUuid); if (row != -1) {
if (!dragEntry || !Tools::hasChild(db, dragEntry) || row != -1) {
return false; return false;
} }
while (!stream.atEnd()) {
Uuid dbUuid;
Uuid entryUuid;
stream >> dbUuid >> entryUuid;
Database* db = Database::databaseByUuid(dbUuid);
if (!db) {
continue;
}
Entry* dragEntry = db->resolveEntry(entryUuid);
if (!dragEntry || !Tools::hasChild(db, dragEntry)) {
continue;
}
dragEntry->setGroup(parentGroup); dragEntry->setGroup(parentGroup);
} }
}
return true; return true;
} }