forked from qt-creator/qt-creator
QmlDesigner: Clear material preview cache on detach
The previews are cached based on modelnode internal id, which can overlap between documents, resulting in briefly showing incorrect preview when new document is opened. Also, never clearing the cache leads to leaking memory. Fixed the issue by clearing the preview cache whenever all materials are removed from browser (model detach and material library deletion). Change-Id: Idad39fef62871c4e94f35604e643c7195ae9ec81 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -212,6 +212,7 @@ bool MaterialBrowserView::isTexture(const ModelNode &node) const
|
|||||||
void MaterialBrowserView::modelAboutToBeDetached(Model *model)
|
void MaterialBrowserView::modelAboutToBeDetached(Model *model)
|
||||||
{
|
{
|
||||||
m_widget->materialBrowserModel()->setMaterials({}, m_hasQuick3DImport);
|
m_widget->materialBrowserModel()->setMaterials({}, m_hasQuick3DImport);
|
||||||
|
m_widget->clearPreviewCache();
|
||||||
|
|
||||||
if (m_propertyGroupsLoaded) {
|
if (m_propertyGroupsLoaded) {
|
||||||
m_propertyGroupsLoaded = false;
|
m_propertyGroupsLoaded = false;
|
||||||
@@ -301,6 +302,7 @@ void MaterialBrowserView::nodeAboutToBeRemoved(const ModelNode &removedNode)
|
|||||||
// removing the material editor node
|
// removing the material editor node
|
||||||
if (removedNode.id() == Constants::MATERIAL_LIB_ID) {
|
if (removedNode.id() == Constants::MATERIAL_LIB_ID) {
|
||||||
m_widget->materialBrowserModel()->setMaterials({}, m_hasQuick3DImport);
|
m_widget->materialBrowserModel()->setMaterials({}, m_hasQuick3DImport);
|
||||||
|
m_widget->clearPreviewCache();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ public:
|
|||||||
m_pixmaps.insert(node.internalId(), pixmap);
|
m_pixmaps.insert(node.internalId(), pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearPixmapCache()
|
||||||
|
{
|
||||||
|
m_pixmaps.clear();
|
||||||
|
}
|
||||||
|
|
||||||
QPixmap requestPixmap(const QString &id,
|
QPixmap requestPixmap(const QString &id,
|
||||||
QSize *size,
|
QSize *size,
|
||||||
[[maybe_unused]] const QSize &requestedSize) override
|
[[maybe_unused]] const QSize &requestedSize) override
|
||||||
@@ -257,6 +262,11 @@ QQuickWidget *MaterialBrowserWidget::quickWidget() const
|
|||||||
return m_quickWidget.data();
|
return m_quickWidget.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MaterialBrowserWidget::clearPreviewCache()
|
||||||
|
{
|
||||||
|
m_previewImageProvider->clearPixmapCache();
|
||||||
|
}
|
||||||
|
|
||||||
QPointer<MaterialBrowserModel> MaterialBrowserWidget::materialBrowserModel() const
|
QPointer<MaterialBrowserModel> MaterialBrowserWidget::materialBrowserModel() const
|
||||||
{
|
{
|
||||||
return m_materialBrowserModel;
|
return m_materialBrowserModel;
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ public:
|
|||||||
|
|
||||||
QQuickWidget *quickWidget() const;
|
QQuickWidget *quickWidget() const;
|
||||||
|
|
||||||
|
void clearPreviewCache();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user