diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-12-11 13:31:01 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-01-23 16:16:21 +0100 |
commit | 64b4211a3c8a037a4f2e6dae71ed65066aca8bea (patch) | |
tree | 6facec01fe185b2b5565ec9be6e537c41bca88d2 /src/quick/items/qquickimagebase.cpp | |
parent | 684f9df7849bc79f1f02a60844fb43c7a3927d2f (diff) |
Deduplicate QQuickImageBase/QQuickBorderImage::load
These two methods share a whole lot of duplicated logic, and already
show signs of divergence due to maintenance going to the one and
not the other.
This patch removes the duplication.
Change-Id: I6a83dd7f354a94547e44198ec679b323f2c5240e
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickimagebase.cpp')
-rw-r--r-- | src/quick/items/qquickimagebase.cpp | 138 |
1 files changed, 78 insertions, 60 deletions
diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp index 8bab14bfd1..55b29d7a70 100644 --- a/src/quick/items/qquickimagebase.cpp +++ b/src/quick/items/qquickimagebase.cpp @@ -241,46 +241,47 @@ int QQuickImageBase::frameCount() const return d->frameCount; } -void QQuickImageBase::load() +void QQuickImageBase::loadEmptyUrl() { Q_D(QQuickImageBase); + d->pix.clear(this); + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + d->status = Null; + setImplicitSize(0, 0); // also called in QQuickImageBase::pixmapChange, but not QQuickImage/QQuickBorderImage overrides + pixmapChange(); // This calls update() in QQuickBorderImage and QQuickImage, not in QQuickImageBase... - if (d->url.isEmpty()) { - d->pix.clear(this); - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - pixmapChange(); - d->status = Null; - emit statusChanged(d->status); - - if (sourceSize() != d->oldSourceSize) { - d->oldSourceSize = sourceSize(); - emit sourceSizeChanged(); - } - if (autoTransform() != d->oldAutoTransform) { - d->oldAutoTransform = autoTransform(); - emitAutoTransformBaseChanged(); - } - update(); - - } else { - QQuickPixmap::Options options; - if (d->async) - options |= QQuickPixmap::Asynchronous; - if (d->cache) - options |= QQuickPixmap::Cache; - d->pix.clear(this); + emit statusChanged(d->status); + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); + emit sourceSizeChanged(); + } + if (autoTransform() != d->oldAutoTransform) { + d->oldAutoTransform = autoTransform(); + emitAutoTransformBaseChanged(); + } + update(); // .. but double updating should be harmless +} +void QQuickImageBase::loadPixmap(const QUrl &url, LoadPixmapOptions loadOptions) +{ + Q_D(QQuickImageBase); + QQuickPixmap::Options options; + if (d->async) + options |= QQuickPixmap::Asynchronous; + if (d->cache) + options |= QQuickPixmap::Cache; + d->pix.clear(this); + QUrl loadUrl = url; + QQmlEngine* engine = qmlEngine(this); + if (engine && engine->urlInterceptor()) + loadUrl = engine->urlInterceptor()->intercept(loadUrl, QQmlAbstractUrlInterceptor::UrlString); + + if (loadOptions & HandleDPR) { const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio()); d->devicePixelRatio = 1.0; - - QUrl loadUrl = d->url; - QQmlEngine* engine = qmlEngine(this); - if (engine && engine->urlInterceptor()) - loadUrl = engine->urlInterceptor()->intercept(loadUrl, QQmlAbstractUrlInterceptor::UrlString); - bool updatedDevicePixelRatio = false; if (d->sourcesize.isValid()) updatedDevicePixelRatio = d->updateDevicePixelRatio(targetDevicePixelRatio); @@ -290,34 +291,51 @@ void QQuickImageBase::load() // an "@2x" file is found. resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio); } + } + + d->pix.load(qmlEngine(this), + loadUrl, + (loadOptions & HandleDPR) ? d->sourcesize * d->devicePixelRatio : QSize(), + options, + (loadOptions & UseProviderOptions) ? d->providerOptions : QQuickImageProviderOptions(), + d->currentFrame, d->frameCount); + + if (d->pix.isLoading()) { + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + if (d->status != Loading) { + d->status = Loading; + emit statusChanged(d->status); + } - d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->providerOptions, d->currentFrame, d->frameCount); - - if (d->pix.isLoading()) { - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - if (d->status != Loading) { - d->status = Loading; - emit statusChanged(d->status); - } - - static int thisRequestProgress = -1; - static int thisRequestFinished = -1; - if (thisRequestProgress == -1) { - thisRequestProgress = - QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); - thisRequestFinished = - QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()"); - } - - d->pix.connectFinished(this, thisRequestFinished); - d->pix.connectDownloadProgress(this, thisRequestProgress); - update(); //pixmap may have invalidated texture, updatePaintNode needs to be called before the next repaint - } else { - requestFinished(); + static int thisRequestProgress = -1; + static int thisRequestFinished = -1; + if (thisRequestProgress == -1) { + thisRequestProgress = + QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); + thisRequestFinished = + QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()"); } + + d->pix.connectFinished(this, thisRequestFinished); + d->pix.connectDownloadProgress(this, thisRequestProgress); + update(); //pixmap may have invalidated texture, updatePaintNode needs to be called before the next repaint + } else { + requestFinished(); + } +} + +void QQuickImageBase::load() +{ + Q_D(QQuickImageBase); + + if (d->url.isEmpty()) { + loadEmptyUrl(); + update(); + } else { + loadPixmap(d->url, LoadPixmapOptions(HandleDPR | UseProviderOptions)); } } |