QmlDesigner: Don't save null image for preview collector

Change-Id: I01ad1c12c25a734107b359461508c037a2f23bb2
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marco Bubke
2022-01-10 15:46:19 +01:00
parent 0c00f58e8b
commit 3d0d9e8e0c
5 changed files with 27 additions and 50 deletions

View File

@@ -116,7 +116,7 @@ void AsynchronousImageFactory::request(Utils::SmallStringView name,
const auto currentModifiedTime = timeStampProvider.timeStamp(name);
const auto storageModifiedTime = storage.fetchModifiedImageTime(id);
if (currentModifiedTime == storageModifiedTime && storage.fetchHasImage(id))
if (currentModifiedTime == storageModifiedTime)
return;
generator.generateImage(name,

View File

@@ -60,8 +60,10 @@ QString fileToString(const QString &filename)
} // namespace
ImageCacheCollector::ImageCacheCollector(ImageCacheConnectionManager &connectionManager)
ImageCacheCollector::ImageCacheCollector(ImageCacheConnectionManager &connectionManager,
ImageCacheCollectorNullImageHandling nullImageHandling)
: m_connectionManager{connectionManager}
, nullImageHandling{nullImageHandling}
{}
ImageCacheCollector::~ImageCacheCollector() = default;
@@ -98,12 +100,14 @@ void ImageCacheCollector::start(Utils::SmallStringView name,
if (stateNode.isValid())
rewriterView.setCurrentStateNode(stateNode);
auto callback = [captureCallback = std::move(captureCallback)](const QImage &image) {
QSize smallImageSize = image.size().scaled(QSize{96, 96}.boundedTo(image.size()),
Qt::KeepAspectRatio);
QImage smallImage = image.isNull() ? QImage{} : image.scaled(smallImageSize);
captureCallback(image, smallImage);
auto callback = [=, captureCallback = std::move(captureCallback)](const QImage &image) {
if (nullImageHandling == ImageCacheCollectorNullImageHandling::CaptureNullImage
|| !image.isNull()) {
QSize smallImageSize = image.size().scaled(QSize{96, 96}.boundedTo(image.size()),
Qt::KeepAspectRatio);
QImage smallImage = image.isNull() ? QImage{} : image.scaled(smallImageSize);
captureCallback(image, smallImage);
}
};
if (!m_target)
@@ -126,25 +130,17 @@ void ImageCacheCollector::start(Utils::SmallStringView name,
abortCallback(ImageCache::AbortReason::Failed);
}
std::pair<QImage, QImage> ImageCacheCollector::createImage(Utils::SmallStringView filePath,
Utils::SmallStringView state,
const ImageCache::AuxiliaryData &auxiliaryData)
std::pair<QImage, QImage> ImageCacheCollector::createImage(Utils::SmallStringView,
Utils::SmallStringView,
const ImageCache::AuxiliaryData &)
{
Q_UNUSED(filePath)
Q_UNUSED(state)
Q_UNUSED(auxiliaryData)
return {};
}
QIcon ImageCacheCollector::createIcon(Utils::SmallStringView filePath,
Utils::SmallStringView state,
const ImageCache::AuxiliaryData &auxiliaryData)
QIcon ImageCacheCollector::createIcon(Utils::SmallStringView,
Utils::SmallStringView,
const ImageCache::AuxiliaryData &)
{
Q_UNUSED(filePath)
Q_UNUSED(state)
Q_UNUSED(auxiliaryData)
return {};
}

View File

@@ -45,10 +45,13 @@ class ImageCacheConnectionManager;
class RewriterView;
class NodeInstanceView;
enum class ImageCacheCollectorNullImageHandling { CaptureNullImage, DontCaptureNullImage };
class ImageCacheCollector final : public ImageCacheCollectorInterface
{
public:
ImageCacheCollector(ImageCacheConnectionManager &connectionManager);
ImageCacheCollector(ImageCacheConnectionManager &connectionManager,
ImageCacheCollectorNullImageHandling nullImageHandling = {});
~ImageCacheCollector();
@@ -72,6 +75,7 @@ public:
private:
ImageCacheConnectionManager &m_connectionManager;
QPointer<ProjectExplorer::Target> m_target;
ImageCacheCollectorNullImageHandling nullImageHandling{};
};
} // namespace QmlDesigner

View File

@@ -81,7 +81,8 @@ public:
Sqlite::LockingMode::Normal};
ImageCacheStorage<Sqlite::Database> storage{database};
ImageCacheConnectionManager connectionManager;
ImageCacheCollector collector{connectionManager};
ImageCacheCollector collector{connectionManager,
ImageCacheCollectorNullImageHandling::DontCaptureNullImage};
ImageCacheGenerator generator{collector, storage};
TimeStampProvider timeStampProvider;
AsynchronousExplicitImageCache cache{storage};

View File

@@ -113,12 +113,10 @@ TEST_F(AsynchronousImageFactory, RequestImageWithAuxiliaryDataRequestImageFromGe
TEST_F(AsynchronousImageFactory, DontRequestImageRequestImageFromGeneratorIfFileWasNotUpdated)
{
ON_CALL(mockStorage, fetchHasImage(Eq("/path/to/Component.qml"))).WillByDefault([&](auto) {
ON_CALL(mockStorage, fetchModifiedImageTime(Eq("/path/to/Component.qml"))).WillByDefault([&](auto) {
notification.notify();
return true;
return Sqlite::TimeStamp{124};
});
ON_CALL(mockStorage, fetchModifiedImageTime(Eq("/path/to/Component.qml")))
.WillByDefault(Return(Sqlite::TimeStamp{124}));
ON_CALL(mockTimeStampProvider, timeStamp(Eq("/path/to/Component.qml")))
.WillByDefault(Return(Sqlite::TimeStamp{124}));
@@ -128,28 +126,6 @@ TEST_F(AsynchronousImageFactory, DontRequestImageRequestImageFromGeneratorIfFile
notification.wait();
}
TEST_F(AsynchronousImageFactory,
RequestImageRequestImageFromGeneratorIfFileWasNotUpdatedButTheImageIsNull)
{
ON_CALL(mockStorage, fetchHasImage(Eq("/path/to/Component.qml"))).WillByDefault(Return(false));
ON_CALL(mockStorage, fetchModifiedImageTime(Eq("/path/to/Component.qml")))
.WillByDefault(Return(Sqlite::TimeStamp{124}));
ON_CALL(mockTimeStampProvider, timeStamp(Eq("/path/to/Component.qml")))
.WillByDefault(Return(Sqlite::TimeStamp{124}));
EXPECT_CALL(mockGenerator,
generateImage(Eq("/path/to/Component.qml"),
IsEmpty(),
Eq(Sqlite::TimeStamp{124}),
_,
_,
VariantWith<Utils::monostate>(Utils::monostate{})))
.WillRepeatedly([&](auto, auto, auto, auto, auto, auto) { notification.notify(); });
factory.generate("/path/to/Component.qml");
notification.wait();
}
TEST_F(AsynchronousImageFactory, CleanRemovesEntries)
{
EXPECT_CALL(mockGenerator, generateImage(Eq("/path/to/Component1.qml"), _, _, _, _, _))