AnimatedImage: Introduce private clearCache() method

Introduce clearCache() method in QQuickAnimatedImagePrivate and use
it wherever applicable to make the code a bit cleaner. Also don't clean
the cache explicitly on setSource(), as it's still cleared in setMovie()
call.

Change-Id: I299b138371534ff091248013ac833d734d8a6607
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Vladimir Belyavsky 2023-01-30 17:18:54 +03:00
parent b48cf3dcba
commit 1b635cf831
2 changed files with 12 additions and 14 deletions

View File

@ -47,6 +47,12 @@ QQuickPixmap* QQuickAnimatedImagePrivate::infoForCurrentFrame(QQmlEngine *engine
return frameMap.value(current);
}
void QQuickAnimatedImagePrivate::clearCache()
{
qDeleteAll(frameMap);
frameMap.clear();
}
/*!
\qmltype AnimatedImage
\instantiates QQuickAnimatedImage
@ -117,8 +123,7 @@ QQuickAnimatedImage::~QQuickAnimatedImage()
d->reply->deleteLater();
#endif
delete d->movie;
qDeleteAll(d->frameMap);
d->frameMap.clear();
d->clearCache();
}
/*!
@ -268,9 +273,6 @@ void QQuickAnimatedImage::setSource(const QUrl &url)
#endif
d->setImage(QImage());
qDeleteAll(d->frameMap);
d->frameMap.clear();
d->oldPlaying = isPlaying();
d->setMovie(nullptr);
d->url = url;
@ -425,10 +427,8 @@ void QQuickAnimatedImage::movieUpdate()
{
Q_D(QQuickAnimatedImage);
if (!d->cache) {
qDeleteAll(d->frameMap);
d->frameMap.clear();
}
if (!d->cache)
d->clearCache();
if (d->movie) {
d->setPixmap(*d->infoForCurrentFrame(qmlEngine(this)));
@ -454,8 +454,7 @@ void QQuickAnimatedImage::onCacheChanged()
{
Q_D(QQuickAnimatedImage);
if (!cache()) {
qDeleteAll(d->frameMap);
d->frameMap.clear();
d->clearCache();
if (d->movie)
d->movie->setCacheMode(QMovie::CacheNone);
} else {
@ -484,9 +483,7 @@ void QQuickAnimatedImagePrivate::setMovie(QMovie *m)
}
movie = m;
qDeleteAll(frameMap);
frameMap.clear();
clearCache();
if (movie)
movie->setScaledSize(sourcesize);

View File

@ -44,6 +44,7 @@ public:
QQuickPixmap *infoForCurrentFrame(QQmlEngine *engine);
void setMovie(QMovie *movie);
void clearCache();
bool playing : 1;
bool paused : 1;