forked from qt-creator/qt-creator
QmlDesigner: Improve puppet reset handling in material browser
Ensure just one reset call for cases where multiple materials are added at once, and detect reset completion from root instance completion notification instead of reset trigger notification, as it comes later and catches all puppet reset cases. Fixes: QDS-7119 Change-Id: I99baa718bd1c85b4581f07ce75193213110e8e96 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -211,8 +211,11 @@ void MaterialBrowserView::nodeReparented(const ModelNode &node,
|
||||
bool matRemoved = oldParentNode.isValid() && oldParentNode.id() == Constants::MATERIAL_LIB_ID;
|
||||
|
||||
if (matAdded || matRemoved) {
|
||||
if (matAdded) // Workaround to fix various material issues all likely caused by QTBUG-103316
|
||||
if (matAdded && !m_puppetResetPending) {
|
||||
// Workaround to fix various material issues all likely caused by QTBUG-103316
|
||||
resetPuppet();
|
||||
m_puppetResetPending = true;
|
||||
}
|
||||
refreshModel(!matAdded);
|
||||
int idx = m_widget->materialBrowserModel()->materialIndex(node);
|
||||
m_widget->materialBrowserModel()->selectMaterial(idx);
|
||||
@@ -261,16 +264,8 @@ void MaterialBrowserView::importsChanged(const QList<Import> &addedImports, cons
|
||||
|
||||
m_hasQuick3DImport = hasQuick3DImport;
|
||||
|
||||
if (m_hasQuick3DImport) {
|
||||
// Import change will trigger puppet reset.
|
||||
// However, it doesn't seem to trigger the notification about the reset, so wait here.
|
||||
QTimer::singleShot(1000, this, [this]() {
|
||||
refreshModel(true);
|
||||
});
|
||||
} else {
|
||||
// No quick3d import, so we can refresh immediately to clear the browser
|
||||
refreshModel(true);
|
||||
}
|
||||
// Import change will trigger puppet reset, so we don't want to update previews immediately
|
||||
refreshModel(false);
|
||||
}
|
||||
|
||||
void MaterialBrowserView::customNotification(const AbstractView *view, const QString &identifier,
|
||||
@@ -285,13 +280,22 @@ 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]() {
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialBrowserView::instancesCompleted(const QVector<ModelNode> &completedNodeList)
|
||||
{
|
||||
for (const ModelNode &node : completedNodeList) {
|
||||
// We use root node completion as indication of puppet reset
|
||||
if (node.isRootNode()) {
|
||||
m_puppetResetPending = false;
|
||||
QTimer::singleShot(1000, this, [this]() {
|
||||
const QList<ModelNode> materials = m_widget->materialBrowserModel()->materials();
|
||||
for (const ModelNode &node : materials)
|
||||
model()->nodeInstanceView()->previewImageDataForGenericNode(node, {});
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -60,6 +60,7 @@ public:
|
||||
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports) override;
|
||||
void customNotification(const AbstractView *view, const QString &identifier,
|
||||
const QList<ModelNode> &nodeList, const QList<QVariant> &data) override;
|
||||
void instancesCompleted(const QVector<ModelNode> &completedNodeList) override;
|
||||
|
||||
private:
|
||||
void refreshModel(bool updateImages);
|
||||
@@ -68,6 +69,7 @@ private:
|
||||
QPointer<MaterialBrowserWidget> m_widget;
|
||||
bool m_hasQuick3DImport = false;
|
||||
bool m_autoSelectModelMaterial = false; // TODO: wire this to some action
|
||||
bool m_puppetResetPending = false;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
Reference in New Issue
Block a user