Commit 3f283dbc authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.dragAndDrop: properly add imports

Imports have to be added before transaction starts.
parent 27241430
......@@ -235,10 +235,36 @@ void DragTool::dropEvent(QGraphicsSceneDragDropEvent * event)
}
}
static ItemLibraryEntry itemLibraryEntryFromData(const QByteArray &data)
{
QDataStream stream(data);
ItemLibraryEntry itemLibraryEntry;
stream >> itemLibraryEntry;
return itemLibraryEntry;
}
void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
{
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) {
Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty());
ItemLibraryEntry itemLibraryEntry = itemLibraryEntryFromData(event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo"));
if (!itemLibraryEntry.requiredImport().isEmpty()) {
const QString newImportUrl = itemLibraryEntry.requiredImport();
const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion()));
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
if (!view()->model()->imports().contains(newImport)) {
view()->model()->addImport(newImport);
}
}
}
if (!m_rewriterTransaction.isValid()) {
view()->clearSelectedModelNodes();
m_rewriterTransaction = view()->beginRewriterTransaction();
......@@ -268,16 +294,6 @@ void DragTool::dragLeaveEvent(QGraphicsSceneDragDropEvent * event)
}
}
static ItemLibraryEntry itemLibraryEntryFromData(const QByteArray &data)
{
QDataStream stream(data);
ItemLibraryEntry itemLibraryEntry;
stream >> itemLibraryEntry;
return itemLibraryEntry;
}
void DragTool::dragMoveEvent(QGraphicsSceneDragDropEvent * event)
{
if (m_blockMove)
......
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