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
...@@ -264,11 +264,15 @@ QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const ...@@ -264,11 +264,15 @@ QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const
QDataStream stream(&encoded, QIODevice::WriteOnly); QDataStream stream(&encoded, QIODevice::WriteOnly);
stream << indexes.size(); 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) { for (int i = 0; i < indexes.size(); ++i) {
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(indexes.at(i))); QModelIndex index = indexes.at(i);
stream << (quint64)item;
QList<int> rowPath;
for (QModelIndex i = index; i.isValid(); i = i.parent()) {
rowPath.prepend(i.row());
}
stream << rowPath;
} }
data->setData(format, encoded); data->setData(format, encoded);
return data; return data;
...@@ -302,14 +306,23 @@ bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action, ...@@ -302,14 +306,23 @@ bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
stream >> indexSize; stream >> indexSize;
QList<QmlOutlineItem*> itemsToMove; QList<QmlOutlineItem*> itemsToMove;
for (int i = 0; i < indexSize; ++i) { for (int i = 0; i < indexSize; ++i) {
quint64 itemPtr; QList<int> rowPath;
stream >> itemPtr; stream >> rowPath;
itemsToMove << reinterpret_cast<QmlOutlineItem*>(itemPtr);
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)); QmlOutlineItem *targetItem = static_cast<QmlOutlineItem*>(itemFromIndex(parent));
reparentNodes(targetItem, row, itemsToMove); 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; return false;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment