diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp index 92bec0cee7a2aed7637225f4f21fdb6d1aa50de1..81919094bac880f300e51847b5d427fd5156deff 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; }