QmlDesigner: Detect asset drag'n'drop support based on property type

Handle property support for asset drag based on property type rather
than name in order to support properties with any name
(like lightProbe).

Change-Id: I20fd422119db96aebd505b47888c97f0d94bf7f9
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2022-06-07 21:19:44 +03:00
parent 221376aa38
commit 568004e121
2 changed files with 9 additions and 3 deletions

View File

@@ -767,11 +767,16 @@ void MaterialEditorView::customNotification(const AbstractView *view, const QStr
void QmlDesigner::MaterialEditorView::highlightSupportedProperties(bool highlight) void QmlDesigner::MaterialEditorView::highlightSupportedProperties(bool highlight)
{ {
if (!m_selectedMaterial.isValid())
return;
DesignerPropertyMap &propMap = m_qmlBackEnd->backendValuesPropertyMap(); DesignerPropertyMap &propMap = m_qmlBackEnd->backendValuesPropertyMap();
const QStringList propNames = propMap.keys(); const QStringList propNames = propMap.keys();
NodeMetaInfo metaInfo = m_selectedMaterial.metaInfo();
QTC_ASSERT(metaInfo.isValid(), return);
for (const QString &propName : propNames) { for (const QString &propName : propNames) {
if (propName.endsWith("Map")) { if (metaInfo.propertyTypeName(propName.toLatin1()) == "QtQuick3D.Texture") {
QObject *propEditorValObj = propMap.value(propName).value<QObject *>(); QObject *propEditorValObj = propMap.value(propName).value<QObject *>();
PropertyEditorValue *propEditorVal = qobject_cast<PropertyEditorValue *>(propEditorValObj); PropertyEditorValue *propEditorVal = qobject_cast<PropertyEditorValue *>(propEditorValObj);
propEditorVal->setHasActiveDrag(highlight); propEditorVal->setHasActiveDrag(highlight);

View File

@@ -518,14 +518,15 @@ bool PropertyEditorValue::idListReplace(int idx, const QString &value)
void PropertyEditorValue::commitDrop(const QString &path) void PropertyEditorValue::commitDrop(const QString &path)
{ {
if (m_modelNode.isSubclassOf("QtQuick3D.Material") && nameAsQString().endsWith("Map")) { if (m_modelNode.isSubclassOf("QtQuick3D.Material")
&& m_modelNode.metaInfo().propertyTypeName(m_name) == "QtQuick3D.Texture") {
// create a texture node // create a texture node
QmlDesigner::NodeMetaInfo metaInfo = m_modelNode.view()->model()->metaInfo("QtQuick3D.Texture"); QmlDesigner::NodeMetaInfo metaInfo = m_modelNode.view()->model()->metaInfo("QtQuick3D.Texture");
QmlDesigner::ModelNode texture = m_modelNode.view()->createModelNode("QtQuick3D.Texture", QmlDesigner::ModelNode texture = m_modelNode.view()->createModelNode("QtQuick3D.Texture",
metaInfo.majorVersion(), metaInfo.majorVersion(),
metaInfo.minorVersion()); metaInfo.minorVersion());
texture.validId(); texture.validId();
modelNode().view()->rootModelNode().defaultNodeListProperty().reparentHere(texture); m_modelNode.view()->rootModelNode().defaultNodeListProperty().reparentHere(texture);
// TODO: group textures under 1 node (just like materials) // TODO: group textures under 1 node (just like materials)
// set texture source // set texture source