From 7a1c1a373a08e777c2c1108be08a129e8aff1ecc Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Mon, 9 Aug 2010 17:41:22 +0200
Subject: [PATCH] QmlOutline: Store relative path instead of pointer in
 mimetype

Don't store pointers in the drag document, but the path to the item.
---
 src/plugins/qmljseditor/qmloutlinemodel.cpp | 29 +++++++++++++++------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp
index 92bec0cee7a..81919094bac 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.cpp
+++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp
@@ -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;
 }
 
-- 
GitLab