Intercept image source url
Fixes: QTBUG-55027 Task-number: QTBUG-76879 Change-Id: Id0c7b33cf22827ebc984c4ee848ef4f63c359b20 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
0f2178a7e3
commit
2149842f7b
|
@ -46,6 +46,8 @@
|
|||
|
||||
#include <QtQml/qqmlinfo.h>
|
||||
#include <QtQml/qqmlfile.h>
|
||||
#include <QtQml/qqmlabstracturlinterceptor.h>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -244,6 +246,9 @@ void QQuickImageBase::load()
|
|||
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())
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include <QQuickWindow>
|
||||
#include <QQuickView>
|
||||
#include <QQuickImageProvider>
|
||||
#include <QQmlAbstractUrlInterceptor>
|
||||
|
||||
#include "../../shared/util.h"
|
||||
#include "../../shared/testhttpserver.h"
|
||||
|
@ -95,6 +96,7 @@ private slots:
|
|||
void highDpiFillModesAndSizes_data();
|
||||
void highDpiFillModesAndSizes();
|
||||
void hugeImages();
|
||||
void urlInterceptor();
|
||||
|
||||
private:
|
||||
QQmlEngine engine;
|
||||
|
@ -1100,6 +1102,36 @@ void tst_qquickimage::hugeImages()
|
|||
QCOMPARE(contents.pixel(199, 99), qRgba(0, 0, 255, 255));
|
||||
}
|
||||
|
||||
|
||||
class MyInterceptor : public QQmlAbstractUrlInterceptor
|
||||
{
|
||||
public:
|
||||
MyInterceptor(QUrl url) : QQmlAbstractUrlInterceptor(), m_url(url) {}
|
||||
QUrl intercept(const QUrl &url, QQmlAbstractUrlInterceptor::DataType type)
|
||||
{
|
||||
if (url.scheme() == "interceptthis")
|
||||
return m_url;
|
||||
return url;
|
||||
}
|
||||
|
||||
QUrl m_url;
|
||||
};
|
||||
|
||||
void tst_qquickimage::urlInterceptor()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
MyInterceptor interceptor {testFileUrl("colors.png")};
|
||||
engine.setUrlInterceptor(&interceptor);
|
||||
|
||||
QQmlComponent c(&engine);
|
||||
|
||||
c.setData("import QtQuick 2.12; Image { objectName: \"item\"; source: width == 0 ? \"interceptthis:doesNotExist\" : \"interceptthis:doesNotExist\"}", QUrl{});
|
||||
QScopedPointer<QQuickImage> object { qobject_cast<QQuickImage*>(c.create())};
|
||||
QVERIFY(object);
|
||||
QTRY_COMPARE(object->status(), QQuickImage::Ready);
|
||||
QTRY_COMPARE(object->progress(), 1.0);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_qquickimage)
|
||||
|
||||
#include "tst_qquickimage.moc"
|
||||
|
|
Loading…
Reference in New Issue