forked from qt-creator/qt-creator
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:
@@ -120,6 +120,11 @@ void MaterialBrowserModel::setHasModelSelection(bool b)
|
|||||||
emit hasModelSelectionChanged();
|
emit hasModelSelectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ModelNode> MaterialBrowserModel::materials() const
|
||||||
|
{
|
||||||
|
return m_materialList;
|
||||||
|
}
|
||||||
|
|
||||||
void MaterialBrowserModel::setSearchText(const QString &searchText)
|
void MaterialBrowserModel::setSearchText(const QString &searchText)
|
||||||
{
|
{
|
||||||
QString lowerSearchText = searchText.toLower();
|
QString lowerSearchText = searchText.toLower();
|
||||||
|
@@ -58,6 +58,7 @@ public:
|
|||||||
bool hasModelSelection() const;
|
bool hasModelSelection() const;
|
||||||
void setHasModelSelection(bool b);
|
void setHasModelSelection(bool b);
|
||||||
|
|
||||||
|
QList<ModelNode> materials() const;
|
||||||
void setMaterials(const QList<ModelNode> &materials, bool hasQuick3DImport);
|
void setMaterials(const QList<ModelNode> &materials, bool hasQuick3DImport);
|
||||||
void removeMaterial(const ModelNode &material);
|
void removeMaterial(const ModelNode &material);
|
||||||
void updateMaterialName(const ModelNode &material);
|
void updateMaterialName(const ModelNode &material);
|
||||||
|
@@ -97,10 +97,12 @@ void MaterialBrowserView::modelAttached(Model *model)
|
|||||||
|
|
||||||
m_widget->clearSearchFilter();
|
m_widget->clearSearchFilter();
|
||||||
m_hasQuick3DImport = model->hasImport("QtQuick3D");
|
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);
|
ModelNode matLib = modelNodeForId(Constants::MATERIAL_LIB_ID);
|
||||||
QList <ModelNode> materials;
|
QList <ModelNode> materials;
|
||||||
@@ -115,8 +117,10 @@ void MaterialBrowserView::refreshModel()
|
|||||||
|
|
||||||
m_widget->materialBrowserModel()->setMaterials(materials, m_hasQuick3DImport);
|
m_widget->materialBrowserModel()->setMaterials(materials, m_hasQuick3DImport);
|
||||||
|
|
||||||
for (const ModelNode &node : std::as_const(materials))
|
if (updateImages) {
|
||||||
model()->nodeInstanceView()->previewImageDataForGenericNode(node, {});
|
for (const ModelNode &node : std::as_const(materials))
|
||||||
|
model()->nodeInstanceView()->previewImageDataForGenericNode(node, {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaterialBrowserView::isMaterial(const ModelNode &node) const
|
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;
|
bool matRemoved = oldParentNode.isValid() && oldParentNode.id() == Constants::MATERIAL_LIB_ID;
|
||||||
|
|
||||||
if (matAdded || matRemoved) {
|
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);
|
int idx = m_widget->materialBrowserModel()->materialIndex(node);
|
||||||
m_widget->materialBrowserModel()->selectMaterial(idx);
|
m_widget->materialBrowserModel()->selectMaterial(idx);
|
||||||
}
|
}
|
||||||
@@ -252,7 +257,7 @@ void MaterialBrowserView::importsChanged(const QList<Import> &addedImports, cons
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_hasQuick3DImport = hasQuick3DImport;
|
m_hasQuick3DImport = hasQuick3DImport;
|
||||||
refreshModel();
|
refreshModel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialBrowserView::customNotification(const AbstractView *view, const QString &identifier,
|
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());
|
int idx = m_widget->materialBrowserModel()->materialIndex(nodeList.first());
|
||||||
if (idx != -1)
|
if (idx != -1)
|
||||||
m_widget->materialBrowserModel()->selectMaterial(idx);
|
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, {});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,7 +62,7 @@ public:
|
|||||||
const QList<ModelNode> &nodeList, const QList<QVariant> &data) override;
|
const QList<ModelNode> &nodeList, const QList<QVariant> &data) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void refreshModel();
|
void refreshModel(bool updateImages);
|
||||||
bool isMaterial(const ModelNode &node) const;
|
bool isMaterial(const ModelNode &node) const;
|
||||||
|
|
||||||
QPointer<MaterialBrowserWidget> m_widget;
|
QPointer<MaterialBrowserWidget> m_widget;
|
||||||
|
Reference in New Issue
Block a user