forked from qt-creator/qt-creator
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:
@@ -39,6 +39,8 @@
|
|||||||
#include <importmanagerview.h>
|
#include <importmanagerview.h>
|
||||||
#include <nodelistproperty.h>
|
#include <nodelistproperty.h>
|
||||||
#include <projectexplorer/kit.h>
|
#include <projectexplorer/kit.h>
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <rewriterview.h>
|
#include <rewriterview.h>
|
||||||
#include <sqlitedatabase.h>
|
#include <sqlitedatabase.h>
|
||||||
@@ -49,6 +51,16 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
ProjectExplorer::Target *activeTarget(ProjectExplorer::Project *project)
|
||||||
|
{
|
||||||
|
if (project)
|
||||||
|
return project->activeTarget();
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
class ImageCacheData
|
class ImageCacheData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -72,9 +84,32 @@ ItemLibraryView::ItemLibraryView(QObject* parent)
|
|||||||
|
|
||||||
{
|
{
|
||||||
m_imageCacheData = std::make_unique<ImageCacheData>();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemLibraryView::~ItemLibraryView() = default;
|
connect(ProjectExplorer::SessionManager::instance(),
|
||||||
|
&ProjectExplorer::SessionManager::startupProjectChanged,
|
||||||
|
this,
|
||||||
|
[=](ProjectExplorer::Project *project) { setTargetInImageCache(activeTarget(project)); });
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemLibraryView::~ItemLibraryView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool ItemLibraryView::hasWidget() const
|
bool ItemLibraryView::hasWidget() const
|
||||||
{
|
{
|
||||||
@@ -101,11 +136,6 @@ WidgetInfo ItemLibraryView::widgetInfo()
|
|||||||
void ItemLibraryView::modelAttached(Model *model)
|
void ItemLibraryView::modelAttached(Model *model)
|
||||||
{
|
{
|
||||||
AbstractView::modelAttached(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->clearSearchFilter();
|
||||||
m_widget->setModel(model);
|
m_widget->setModel(model);
|
||||||
@@ -120,8 +150,6 @@ void ItemLibraryView::modelAboutToBeDetached(Model *model)
|
|||||||
{
|
{
|
||||||
model->detachView(m_importManagerView);
|
model->detachView(m_importManagerView);
|
||||||
|
|
||||||
m_imageCacheData->collector.setTarget({});
|
|
||||||
|
|
||||||
AbstractView::modelAboutToBeDetached(model);
|
AbstractView::modelAboutToBeDetached(model);
|
||||||
|
|
||||||
m_widget->setModel(nullptr);
|
m_widget->setModel(nullptr);
|
||||||
|
@@ -268,6 +268,9 @@ ItemLibraryWidget::ItemLibraryWidget(AsynchronousImageCache &imageCache,
|
|||||||
connect(dropSupport, &Utils::DropSupport::filesDropped,
|
connect(dropSupport, &Utils::DropSupport::filesDropped,
|
||||||
this, &ItemLibraryWidget::importDroppedFiles);
|
this, &ItemLibraryWidget::importDroppedFiles);
|
||||||
|
|
||||||
|
m_itemViewQuickWidget->engine()->addImageProvider("itemlibrary_preview",
|
||||||
|
new ItemLibraryIconImageProvider{m_imageCache});
|
||||||
|
|
||||||
// init the first load of the QML UI elements
|
// init the first load of the QML UI elements
|
||||||
reloadQmlSource();
|
reloadQmlSource();
|
||||||
}
|
}
|
||||||
@@ -337,14 +340,10 @@ void ItemLibraryWidget::delayedUpdateModel()
|
|||||||
|
|
||||||
void ItemLibraryWidget::setModel(Model *model)
|
void ItemLibraryWidget::setModel(Model *model)
|
||||||
{
|
{
|
||||||
m_itemViewQuickWidget->engine()->removeImageProvider("itemlibrary_preview");
|
|
||||||
m_model = model;
|
m_model = model;
|
||||||
if (!model)
|
if (!model)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_itemViewQuickWidget->engine()->addImageProvider("itemlibrary_preview",
|
|
||||||
new ItemLibraryIconImageProvider{m_imageCache});
|
|
||||||
|
|
||||||
setItemLibraryInfo(model->metaInfo().itemLibraryInfo());
|
setItemLibraryInfo(model->metaInfo().itemLibraryInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -153,4 +153,9 @@ void ImageCacheCollector::setTarget(ProjectExplorer::Target *target)
|
|||||||
m_target = target;
|
m_target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProjectExplorer::Target *ImageCacheCollector::target() const
|
||||||
|
{
|
||||||
|
return m_target;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -67,6 +67,7 @@ public:
|
|||||||
const ImageCache::AuxiliaryData &auxiliaryData) override;
|
const ImageCache::AuxiliaryData &auxiliaryData) override;
|
||||||
|
|
||||||
void setTarget(ProjectExplorer::Target *target);
|
void setTarget(ProjectExplorer::Target *target);
|
||||||
|
ProjectExplorer::Target *target() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImageCacheConnectionManager &m_connectionManager;
|
ImageCacheConnectionManager &m_connectionManager;
|
||||||
|
Reference in New Issue
Block a user