QmlDesigner: Do only clean image cache if the target changed

Task-number: QDS-3388
Change-Id: I159f70b2bc2f874203392befea566e4c52de7347
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2021-01-26 17:05:27 +01:00
parent 27334cbe6d
commit eb614457ee
4 changed files with 45 additions and 12 deletions

View File

@@ -39,6 +39,8 @@
#include <importmanagerview.h>
#include <nodelistproperty.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <rewriterview.h>
#include <sqlitedatabase.h>
@@ -49,6 +51,16 @@
namespace QmlDesigner {
namespace {
ProjectExplorer::Target *activeTarget(ProjectExplorer::Project *project)
{
if (project)
return project->activeTarget();
return {};
}
} // namespace
class ImageCacheData
{
public:
@@ -72,9 +84,32 @@ ItemLibraryView::ItemLibraryView(QObject* parent)
{
m_imageCacheData = std::make_unique<ImageCacheData>();
auto setTargetInImageCache =
[imageCacheData = m_imageCacheData.get()](ProjectExplorer::Target *target) {
if (target == imageCacheData->collector.target())
return;
if (target)
imageCacheData->cache.clean();
imageCacheData->collector.setTarget(target);
};
if (auto project = ProjectExplorer::SessionManager::startupProject(); project) {
m_imageCacheData->collector.setTarget(project->activeTarget());
connect(project, &ProjectExplorer::Project::activeTargetChanged, this, setTargetInImageCache);
}
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::startupProjectChanged,
this,
[=](ProjectExplorer::Project *project) { setTargetInImageCache(activeTarget(project)); });
}
ItemLibraryView::~ItemLibraryView() = default;
ItemLibraryView::~ItemLibraryView()
{
}
bool ItemLibraryView::hasWidget() const
{
@@ -101,11 +136,6 @@ WidgetInfo ItemLibraryView::widgetInfo()
void ItemLibraryView::modelAttached(Model *model)
{
AbstractView::modelAttached(model);
auto target = QmlDesignerPlugin::instance()->currentDesignDocument()->currentTarget();
m_imageCacheData->cache.clean();
if (target)
m_imageCacheData->collector.setTarget(target);
m_widget->clearSearchFilter();
m_widget->setModel(model);
@@ -120,8 +150,6 @@ void ItemLibraryView::modelAboutToBeDetached(Model *model)
{
model->detachView(m_importManagerView);
m_imageCacheData->collector.setTarget({});
AbstractView::modelAboutToBeDetached(model);
m_widget->setModel(nullptr);

View File

@@ -268,6 +268,9 @@ ItemLibraryWidget::ItemLibraryWidget(AsynchronousImageCache &imageCache,
connect(dropSupport, &Utils::DropSupport::filesDropped,
this, &ItemLibraryWidget::importDroppedFiles);
m_itemViewQuickWidget->engine()->addImageProvider("itemlibrary_preview",
new ItemLibraryIconImageProvider{m_imageCache});
// init the first load of the QML UI elements
reloadQmlSource();
}
@@ -337,14 +340,10 @@ void ItemLibraryWidget::delayedUpdateModel()
void ItemLibraryWidget::setModel(Model *model)
{
m_itemViewQuickWidget->engine()->removeImageProvider("itemlibrary_preview");
m_model = model;
if (!model)
return;
m_itemViewQuickWidget->engine()->addImageProvider("itemlibrary_preview",
new ItemLibraryIconImageProvider{m_imageCache});
setItemLibraryInfo(model->metaInfo().itemLibraryInfo());
}

View File

@@ -153,4 +153,9 @@ void ImageCacheCollector::setTarget(ProjectExplorer::Target *target)
m_target = target;
}
ProjectExplorer::Target *ImageCacheCollector::target() const
{
return m_target;
}
} // namespace QmlDesigner

View File

@@ -67,6 +67,7 @@ public:
const ImageCache::AuxiliaryData &auxiliaryData) override;
void setTarget(ProjectExplorer::Target *target);
ProjectExplorer::Target *target() const;
private:
ImageCacheConnectionManager &m_connectionManager;