Do not resolve URLs when assigning them to a property
We don't know in advance if a URL is part of the source code and should be relative to the current element, or if it is part of the application data and should not be touched. [ChangeLog][QtQml][Important Behavior Changes] URLs are not resolved or intercepted anymore when assigning them to a "url" property. Instead they are resolved and possibly intercepted when used to access an actual resource. Fixes: QTBUG-76879 Change-Id: Iaa2385aff2c13aa71a12e57385d9afb5dc60a073 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
4e266103ad
commit
0a1e4cc7ec
|
@ -1169,22 +1169,33 @@ bool QQuickImageParticle::loadingSomething()
|
|||
|
||||
void QQuickImageParticle::mainThreadFetchImageData()
|
||||
{
|
||||
const QQmlContext *context = nullptr;
|
||||
QQmlEngine *engine = nullptr;
|
||||
const auto loadPix = [&](ImageData *image) {
|
||||
if (!engine) {
|
||||
context = qmlContext(this);
|
||||
engine = context->engine();
|
||||
}
|
||||
image->pix.load(engine, context->resolvedUrl(image->source));
|
||||
};
|
||||
|
||||
|
||||
if (m_image) {//ImageData created on setSource
|
||||
m_image->pix.clear(this);
|
||||
m_image->pix.load(qmlEngine(this), m_image->source);
|
||||
loadPix(m_image.get());
|
||||
}
|
||||
|
||||
if (m_spriteEngine)
|
||||
m_spriteEngine->startAssemblingImage();
|
||||
|
||||
if (m_colorTable)
|
||||
m_colorTable->pix.load(qmlEngine(this), m_colorTable->source);
|
||||
loadPix(m_colorTable.get());
|
||||
|
||||
if (m_sizeTable)
|
||||
m_sizeTable->pix.load(qmlEngine(this), m_sizeTable->source);
|
||||
loadPix(m_sizeTable.get());
|
||||
|
||||
if (m_opacityTable)
|
||||
m_opacityTable->pix.load(qmlEngine(this), m_opacityTable->source);
|
||||
loadPix(m_opacityTable.get());
|
||||
|
||||
m_startedImageLoading = 2;
|
||||
}
|
||||
|
|
|
@ -40,9 +40,12 @@
|
|||
#include "qquickmaskextruder_p.h"
|
||||
#include <QtQml/qqml.h>
|
||||
#include <QtQml/qqmlinfo.h>
|
||||
#include <QtQml/qqmlcontext.h>
|
||||
|
||||
#include <QImage>
|
||||
#include <QDebug>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
/*!
|
||||
\qmltype MaskShape
|
||||
|
@ -85,7 +88,8 @@ void QQuickMaskExtruder::startMaskLoading()
|
|||
m_pix.clear(this);
|
||||
if (m_source.isEmpty())
|
||||
return;
|
||||
m_pix.load(qmlEngine(this), m_source);
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
m_pix.load(context->engine(), context->resolvedUrl(m_source));
|
||||
if (m_pix.isLoading())
|
||||
m_pix.connectFinished(this, SLOT(finishMaskLoading()));
|
||||
else
|
||||
|
|
|
@ -426,7 +426,7 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core,
|
|||
} else if (result.isNull() && core.isQObject()) {
|
||||
value = QVariant::fromValue((QObject *)nullptr);
|
||||
} else if (core.propType() == qMetaTypeId<QList<QUrl> >()) {
|
||||
value = QQmlPropertyPrivate::resolvedUrlSequence(v4engine->toVariant(result, qMetaTypeId<QList<QUrl> >()), context());
|
||||
value = QQmlPropertyPrivate::urlSequence(v4engine->toVariant(result, qMetaTypeId<QList<QUrl>>()));
|
||||
} else if (!isVarProperty && type != qMetaTypeId<QJSValue>()) {
|
||||
value = v4engine->toVariant(result, type);
|
||||
}
|
||||
|
|
|
@ -452,10 +452,7 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const
|
|||
case QMetaType::QUrl: {
|
||||
assertType(QV4::CompiledData::Binding::Type_String);
|
||||
const QString string = compilationUnit->bindingValueAsString(binding);
|
||||
QUrl value = string.isEmpty() ? QUrl()
|
||||
: compilationUnit->finalUrl().resolved(QUrl(string));
|
||||
// Apply URL interceptor
|
||||
value = engine->interceptUrl(value, QQmlAbstractUrlInterceptor::UrlString);
|
||||
QUrl value(string);
|
||||
property->writeProperty(_qobject, &value, propertyWriteFlags);
|
||||
}
|
||||
break;
|
||||
|
@ -646,11 +643,7 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const
|
|||
break;
|
||||
} else if (property->propType() == qMetaTypeId<QList<QUrl> >()) {
|
||||
assertType(QV4::CompiledData::Binding::Type_String);
|
||||
QString urlString = compilationUnit->bindingValueAsString(binding);
|
||||
QUrl u = urlString.isEmpty() ? QUrl()
|
||||
: compilationUnit->finalUrl().resolved(QUrl(urlString));
|
||||
QList<QUrl> value;
|
||||
value.append(u);
|
||||
QList<QUrl> value { QUrl(compilationUnit->bindingValueAsString(binding)) };
|
||||
property->writeProperty(_qobject, &value, propertyWriteFlags);
|
||||
break;
|
||||
} else if (property->propType() == qMetaTypeId<QList<QString> >()) {
|
||||
|
|
|
@ -1100,8 +1100,7 @@ QVariant QQmlPropertyPrivate::readValueProperty()
|
|||
}
|
||||
|
||||
// helper function to allow assignment / binding to QList<QUrl> properties.
|
||||
QVariant QQmlPropertyPrivate::resolvedUrlSequence(
|
||||
const QVariant &value, const QQmlRefPointer<QQmlContextData> &context)
|
||||
QVariant QQmlPropertyPrivate::urlSequence(const QVariant &value)
|
||||
{
|
||||
QList<QUrl> urls;
|
||||
if (value.userType() == qMetaTypeId<QUrl>()) {
|
||||
|
@ -1126,17 +1125,7 @@ QVariant QQmlPropertyPrivate::resolvedUrlSequence(
|
|||
urls.append(QUrl(urlStrings.at(i)));
|
||||
} // note: QList<QByteArray> is not currently supported.
|
||||
|
||||
QList<QUrl> resolvedUrls;
|
||||
const int urlsSize = urls.size();
|
||||
resolvedUrls.reserve(urlsSize);
|
||||
for (int i = 0; i < urlsSize; ++i) {
|
||||
QUrl u = urls.at(i);
|
||||
if (context && u.isRelative() && !u.isEmpty())
|
||||
u = context->resolvedUrl(u);
|
||||
resolvedUrls.append(u);
|
||||
}
|
||||
|
||||
return QVariant::fromValue<QList<QUrl> >(resolvedUrls);
|
||||
return QVariant::fromValue<QList<QUrl> >(urls);
|
||||
}
|
||||
|
||||
//writeEnumProperty MIRRORS the relelvant bit of QMetaProperty::write AND MUST BE KEPT IN SYNC!
|
||||
|
@ -1318,11 +1307,9 @@ bool QQmlPropertyPrivate::write(
|
|||
else
|
||||
return false;
|
||||
|
||||
if (context && u.isRelative() && !u.isEmpty())
|
||||
u = context->resolvedUrl(u);
|
||||
return property.writeProperty(object, &u, flags);
|
||||
} else if (propertyType == qMetaTypeId<QList<QUrl>>()) {
|
||||
QList<QUrl> urlSeq = resolvedUrlSequence(value, context).value<QList<QUrl>>();
|
||||
QList<QUrl> urlSeq = urlSequence(value).value<QList<QUrl>>();
|
||||
return property.writeProperty(object, &urlSeq, flags);
|
||||
} else if (property.isQList()) {
|
||||
QQmlMetaObject listType;
|
||||
|
|
|
@ -150,8 +150,7 @@ public:
|
|||
int type = 0, int *types = nullptr);
|
||||
static void flushSignal(const QObject *sender, int signal_index);
|
||||
|
||||
static QVariant resolvedUrlSequence(
|
||||
const QVariant &value, const QQmlRefPointer<QQmlContextData> &context);
|
||||
static QVariant urlSequence(const QVariant &value);
|
||||
static QQmlProperty create(
|
||||
QObject *target, const QString &propertyName,
|
||||
const QQmlRefPointer<QQmlContextData> &context);
|
||||
|
|
|
@ -553,8 +553,10 @@ void QQuickWorkerScript::setSource(const QUrl &source)
|
|||
|
||||
m_source = source;
|
||||
|
||||
if (engine())
|
||||
m_engine->executeUrl(m_scriptId, m_source);
|
||||
if (engine()) {
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
m_engine->executeUrl(m_scriptId, context ? context->resolvedUrl(m_source) : m_source);
|
||||
}
|
||||
|
||||
emit sourceChanged();
|
||||
}
|
||||
|
@ -614,7 +616,8 @@ QQuickWorkerScriptEngine *QQuickWorkerScript::engine()
|
|||
{
|
||||
if (m_engine) return m_engine;
|
||||
if (m_componentComplete) {
|
||||
QQmlEngine *engine = qmlEngine(this);
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
QQmlEngine *engine = context ? context->engine() : nullptr;
|
||||
if (!engine) {
|
||||
qWarning("QQuickWorkerScript: engine() called without qmlEngine() set");
|
||||
return nullptr;
|
||||
|
@ -628,7 +631,7 @@ QQuickWorkerScriptEngine *QQuickWorkerScript::engine()
|
|||
m_scriptId = m_engine->registerWorkerScript(this);
|
||||
|
||||
if (m_source.isValid())
|
||||
m_engine->executeUrl(m_scriptId, m_source);
|
||||
m_engine->executeUrl(m_scriptId, context->resolvedUrl(m_source));
|
||||
|
||||
emit readyChanged();
|
||||
|
||||
|
|
|
@ -339,8 +339,10 @@ void QQuickAnimatedImage::load()
|
|||
const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
|
||||
d->devicePixelRatio = 1.0;
|
||||
|
||||
QUrl loadUrl = d->url;
|
||||
resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);
|
||||
const auto context = qmlContext(this);
|
||||
QUrl loadUrl = context ? context->resolvedUrl(d->url) : d->url;
|
||||
const QUrl resolvedUrl = loadUrl;
|
||||
resolve2xLocalFile(resolvedUrl, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);
|
||||
QString lf = QQmlFile::urlToLocalFileOrQrc(loadUrl);
|
||||
|
||||
if (!lf.isEmpty()) {
|
||||
|
@ -393,7 +395,9 @@ void QQuickAnimatedImage::movieRequestFinished()
|
|||
#endif
|
||||
|
||||
if (!d->movie || !d->movie->isValid()) {
|
||||
qmlWarning(this) << "Error Reading Animated Image File " << d->url.toString();
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
qmlWarning(this) << "Error Reading Animated Image File "
|
||||
<< (context ? context->resolvedUrl(d->url) : d->url).toString();
|
||||
d->setMovie(nullptr);
|
||||
d->setImage(QImage());
|
||||
if (d->progress != 0) {
|
||||
|
|
|
@ -299,7 +299,9 @@ void QQuickBorderImage::load()
|
|||
loadEmptyUrl();
|
||||
} else {
|
||||
if (d->url.path().endsWith(QLatin1String("sci"))) {
|
||||
QString lf = QQmlFile::urlToLocalFileOrQrc(d->url);
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
QString lf = QQmlFile::urlToLocalFileOrQrc(context ? context->resolvedUrl(d->url)
|
||||
: d->url);
|
||||
if (!lf.isEmpty()) {
|
||||
QFile file(lf);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
|
|
@ -298,8 +298,9 @@ void QQuickImageBase::loadPixmap(const QUrl &url, LoadPixmapOptions loadOptions)
|
|||
options |= QQuickPixmap::Cache;
|
||||
d->pix.clear(this);
|
||||
QUrl loadUrl = url;
|
||||
if (const QQmlEngine *engine = qmlEngine(this))
|
||||
loadUrl = engine->interceptUrl(loadUrl, QQmlAbstractUrlInterceptor::UrlString);
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
if (context)
|
||||
loadUrl = context->resolvedUrl(url);
|
||||
|
||||
if (loadOptions & HandleDPR) {
|
||||
const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
|
||||
|
@ -311,7 +312,8 @@ void QQuickImageBase::loadPixmap(const QUrl &url, LoadPixmapOptions loadOptions)
|
|||
if (!updatedDevicePixelRatio) {
|
||||
// (possible) local file: loadUrl and d->devicePixelRatio will be modified if
|
||||
// an "@2x" file is found.
|
||||
resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);
|
||||
resolve2xLocalFile(context ? context->resolvedUrl(d->url) : d->url,
|
||||
targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -439,9 +439,8 @@ void QQuickLoader::loadFromSource()
|
|||
}
|
||||
|
||||
if (isComponentComplete()) {
|
||||
QQmlComponent::CompilationMode mode = d->asynchronous ? QQmlComponent::Asynchronous : QQmlComponent::PreferSynchronous;
|
||||
if (!d->component)
|
||||
d->component.setObject(new QQmlComponent(qmlEngine(this), d->source, mode, this), this);
|
||||
d->createComponent();
|
||||
d->load();
|
||||
}
|
||||
}
|
||||
|
@ -796,11 +795,8 @@ void QQuickLoader::componentComplete()
|
|||
Q_D(QQuickLoader);
|
||||
QQuickItem::componentComplete();
|
||||
if (active()) {
|
||||
if (d->loadingFromSource) {
|
||||
QQmlComponent::CompilationMode mode = d->asynchronous ? QQmlComponent::Asynchronous : QQmlComponent::PreferSynchronous;
|
||||
if (!d->component)
|
||||
d->component.setObject(new QQmlComponent(qmlEngine(this), d->source, mode, this), this);
|
||||
}
|
||||
if (d->loadingFromSource)
|
||||
d->createComponent();
|
||||
d->load();
|
||||
}
|
||||
}
|
||||
|
@ -1027,6 +1023,17 @@ void QQuickLoaderPrivate::updateStatus()
|
|||
}
|
||||
}
|
||||
|
||||
void QQuickLoaderPrivate::createComponent()
|
||||
{
|
||||
Q_Q(QQuickLoader);
|
||||
const QQmlComponent::CompilationMode mode = asynchronous
|
||||
? QQmlComponent::Asynchronous
|
||||
: QQmlComponent::PreferSynchronous;
|
||||
QQmlContext *context = qmlContext(q);
|
||||
component.setObject(new QQmlComponent(
|
||||
context->engine(), context->resolvedUrl(source), mode, q), q);
|
||||
}
|
||||
|
||||
#include <moc_qquickloader_p.cpp>
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
@ -98,6 +98,7 @@ public:
|
|||
QV4::ReturnedValue extractInitialPropertyValues(QQmlV4Function *args, QObject *loader, bool *error);
|
||||
QQuickLoader::Status computeStatus() const;
|
||||
void updateStatus();
|
||||
void createComponent();
|
||||
|
||||
qreal getImplicitWidth() const override;
|
||||
qreal getImplicitHeight() const override;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "qquicksprite_p.h"
|
||||
#include "qquickimagebase_p.h"
|
||||
#include <qqml.h>
|
||||
#include <QQmlContext>
|
||||
#include <QDebug>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
|
@ -261,14 +262,18 @@ void QQuickSprite::startImageLoading()
|
|||
{
|
||||
m_pix.clear(this);
|
||||
if (!m_source.isEmpty()) {
|
||||
QQmlEngine *e = qmlEngine(this);
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
QQmlEngine *e = context ? context->engine() : nullptr;
|
||||
if (!e) { //If not created in QML, you must set the QObject parent to the QML element so this can work
|
||||
e = qmlEngine(parent());
|
||||
context = qmlContext(parent());
|
||||
e = context ? context->engine() : nullptr;
|
||||
if (!e)
|
||||
qWarning() << "QQuickSprite: Cannot find QQmlEngine - this class is only for use in QML and may not work";
|
||||
}
|
||||
QUrl loadUrl = m_source;
|
||||
QQuickImageBase::resolve2xLocalFile(m_source, m_devicePixelRatio, &loadUrl, &m_devicePixelRatio);
|
||||
const QUrl resolvedUrl = context ? context->resolvedUrl(m_source) : m_source;
|
||||
QUrl loadUrl = resolvedUrl;
|
||||
QQuickImageBase::resolve2xLocalFile(resolvedUrl, m_devicePixelRatio, &loadUrl,
|
||||
&m_devicePixelRatio);
|
||||
|
||||
m_pix.load(e, loadUrl);
|
||||
}
|
||||
|
|
|
@ -1218,8 +1218,9 @@ void QQuickTextPrivate::setLineGeometry(QTextLine &line, qreal lineWidth, qreal
|
|||
image->position < line.textStart() + line.textLength()) {
|
||||
|
||||
if (!image->pix) {
|
||||
QUrl url = q->baseUrl().resolved(image->url);
|
||||
image->pix = new QQuickPixmap(qmlEngine(q), url, QRect(), image->size);
|
||||
const QQmlContext *context = qmlContext(q);
|
||||
const QUrl url = context->resolvedUrl(q->baseUrl()).resolved(image->url);
|
||||
image->pix = new QQuickPixmap(context->engine(), url, QRect(), image->size);
|
||||
if (image->pix->isLoading()) {
|
||||
image->pix->connectFinished(q, SLOT(imageDownloadFinished()));
|
||||
if (!extra.isAllocated() || !extra->nbActiveDownloads)
|
||||
|
@ -1285,7 +1286,8 @@ void QQuickTextPrivate::ensureDoc()
|
|||
extra.value().doc = new QQuickTextDocumentWithImageResources(q);
|
||||
extra->doc->setPageSize(QSizeF(0, 0));
|
||||
extra->doc->setDocumentMargin(0);
|
||||
extra->doc->setBaseUrl(q->baseUrl());
|
||||
const QQmlContext *context = qmlContext(q);
|
||||
extra->doc->setBaseUrl(context ? context->resolvedUrl(q->baseUrl()) : q->baseUrl());
|
||||
qmlobject_connect(extra->doc, QQuickTextDocumentWithImageResources, SIGNAL(imagesLoaded()),
|
||||
q, QQuickText, SLOT(q_updateLayout()));
|
||||
}
|
||||
|
|
|
@ -1465,7 +1465,9 @@ void QQuickTextEdit::componentComplete()
|
|||
Q_D(QQuickTextEdit);
|
||||
QQuickImplicitSizeItem::componentComplete();
|
||||
|
||||
d->document->setBaseUrl(baseUrl());
|
||||
const QUrl url = baseUrl();
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
d->document->setBaseUrl(context ? context->resolvedUrl(url) : url);
|
||||
#if QT_CONFIG(texthtmlparser)
|
||||
if (d->richText)
|
||||
d->control->setHtml(d->text);
|
||||
|
|
|
@ -247,24 +247,27 @@ void QQuickFontLoader::setSource(const QUrl &url)
|
|||
d->url = url;
|
||||
emit sourceChanged();
|
||||
|
||||
QString localFile = QQmlFile::urlToLocalFileOrQrc(d->url);
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
const QUrl &resolvedUrl = context ? context->resolvedUrl(d->url) : d->url;
|
||||
QString localFile = QQmlFile::urlToLocalFileOrQrc(resolvedUrl);
|
||||
if (!localFile.isEmpty()) {
|
||||
if (!fontLoaderFonts()->map.contains(d->url)) {
|
||||
if (!fontLoaderFonts()->map.contains(resolvedUrl)) {
|
||||
int id = QFontDatabase::addApplicationFont(localFile);
|
||||
updateFontInfo(id);
|
||||
if (id != -1) {
|
||||
QQuickFontObject *fo = new QQuickFontObject(id);
|
||||
fontLoaderFonts()->map[d->url] = fo;
|
||||
fontLoaderFonts()->map[resolvedUrl] = fo;
|
||||
}
|
||||
} else {
|
||||
updateFontInfo(fontLoaderFonts()->map.value(d->url)->id);
|
||||
updateFontInfo(fontLoaderFonts()->map.value(resolvedUrl)->id);
|
||||
}
|
||||
} else {
|
||||
if (!fontLoaderFonts()->map.contains(d->url)) {
|
||||
if (!fontLoaderFonts()->map.contains(resolvedUrl)) {
|
||||
Q_ASSERT(context);
|
||||
#if QT_CONFIG(qml_network)
|
||||
QQuickFontObject *fo = new QQuickFontObject;
|
||||
fontLoaderFonts()->map[d->url] = fo;
|
||||
fo->download(d->url, qmlEngine(this)->networkAccessManager());
|
||||
fontLoaderFonts()->map[resolvedUrl] = fo;
|
||||
fo->download(resolvedUrl, context->engine()->networkAccessManager());
|
||||
d->status = Loading;
|
||||
emit statusChanged();
|
||||
QObject::connect(fo, SIGNAL(fontDownloaded(int)),
|
||||
|
@ -273,7 +276,7 @@ void QQuickFontLoader::setSource(const QUrl &url)
|
|||
// Silently fail if compiled with no_network
|
||||
#endif
|
||||
} else {
|
||||
QQuickFontObject *fo = fontLoaderFonts()->map.value(d->url);
|
||||
QQuickFontObject *fo = fontLoaderFonts()->map.value(resolvedUrl);
|
||||
if (fo->id == -1) {
|
||||
#if QT_CONFIG(qml_network)
|
||||
d->status = Loading;
|
||||
|
@ -321,8 +324,11 @@ void QQuickFontLoader::updateFontInfo(int id)
|
|||
}
|
||||
|
||||
if (status != d->status) {
|
||||
if (status == Error)
|
||||
qmlWarning(this) << "Cannot load font: \"" << d->url.toString() << '"';
|
||||
if (status == Error) {
|
||||
const QQmlContext *context = qmlContext(this);
|
||||
qmlWarning(this) << "Cannot load font: \""
|
||||
<< (context ? context->resolvedUrl(d->url) : d->url).toString() << '"';
|
||||
}
|
||||
d->status = status;
|
||||
emit statusChanged();
|
||||
}
|
||||
|
|
|
@ -481,7 +481,7 @@ void tst_qqmlecmascript::assignBasicTypes()
|
|||
QCOMPARE(object->boolProperty(), true);
|
||||
QCOMPARE(object->variantProperty(), QVariant("Hello World!"));
|
||||
QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2f));
|
||||
QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml")));
|
||||
QCOMPARE(object->urlProperty(), QUrl("main.qml"));
|
||||
delete object;
|
||||
}
|
||||
{
|
||||
|
@ -510,7 +510,7 @@ void tst_qqmlecmascript::assignBasicTypes()
|
|||
QCOMPARE(object->boolProperty(), true);
|
||||
QCOMPARE(object->variantProperty(), QVariant("Hello World!"));
|
||||
QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2f));
|
||||
QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml")));
|
||||
QCOMPARE(object->urlProperty(), QUrl("main.qml"));
|
||||
delete object;
|
||||
}
|
||||
}
|
||||
|
@ -6036,10 +6036,10 @@ void tst_qqmlecmascript::assignSequenceTypes()
|
|||
MySequenceConversionObject *msco4 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco4"));
|
||||
MySequenceConversionObject *msco5 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco5"));
|
||||
QVERIFY(msco1 != nullptr && msco2 != nullptr && msco3 != nullptr && msco4 != nullptr && msco5 != nullptr);
|
||||
QCOMPARE(msco1->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html"))));
|
||||
QCOMPARE(msco2->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html"))));
|
||||
QCOMPARE(msco3->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")) << QUrl(testFileUrl("example2.html"))));
|
||||
QCOMPARE(msco4->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")) << QUrl(testFileUrl("example2.html"))));
|
||||
QCOMPARE(msco1->urlListProperty(), (QList<QUrl>() << QUrl("example.html")));
|
||||
QCOMPARE(msco2->urlListProperty(), (QList<QUrl>() << QUrl("example.html")));
|
||||
QCOMPARE(msco3->urlListProperty(), (QList<QUrl>() << QUrl("example.html") << QUrl("example2.html")));
|
||||
QCOMPARE(msco4->urlListProperty(), (QList<QUrl>() << QUrl("example.html") << QUrl("example2.html")));
|
||||
QCOMPARE(msco5->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")) << QUrl(testFileUrl("example2.html"))));
|
||||
delete object;
|
||||
}
|
||||
|
|
|
@ -799,7 +799,6 @@ void tst_qqmlengine::urlInterceptor_data()
|
|||
{
|
||||
QTest::addColumn<QUrl>("testFile");
|
||||
QTest::addColumn<QList<QQmlAbstractUrlInterceptor::DataType> >("interceptionPoint");
|
||||
QTest::addColumn<QString>("expectedFilePath");
|
||||
QTest::addColumn<QString>("expectedChildString");
|
||||
QTest::addColumn<QString>("expectedScriptString");
|
||||
QTest::addColumn<QString>("expectedResolvedUrl");
|
||||
|
@ -808,7 +807,6 @@ void tst_qqmlengine::urlInterceptor_data()
|
|||
QTest::newRow("InterceptTypes")
|
||||
<< testFileUrl("interception/types/urlInterceptor.qml")
|
||||
<< (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmlFile << QQmlAbstractUrlInterceptor::JavaScriptFile << QQmlAbstractUrlInterceptor::UrlString)
|
||||
<< testFileUrl("interception/types/intercepted/doesNotExist.file").toString()
|
||||
<< QStringLiteral("intercepted")
|
||||
<< QStringLiteral("intercepted")
|
||||
<< testFileUrl("interception/types/intercepted/doesNotExist.file").toString()
|
||||
|
@ -817,7 +815,6 @@ void tst_qqmlengine::urlInterceptor_data()
|
|||
QTest::newRow("InterceptQmlDir")
|
||||
<< testFileUrl("interception/qmldir/urlInterceptor.qml")
|
||||
<< (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmldirFile << QQmlAbstractUrlInterceptor::UrlString)
|
||||
<< testFileUrl("interception/qmldir/intercepted/doesNotExist.file").toString()
|
||||
<< QStringLiteral("intercepted")
|
||||
<< QStringLiteral("base file")
|
||||
<< testFileUrl("interception/qmldir/intercepted/doesNotExist.file").toString()
|
||||
|
@ -826,7 +823,6 @@ void tst_qqmlengine::urlInterceptor_data()
|
|||
QTest::newRow("InterceptModule")//just a Test{}, needs to intercept the module import for it to work
|
||||
<< testFileUrl("interception/module/urlInterceptor.qml")
|
||||
<< (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmldirFile )
|
||||
<< testFileUrl("interception/module/intercepted/doesNotExist.file").toString()
|
||||
<< QStringLiteral("intercepted")
|
||||
<< QStringLiteral("intercepted")
|
||||
<< testFileUrl("interception/module/intercepted/doesNotExist.file").toString()
|
||||
|
@ -835,7 +831,6 @@ void tst_qqmlengine::urlInterceptor_data()
|
|||
QTest::newRow("InterceptStrings")
|
||||
<< testFileUrl("interception/strings/urlInterceptor.qml")
|
||||
<< (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::UrlString)
|
||||
<< testFileUrl("interception/strings/intercepted/doesNotExist.file").toString()
|
||||
<< QStringLiteral("base file")
|
||||
<< QStringLiteral("base file")
|
||||
<< testFileUrl("interception/strings/intercepted/doesNotExist.file").toString()
|
||||
|
@ -844,7 +839,6 @@ void tst_qqmlengine::urlInterceptor_data()
|
|||
QTest::newRow("InterceptIncludes")
|
||||
<< testFileUrl("interception/includes/urlInterceptor.qml")
|
||||
<< (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::JavaScriptFile)
|
||||
<< testFileUrl("interception/includes/doesNotExist.file").toString()
|
||||
<< QStringLiteral("base file")
|
||||
<< QStringLiteral("intercepted include file")
|
||||
<< testFileUrl("interception/includes/doesNotExist.file").toString()
|
||||
|
@ -856,7 +850,6 @@ void tst_qqmlengine::urlInterceptor()
|
|||
|
||||
QFETCH(QUrl, testFile);
|
||||
QFETCH(QList<QQmlAbstractUrlInterceptor::DataType>, interceptionPoint);
|
||||
QFETCH(QString, expectedFilePath);
|
||||
QFETCH(QString, expectedChildString);
|
||||
QFETCH(QString, expectedScriptString);
|
||||
QFETCH(QString, expectedResolvedUrl);
|
||||
|
@ -873,7 +866,7 @@ void tst_qqmlengine::urlInterceptor()
|
|||
qDebug() << c.errorString();
|
||||
QVERIFY(o);
|
||||
//Test a URL as a property initialization
|
||||
QCOMPARE(o->property("filePath").toString(), expectedFilePath);
|
||||
QCOMPARE(o->property("filePath").toString(), QUrl("doesNotExist.file").toString());
|
||||
//Test a URL as a Type location
|
||||
QCOMPARE(o->property("childString").toString(), expectedChildString);
|
||||
//Test a URL as a Script location
|
||||
|
|
|
@ -814,7 +814,7 @@ void tst_qqmllanguage::assignBasicTypes()
|
|||
QCOMPARE(object->vector2Property(), QVector2D(2, 3));
|
||||
QCOMPARE(object->vector4Property(), QVector4D(10, 1, 2.2f, 2.3f));
|
||||
const QUrl encoded = QUrl::fromEncoded("main.qml?with%3cencoded%3edata", QUrl::TolerantMode);
|
||||
QCOMPARE(object->urlProperty(), component.url().resolved(encoded));
|
||||
QCOMPARE(object->urlProperty(), encoded);
|
||||
QVERIFY(object->objectProperty() != nullptr);
|
||||
MyTypeObject *child = qobject_cast<MyTypeObject *>(object->objectProperty());
|
||||
QVERIFY(child != nullptr);
|
||||
|
@ -1293,7 +1293,7 @@ void tst_qqmllanguage::bindTypeToJSValue()
|
|||
MyQmlObject *object = root->findChild<MyQmlObject *>("urlProperty");
|
||||
QJSValue value = object->qjsvalue();
|
||||
const QUrl encoded = QUrl::fromEncoded("main.qml?with%3cencoded%3edata", QUrl::TolerantMode);
|
||||
QCOMPARE(value.toString(), component.url().resolved(encoded).toString());
|
||||
QCOMPARE(value.toString(), encoded.toString());
|
||||
} {
|
||||
MyQmlObject *object = root->findChild<MyQmlObject *>("objectProperty");
|
||||
QJSValue value = object->qjsvalue();
|
||||
|
@ -1468,7 +1468,7 @@ void tst_qqmllanguage::dynamicProperties()
|
|||
QCOMPARE(object->property("doubleProperty"), QVariant(-10.1));
|
||||
QCOMPARE(object->property("realProperty"), QVariant((qreal)-19.9));
|
||||
QCOMPARE(object->property("stringProperty"), QVariant("Hello World!"));
|
||||
QCOMPARE(object->property("urlProperty"), QVariant(testFileUrl("main.qml")));
|
||||
QCOMPARE(object->property("urlProperty"), QVariant(QUrl("main.qml")));
|
||||
QCOMPARE(object->property("colorProperty"), QVariant(QColor("red")));
|
||||
QCOMPARE(object->property("dateProperty"), QVariant(QDate(1945, 9, 2)));
|
||||
QCOMPARE(object->property("varProperty"), QVariant("Hello World!"));
|
||||
|
|
|
@ -1396,29 +1396,25 @@ void tst_qqmlproperty::write()
|
|||
{
|
||||
PropertyObject o;
|
||||
QQmlProperty p(&o, "url");
|
||||
const QUrl url = QUrl("main.qml");
|
||||
|
||||
QCOMPARE(p.write(QUrl("main.qml")), true);
|
||||
QCOMPARE(o.url(), QUrl("main.qml"));
|
||||
QCOMPARE(p.write(url), true);
|
||||
QCOMPARE(o.url(), url);
|
||||
|
||||
QQmlProperty p2(&o, "url", engine.rootContext());
|
||||
|
||||
QUrl result = engine.baseUrl().resolved(QUrl("main.qml"));
|
||||
QVERIFY(result != QUrl("main.qml"));
|
||||
|
||||
QCOMPARE(p2.write(QUrl("main.qml")), true);
|
||||
QCOMPARE(o.url(), result);
|
||||
QCOMPARE(p2.write(url), true);
|
||||
QCOMPARE(o.url(), url);
|
||||
}
|
||||
{ // static
|
||||
PropertyObject o;
|
||||
const QUrl url = QUrl("main.qml");
|
||||
|
||||
QCOMPARE(QQmlProperty::write(&o, "url", QUrl("main.qml")), true);
|
||||
QCOMPARE(o.url(), QUrl("main.qml"));
|
||||
QCOMPARE(QQmlProperty::write(&o, "url", url), true);
|
||||
QCOMPARE(o.url(), url);
|
||||
|
||||
QUrl result = engine.baseUrl().resolved(QUrl("main.qml"));
|
||||
QVERIFY(result != QUrl("main.qml"));
|
||||
|
||||
QCOMPARE(QQmlProperty::write(&o, "url", QUrl("main.qml"), engine.rootContext()), true);
|
||||
QCOMPARE(o.url(), result);
|
||||
QCOMPARE(QQmlProperty::write(&o, "url", url, engine.rootContext()), true);
|
||||
QCOMPARE(o.url(), url);
|
||||
}
|
||||
|
||||
// Char/string-property
|
||||
|
|
|
@ -227,7 +227,7 @@ Item {
|
|||
}
|
||||
|
||||
function test_clearSource() {
|
||||
compare(clearSource.source, Qt.resolvedUrl(srcImage))
|
||||
compare(clearSource.source, srcImage)
|
||||
compare(clearSource.width, 160)
|
||||
compare(clearSource.height, 120)
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ Item {
|
|||
}
|
||||
|
||||
function test_clearSource() {
|
||||
compare(clearSource.source, Qt.resolvedUrl("colors.png"))
|
||||
compare(clearSource.source, "colors.png")
|
||||
compare(clearSource.width, 120)
|
||||
compare(clearSource.height, 120)
|
||||
|
||||
|
@ -235,7 +235,7 @@ Item {
|
|||
img.source = row.source;
|
||||
}
|
||||
|
||||
compare(img.source, Qt.resolvedUrl(row.source))
|
||||
compare(img.source, row.source)
|
||||
compare(img.width, 300)
|
||||
compare(img.height, 300)
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ Item {
|
|||
}
|
||||
|
||||
function test_clearSource() {
|
||||
compare(clearSource.source, Qt.resolvedUrl(srcImage))
|
||||
compare(clearSource.source, srcImage)
|
||||
compare(clearSource.width, 59)
|
||||
compare(clearSource.height, 71)
|
||||
|
||||
|
|
|
@ -380,11 +380,11 @@ Item {
|
|||
function test_multipleDelegates_data() {
|
||||
return [
|
||||
{ y: 25, type: "Rectangle", value: "red" },
|
||||
{ y: 75, type: "Image", value: Qt.resolvedUrl("data/logo.png") },
|
||||
{ y: 75, type: "Image", value: "logo.png" },
|
||||
{ y: 125, type: "Text", value: "Hello" },
|
||||
{ y: 175, type: "Text", value: "World" },
|
||||
{ y: 225, type: "Rectangle", value: "green" },
|
||||
{ y: 275, type: "Image", value: Qt.resolvedUrl("data/logo.png") },
|
||||
{ y: 275, type: "Image", value: "logo.png" },
|
||||
{ y: 325, type: "Rectangle", value: "blue" },
|
||||
{ y: 375, type: "Item", value: "" }
|
||||
]
|
||||
|
|
|
@ -429,7 +429,7 @@ void tst_qquickborderimage::statusChanges_data()
|
|||
QTest::newRow("localfile") << testFileUrl("colors.png").toString() << 1 << false << QQuickImageBase::Ready;
|
||||
QTest::newRow("nofile") << "" << 0 << false << QQuickImageBase::Null;
|
||||
QTest::newRow("nonexistent") << testFileUrl("thisfiledoesnotexist.png").toString() << 1 << false << QQuickImageBase::Error;
|
||||
QTest::newRow("noprotocol") << QString("thisfiledoesnotexisteither.png") << 2 << false << QQuickImageBase::Error;
|
||||
QTest::newRow("noprotocol") << QString("thisfiledoesnotexisteither.png") << 1 << false << QQuickImageBase::Error;
|
||||
QTest::newRow("remote") << "/colors.png" << 2 << true << QQuickImageBase::Ready;
|
||||
}
|
||||
|
||||
|
|
|
@ -214,18 +214,13 @@ void tst_QQuickLoader::sourceOrComponent_data()
|
|||
QTest::addColumn<QUrl>("sourceUrl");
|
||||
QTest::addColumn<QString>("errorString");
|
||||
|
||||
auto encodedTestFileUrl = [&](const char *file)
|
||||
{
|
||||
return dataDirectoryUrl().resolved(QUrl(file));
|
||||
};
|
||||
|
||||
QTest::newRow("source") << "source" << "source: 'Rect120x60.qml'\n" << testFileUrl("Rect120x60.qml") << "";
|
||||
QTest::newRow("source with subdir") << "source" << "source: 'subdir/Test.qml'\n" << testFileUrl("subdir/Test.qml") << "";
|
||||
QTest::newRow("source with encoded subdir literal") << "source" << "source: 'subdir%2fTest.qml'\n" << encodedTestFileUrl("subdir%2FTest.qml") << "";
|
||||
QTest::newRow("source with encoded subdir optimized binding") << "source" << "source: 'subdir' + '%2fTest.qml'\n" << encodedTestFileUrl("subdir%2FTest.qml") << "";
|
||||
QTest::newRow("source with encoded subdir binding") << "source" << "source: encodeURIComponent('subdir/Test.qml')\n" << encodedTestFileUrl("subdir%2FTest.qml") << "";
|
||||
QTest::newRow("source") << "source" << "source: 'Rect120x60.qml'\n" << QUrl("Rect120x60.qml") << "";
|
||||
QTest::newRow("source with subdir") << "source" << "source: 'subdir/Test.qml'\n" << QUrl("subdir/Test.qml") << "";
|
||||
QTest::newRow("source with encoded subdir literal") << "source" << "source: 'subdir%2fTest.qml'\n" << QUrl("subdir%2FTest.qml") << "";
|
||||
QTest::newRow("source with encoded subdir optimized binding") << "source" << "source: 'subdir' + '%2fTest.qml'\n" << QUrl("subdir%2FTest.qml") << "";
|
||||
QTest::newRow("source with encoded subdir binding") << "source" << "source: encodeURIComponent('subdir/Test.qml')\n" << QUrl("subdir%2FTest.qml") << "";
|
||||
QTest::newRow("sourceComponent") << "component" << "Component { id: comp; Rectangle { width: 100; height: 50 } }\n sourceComponent: comp\n" << QUrl() << "";
|
||||
QTest::newRow("invalid source") << "source" << "source: 'IDontExist.qml'\n" << testFileUrl("IDontExist.qml")
|
||||
QTest::newRow("invalid source") << "source" << "source: 'IDontExist.qml'\n" << QUrl("IDontExist.qml")
|
||||
<< QString(testFileUrl("IDontExist.qml").toString() + ": No such file or directory");
|
||||
}
|
||||
|
||||
|
@ -809,7 +804,7 @@ void tst_QQuickLoader::deleteComponentCrash()
|
|||
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
||||
QCoreApplication::processEvents();
|
||||
QTRY_COMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1);
|
||||
QCOMPARE(loader->source(), testFileUrl("BlueRect.qml"));
|
||||
QCOMPARE(loader->source(), QUrl("BlueRect.qml"));
|
||||
}
|
||||
|
||||
void tst_QQuickLoader::nonItem()
|
||||
|
|
|
@ -1360,7 +1360,7 @@ void tst_qquickstates::urlResolution()
|
|||
QVERIFY(myType != nullptr && image1 != nullptr && image2 != nullptr && image3 != nullptr);
|
||||
|
||||
QQuickItemPrivate::get(myType)->setState("SetImageState");
|
||||
QUrl resolved = testFileUrl("Implementation/images/qt-logo.png");
|
||||
QUrl resolved = QUrl("images/qt-logo.png");
|
||||
QCOMPARE(image1->source(), resolved);
|
||||
QCOMPARE(image2->source(), resolved);
|
||||
QCOMPARE(image3->source(), resolved);
|
||||
|
|
|
@ -52,6 +52,6 @@ import QmlRuntime.Config 1.0
|
|||
Configuration {
|
||||
PartialScene {
|
||||
itemType: "QQuickItem"
|
||||
container: "content/resizeItemToWindow.qml"
|
||||
container: "qrc:/qt-project.org/QmlRuntime/conf/content/resizeItemToWindow.qml"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue