Commit f4520baf authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Refactor NavigatorTreeModel::mimeData

Change-Id: Icafc4deb2e879acbbc32bb6950256f8b3494ac10
Reviewed-by: default avatarMarco Bubke <marco.bubke@digia.com>
parent c5d6c754
......@@ -127,27 +127,32 @@ QStringList NavigatorTreeModel::mimeTypes() const
return types;
}
QMimeData *NavigatorTreeModel::mimeData(const QModelIndexList &indexList) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QSet<QModelIndex> rowAlreadyUsedSet;
QByteArray encodeModelNodes(const QModelIndexList &modelIndexList)
{
QByteArray encodedModelNodeData;
QDataStream encodedModelNodeDataStream(&encodedModelNodeData, QIODevice::WriteOnly);
QSet<QModelIndex> rowAlreadyUsedSet;
foreach (const QModelIndex &modelIndex, modelIndexList) {
if (modelIndex.isValid()) {
QModelIndex idModelIndex = modelIndex.sibling(modelIndex.row(), 0);
if (!rowAlreadyUsedSet.contains(idModelIndex)) {
rowAlreadyUsedSet.insert(idModelIndex);
encodedModelNodeDataStream << idModelIndex.data(NavigatorTreeModel::InternalIdRole).toInt();
}
}
}
QDataStream stream(&encodedData, QIODevice::WriteOnly);
return encodedModelNodeData;
}
foreach (const QModelIndex &index, indexList) {
if (!index.isValid())
continue;
QModelIndex idIndex = index.sibling(index.row(), 0);
if (rowAlreadyUsedSet.contains(idIndex))
continue;
QMimeData *NavigatorTreeModel::mimeData(const QModelIndexList &modelIndexList) const
{
QMimeData *mimeData = new QMimeData();
rowAlreadyUsedSet.insert(idIndex);
stream << idIndex.data(InternalIdRole).toInt();
}
QByteArray encodedModelNodeData = encodeModelNodes(modelIndexList);
mimeData->setData("application/vnd.modelnode.list", encodedData);
mimeData->setData("application/vnd.modelnode.list", encodedModelNodeData);
return mimeData;
}
......
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