QmlDesigner: Allow dropping bundle materials to Navigator

Fixes: QDS-7844
Change-Id: If3c58f82797beabe76baf99ea2dddc59032729df
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2022-09-30 14:44:42 +03:00
parent 5da5830fa7
commit 395e40b8f3
5 changed files with 24 additions and 4 deletions

View File

@@ -481,7 +481,6 @@ void MaterialBrowserView::customNotification(const AbstractView *view, const QSt
} else if (identifier == "drop_bundle_material") {
m_bundleMaterialDropTarget = nodeList.first();
ModelNode defaultMat = getBundleMaterialDefaultInstance(m_draggedBundleMaterial->type());
if (defaultMat.isValid())
applyBundleMaterialToDropTarget(defaultMat);

View File

@@ -132,12 +132,15 @@ bool MaterialBrowserWidget::eventFilter(QObject *obj, QEvent *event)
} else if (m_bundleMaterialToDrag != nullptr) {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if ((me->globalPos() - m_dragStartPoint).manhattanLength() > 20) {
QByteArray data;
QMimeData *mimeData = new QMimeData;
mimeData->setData(Constants::MIME_TYPE_BUNDLE_MATERIAL, {});
QDataStream stream(&data, QIODevice::WriteOnly);
stream << m_bundleMaterialToDrag->type();
mimeData->setData(Constants::MIME_TYPE_BUNDLE_MATERIAL, data);
mimeData->removeFormat("text/plain");
model->startDrag(mimeData, m_bundleMaterialToDrag->icon().toLocalFile());
emit bundleMaterialDragStarted(m_bundleMaterialToDrag);
model->startDrag(mimeData, m_bundleMaterialToDrag->icon().toLocalFile());
m_bundleMaterialToDrag = {};
}
}

View File

@@ -58,6 +58,8 @@ ChooseFromPropertyListFilter::ChooseFromPropertyListFilter(const NodeMetaInfo &i
// -> Attractor3D
// Material
// -> Model
// BundleMaterial
// -> Model
const TypeName textureType = "QtQuick3D.Texture";
if (insertInfo.isSubclassOf(textureType)) {
@@ -107,7 +109,10 @@ ChooseFromPropertyListFilter::ChooseFromPropertyListFilter(const NodeMetaInfo &i
|| parentInfo.isSubclassOf("QtQuick3D.Particles3D.Attractor3D"))
propertyList.append("shape");
} else if (insertInfo.isSubclassOf("QtQuick3D.Material")) {
if (parentInfo.isSubclassOf("QtQuick3D.Particles3D.Model"))
if (parentInfo.isSubclassOf("QtQuick3D.Model"))
propertyList.append("materials");
} else if (insertInfo.typeName().startsWith("ComponentBundles.MaterialBundle")) {
if (parentInfo.isSubclassOf("QtQuick3D.Model"))
propertyList.append("materials");
}
}

View File

@@ -465,6 +465,7 @@ QStringList NavigatorTreeModel::mimeTypes() const
const static QStringList types({Constants::MIME_TYPE_MODELNODE_LIST,
Constants::MIME_TYPE_ITEM_LIBRARY_INFO,
Constants::MIME_TYPE_MATERIAL,
Constants::MIME_TYPE_BUNDLE_MATERIAL,
Constants::MIME_TYPE_ASSETS});
return types;
@@ -562,6 +563,10 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *mimeData,
handleItemLibraryItemDrop(mimeData, rowNumber, dropModelIndex);
} else if (mimeData->hasFormat(Constants::MIME_TYPE_MATERIAL)) {
handleMaterialDrop(mimeData, rowNumber, dropModelIndex);
} else if (mimeData->hasFormat(Constants::MIME_TYPE_BUNDLE_MATERIAL)) {
ModelNode targetNode(modelNodeForIndex(dropModelIndex));
if (targetNode.isValid())
m_view->emitCustomNotification("drop_bundle_material", {targetNode}); // To MaterialBrowserView
} else if (mimeData->hasFormat(Constants::MIME_TYPE_ASSETS)) {
const QStringList assetsPaths = QString::fromUtf8(mimeData->data(Constants::MIME_TYPE_ASSETS)).split(',');
NodeAbstractProperty targetProperty;

View File

@@ -284,6 +284,14 @@ void NavigatorView::dragStarted(QMimeData *mimeData)
m_widget->setDragType(matNode.metaInfo().typeName());
m_widget->update();
} else if (mimeData->hasFormat(Constants::MIME_TYPE_BUNDLE_MATERIAL)) {
QByteArray data = mimeData->data(Constants::MIME_TYPE_BUNDLE_MATERIAL);
QDataStream stream(data);
TypeName bundleMatType;
stream >> bundleMatType;
m_widget->setDragType(bundleMatType);
m_widget->update();
}
}