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