Skip to content
Snippets Groups Projects
Commit 7a1c1a37 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlOutline: Store relative path instead of pointer in mimetype

Don't store pointers in the drag document, but the path to the item.
parent 822de6c1
No related branches found
No related tags found
No related merge requests found
......@@ -264,11 +264,15 @@ QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const
QDataStream stream(&encoded, QIODevice::WriteOnly);
stream << indexes.size();
// We store pointers to the QmlOutlineItems dropped.
// This works because we're only supporting drag&drop inside the model
for (int i = 0; i < indexes.size(); ++i) {
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(indexes.at(i)));
stream << (quint64)item;
QModelIndex index = indexes.at(i);
QList<int> rowPath;
for (QModelIndex i = index; i.isValid(); i = i.parent()) {
rowPath.prepend(i.row());
}
stream << rowPath;
}
data->setData(format, encoded);
return data;
......@@ -302,14 +306,23 @@ bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
stream >> indexSize;
QList<QmlOutlineItem*> itemsToMove;
for (int i = 0; i < indexSize; ++i) {
quint64 itemPtr;
stream >> itemPtr;
itemsToMove << reinterpret_cast<QmlOutlineItem*>(itemPtr);
QList<int> rowPath;
stream >> rowPath;
QModelIndex index;
foreach (int row, rowPath) {
index = this->index(row, 0, index);
if (!index.isValid())
continue;
}
itemsToMove << static_cast<QmlOutlineItem*>(itemFromIndex(index));
}
QmlOutlineItem *targetItem = static_cast<QmlOutlineItem*>(itemFromIndex(parent));
reparentNodes(targetItem, row, itemsToMove);
// Prevent view from calling insertRow(), removeRow() on it's own
// Prevent view from calling removeRow() on it's own
return false;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment