forked from qt-creator/qt-creator
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:
@@ -116,7 +116,7 @@ void AsynchronousImageFactory::request(Utils::SmallStringView name,
|
|||||||
const auto currentModifiedTime = timeStampProvider.timeStamp(name);
|
const auto currentModifiedTime = timeStampProvider.timeStamp(name);
|
||||||
const auto storageModifiedTime = storage.fetchModifiedImageTime(id);
|
const auto storageModifiedTime = storage.fetchModifiedImageTime(id);
|
||||||
|
|
||||||
if (currentModifiedTime == storageModifiedTime && storage.fetchHasImage(id))
|
if (currentModifiedTime == storageModifiedTime)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
generator.generateImage(name,
|
generator.generateImage(name,
|
||||||
|
@@ -60,8 +60,10 @@ QString fileToString(const QString &filename)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ImageCacheCollector::ImageCacheCollector(ImageCacheConnectionManager &connectionManager)
|
ImageCacheCollector::ImageCacheCollector(ImageCacheConnectionManager &connectionManager,
|
||||||
|
ImageCacheCollectorNullImageHandling nullImageHandling)
|
||||||
: m_connectionManager{connectionManager}
|
: m_connectionManager{connectionManager}
|
||||||
|
, nullImageHandling{nullImageHandling}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ImageCacheCollector::~ImageCacheCollector() = default;
|
ImageCacheCollector::~ImageCacheCollector() = default;
|
||||||
@@ -98,12 +100,14 @@ void ImageCacheCollector::start(Utils::SmallStringView name,
|
|||||||
if (stateNode.isValid())
|
if (stateNode.isValid())
|
||||||
rewriterView.setCurrentStateNode(stateNode);
|
rewriterView.setCurrentStateNode(stateNode);
|
||||||
|
|
||||||
auto callback = [captureCallback = std::move(captureCallback)](const QImage &image) {
|
auto callback = [=, captureCallback = std::move(captureCallback)](const QImage &image) {
|
||||||
QSize smallImageSize = image.size().scaled(QSize{96, 96}.boundedTo(image.size()),
|
if (nullImageHandling == ImageCacheCollectorNullImageHandling::CaptureNullImage
|
||||||
Qt::KeepAspectRatio);
|
|| !image.isNull()) {
|
||||||
QImage smallImage = image.isNull() ? QImage{} : image.scaled(smallImageSize);
|
QSize smallImageSize = image.size().scaled(QSize{96, 96}.boundedTo(image.size()),
|
||||||
|
Qt::KeepAspectRatio);
|
||||||
captureCallback(image, smallImage);
|
QImage smallImage = image.isNull() ? QImage{} : image.scaled(smallImageSize);
|
||||||
|
captureCallback(image, smallImage);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!m_target)
|
if (!m_target)
|
||||||
@@ -126,25 +130,17 @@ void ImageCacheCollector::start(Utils::SmallStringView name,
|
|||||||
abortCallback(ImageCache::AbortReason::Failed);
|
abortCallback(ImageCache::AbortReason::Failed);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<QImage, QImage> ImageCacheCollector::createImage(Utils::SmallStringView filePath,
|
std::pair<QImage, QImage> ImageCacheCollector::createImage(Utils::SmallStringView,
|
||||||
Utils::SmallStringView state,
|
Utils::SmallStringView,
|
||||||
const ImageCache::AuxiliaryData &auxiliaryData)
|
const ImageCache::AuxiliaryData &)
|
||||||
{
|
{
|
||||||
Q_UNUSED(filePath)
|
|
||||||
Q_UNUSED(state)
|
|
||||||
Q_UNUSED(auxiliaryData)
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon ImageCacheCollector::createIcon(Utils::SmallStringView filePath,
|
QIcon ImageCacheCollector::createIcon(Utils::SmallStringView,
|
||||||
Utils::SmallStringView state,
|
Utils::SmallStringView,
|
||||||
const ImageCache::AuxiliaryData &auxiliaryData)
|
const ImageCache::AuxiliaryData &)
|
||||||
{
|
{
|
||||||
Q_UNUSED(filePath)
|
|
||||||
Q_UNUSED(state)
|
|
||||||
Q_UNUSED(auxiliaryData)
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,10 +45,13 @@ class ImageCacheConnectionManager;
|
|||||||
class RewriterView;
|
class RewriterView;
|
||||||
class NodeInstanceView;
|
class NodeInstanceView;
|
||||||
|
|
||||||
|
enum class ImageCacheCollectorNullImageHandling { CaptureNullImage, DontCaptureNullImage };
|
||||||
|
|
||||||
class ImageCacheCollector final : public ImageCacheCollectorInterface
|
class ImageCacheCollector final : public ImageCacheCollectorInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ImageCacheCollector(ImageCacheConnectionManager &connectionManager);
|
ImageCacheCollector(ImageCacheConnectionManager &connectionManager,
|
||||||
|
ImageCacheCollectorNullImageHandling nullImageHandling = {});
|
||||||
|
|
||||||
~ImageCacheCollector();
|
~ImageCacheCollector();
|
||||||
|
|
||||||
@@ -72,6 +75,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
ImageCacheConnectionManager &m_connectionManager;
|
ImageCacheConnectionManager &m_connectionManager;
|
||||||
QPointer<ProjectExplorer::Target> m_target;
|
QPointer<ProjectExplorer::Target> m_target;
|
||||||
|
ImageCacheCollectorNullImageHandling nullImageHandling{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -81,7 +81,8 @@ public:
|
|||||||
Sqlite::LockingMode::Normal};
|
Sqlite::LockingMode::Normal};
|
||||||
ImageCacheStorage<Sqlite::Database> storage{database};
|
ImageCacheStorage<Sqlite::Database> storage{database};
|
||||||
ImageCacheConnectionManager connectionManager;
|
ImageCacheConnectionManager connectionManager;
|
||||||
ImageCacheCollector collector{connectionManager};
|
ImageCacheCollector collector{connectionManager,
|
||||||
|
ImageCacheCollectorNullImageHandling::DontCaptureNullImage};
|
||||||
ImageCacheGenerator generator{collector, storage};
|
ImageCacheGenerator generator{collector, storage};
|
||||||
TimeStampProvider timeStampProvider;
|
TimeStampProvider timeStampProvider;
|
||||||
AsynchronousExplicitImageCache cache{storage};
|
AsynchronousExplicitImageCache cache{storage};
|
||||||
|
@@ -113,12 +113,10 @@ TEST_F(AsynchronousImageFactory, RequestImageWithAuxiliaryDataRequestImageFromGe
|
|||||||
|
|
||||||
TEST_F(AsynchronousImageFactory, DontRequestImageRequestImageFromGeneratorIfFileWasNotUpdated)
|
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();
|
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")))
|
ON_CALL(mockTimeStampProvider, timeStamp(Eq("/path/to/Component.qml")))
|
||||||
.WillByDefault(Return(Sqlite::TimeStamp{124}));
|
.WillByDefault(Return(Sqlite::TimeStamp{124}));
|
||||||
|
|
||||||
@@ -128,28 +126,6 @@ TEST_F(AsynchronousImageFactory, DontRequestImageRequestImageFromGeneratorIfFile
|
|||||||
notification.wait();
|
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)
|
TEST_F(AsynchronousImageFactory, CleanRemovesEntries)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(mockGenerator, generateImage(Eq("/path/to/Component1.qml"), _, _, _, _, _))
|
EXPECT_CALL(mockGenerator, generateImage(Eq("/path/to/Component1.qml"), _, _, _, _, _))
|
||||||
|
Reference in New Issue
Block a user