QmlDesigner: Reset puppet when material is added

This is workaround for material rendering issues in quick3d when a
material is shared by multiple windows.

Fixes: QDS-7096
Fixes: QDS-7118
Change-Id: I64fe2e51c5dda8e238502e5d926b6938b7b0731a
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-06-16 15:30:25 +03:00
parent 9c3636af49
commit 221376aa38
4 changed files with 26 additions and 8 deletions

View File

@@ -120,6 +120,11 @@ void MaterialBrowserModel::setHasModelSelection(bool b)
emit hasModelSelectionChanged();
}
QList<ModelNode> MaterialBrowserModel::materials() const
{
return m_materialList;
}
void MaterialBrowserModel::setSearchText(const QString &searchText)
{
QString lowerSearchText = searchText.toLower();

View File

@@ -58,6 +58,7 @@ public:
bool hasModelSelection() const;
void setHasModelSelection(bool b);
QList<ModelNode> materials() const;
void setMaterials(const QList<ModelNode> &materials, bool hasQuick3DImport);
void removeMaterial(const ModelNode &material);
void updateMaterialName(const ModelNode &material);

View File

@@ -97,10 +97,12 @@ void MaterialBrowserView::modelAttached(Model *model)
m_widget->clearSearchFilter();
m_hasQuick3DImport = model->hasImport("QtQuick3D");
QTimer::singleShot(0, this, &MaterialBrowserView::refreshModel);
QTimer::singleShot(0, this, [this]() {
refreshModel(true);
});
}
void MaterialBrowserView::refreshModel()
void MaterialBrowserView::refreshModel(bool updateImages)
{
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
QList <ModelNode> materials;
@@ -115,8 +117,10 @@ void MaterialBrowserView::refreshModel()
m_widget->materialBrowserModel()->setMaterials(materials, m_hasQuick3DImport);
for (const ModelNode &node : std::as_const(materials))
model()->nodeInstanceView()->previewImageDataForGenericNode(node, {});
if (updateImages) {
for (const ModelNode &node : std::as_const(materials))
model()->nodeInstanceView()->previewImageDataForGenericNode(node, {});
}
}
bool MaterialBrowserView::isMaterial(const ModelNode &node) const
@@ -204,8 +208,9 @@ void MaterialBrowserView::nodeReparented(const ModelNode &node,
bool matRemoved = oldParentNode.isValid() && oldParentNode.id() == Constants::MATERIAL_LIB_ID;
if (matAdded || matRemoved) {
refreshModel();
if (matAdded) // Workaround to fix various material issues all likely caused by QTBUG-103316
resetPuppet();
refreshModel(!matAdded);
int idx = m_widget->materialBrowserModel()->materialIndex(node);
m_widget->materialBrowserModel()->selectMaterial(idx);
}
@@ -252,7 +257,7 @@ void MaterialBrowserView::importsChanged(const QList<Import> &addedImports, cons
return;
m_hasQuick3DImport = hasQuick3DImport;
refreshModel();
refreshModel(true);
}
void MaterialBrowserView::customNotification(const AbstractView *view, const QString &identifier,
@@ -267,6 +272,13 @@ void MaterialBrowserView::customNotification(const AbstractView *view, const QSt
int idx = m_widget->materialBrowserModel()->materialIndex(nodeList.first());
if (idx != -1)
m_widget->materialBrowserModel()->selectMaterial(idx);
} else if (identifier == "reset QmlPuppet") {
// Little delay is needed to allow puppet reset to actually be done, as it is async as well
QTimer::singleShot(200, this, [this]() {
const QList<ModelNode> materials = m_widget->materialBrowserModel()->materials();
for (const ModelNode &node : materials)
model()->nodeInstanceView()->previewImageDataForGenericNode(node, {});
});
}
}

View File

@@ -62,7 +62,7 @@ public:
const QList<ModelNode> &nodeList, const QList<QVariant> &data) override;
private:
void refreshModel();
void refreshModel(bool updateImages);
bool isMaterial(const ModelNode &node) const;
QPointer<MaterialBrowserWidget> m_widget;