From 64b4211a3c8a037a4f2e6dae71ed65066aca8bea Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Tue, 11 Dec 2018 13:31:01 +0100 Subject: 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 --- src/quick/items/qquickborderimage.cpp | 92 ++--------------------------------- 1 file changed, 5 insertions(+), 87 deletions(-) (limited to 'src/quick/items/qquickborderimage.cpp') diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp index edd3805d7c..32407a474f 100644 --- a/src/quick/items/qquickborderimage.cpp +++ b/src/quick/items/qquickborderimage.cpp @@ -168,6 +168,7 @@ QT_BEGIN_NAMESPACE QQuickBorderImage::QQuickBorderImage(QQuickItem *parent) : QQuickImageBase(*(new QQuickBorderImagePrivate), parent) { + connect(this, &QQuickImageBase::sourceSizeChanged, this, &QQuickBorderImage::sourceSizeChanged); } QQuickBorderImage::~QQuickBorderImage() @@ -295,20 +296,7 @@ void QQuickBorderImage::load() Q_D(QQuickBorderImage); if (d->url.isEmpty()) { - d->pix.clear(this); - d->status = Null; - setImplicitSize(0, 0); - emit statusChanged(d->status); - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - if (sourceSize() != d->oldSourceSize) { - d->oldSourceSize = sourceSize(); - emit sourceSizeChanged(); - } - pixmapChange(); - return; + loadEmptyUrl(); } else { if (d->url.path().endsWith(QLatin1String("sci"))) { QString lf = QQmlFile::urlToLocalFileOrQrc(d->url); @@ -316,7 +304,6 @@ void QQuickBorderImage::load() QFile file(lf); file.open(QIODevice::ReadOnly); setGridScaledImage(QQuickGridScaledImage(&file)); - return; } else { #if QT_CONFIG(qml_network) if (d->progress != 0.0) { @@ -328,50 +315,13 @@ void QQuickBorderImage::load() d->sciReply = qmlEngine(this)->networkAccessManager()->get(req); qmlobject_connect(d->sciReply, QNetworkReply, SIGNAL(finished()), this, QQuickBorderImage, SLOT(sciRequestFinished())); + emit statusChanged(d->status); #endif } } else { - QQuickPixmap::Options options; - if (d->async) - options |= QQuickPixmap::Asynchronous; - if (d->cache) - options |= QQuickPixmap::Cache; - d->pix.clear(this); - - const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qGuiApp->devicePixelRatio()); - d->devicePixelRatio = 1.0; - - QUrl loadUrl = d->url; - resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio); - d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, QQuickImageProviderOptions(), d->currentFrame, d->frameCount); - - if (d->pix.isLoading()) { - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - d->status = Loading; - - 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(); - return; - } + loadPixmap(d->url, LoadPixmapOptions(HandleDPR | UseProviderOptions)); } } - - emit statusChanged(d->status); } /*! @@ -472,39 +422,7 @@ void QQuickBorderImage::setGridScaledImage(const QQuickGridScaledImage& sci) d->verticalTileMode = sci.verticalTileRule(); d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - - QQuickPixmap::Options options; - if (d->async) - options |= QQuickPixmap::Asynchronous; - if (d->cache) - options |= QQuickPixmap::Cache; - d->pix.clear(this); - d->pix.load(qmlEngine(this), d->sciurl, options); - - 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 = - QQuickBorderImage::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); - thisRequestFinished = - QQuickBorderImage::staticMetaObject.indexOfSlot("requestFinished()"); - } - - d->pix.connectFinished(this, thisRequestFinished); - d->pix.connectDownloadProgress(this, thisRequestProgress); - - } else { - requestFinished(); - } + loadPixmap(d->sciurl); } } -- cgit v1.2.3