aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-11-10 21:01:35 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-11-11 11:23:37 +0100
commite2b87dda1fe4e8e22ea4231971085f4cd4852843 (patch)
tree5d2634f81256fc4f996d736da44810e0dc49e020 /src/quicktemplates2
parentb207f90c3074ef27b10c17cc719d83076bb3d78c (diff)
QQuickStackView: Allow URLs in createElement()
The value is intended to be a URL, therefore only accepting the string form is not enough. Task-number: QTBUG-88372 Change-Id: I4d31d1c5eacd49b7591f087c2e82c31b70a3bc1d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickstackview_p.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickstackview_p.cpp b/src/quicktemplates2/qquickstackview_p.cpp
index ce81a929..13e79e0e 100644
--- a/src/quicktemplates2/qquickstackview_p.cpp
+++ b/src/quicktemplates2/qquickstackview_p.cpp
@@ -42,6 +42,8 @@
#include <QtQml/qqmllist.h>
#include <QtQml/private/qv4qmlcontext_p.h>
#include <QtQml/private/qv4qobjectwrapper_p.h>
+#include <QtQml/private/qv4variantobject_p.h>
+#include <QtQml/private/qv4urlobject_p.h>
#include <QtQuick/private/qquickanimation_p.h>
#include <QtQuick/private/qquicktransition_p.h>
@@ -155,6 +157,13 @@ QQuickStackElement *QQuickStackViewPrivate::findElement(const QV4::Value &value)
return nullptr;
}
+static QUrl resolvedUrl(const QUrl &url, const QQmlRefPointer<QQmlContextData> &context)
+{
+ if (url.isRelative())
+ return context->resolvedUrl(url).toString();
+ return url;
+}
+
static QString resolvedUrl(const QString &str, const QQmlRefPointer<QQmlContextData> &context)
{
QUrl url(str);
@@ -170,6 +179,17 @@ QQuickStackElement *QQuickStackViewPrivate::createElement(const QV4::Value &valu
return QQuickStackElement::fromString(resolvedUrl(s->toQString(), context), q, error);
if (const QV4::QObjectWrapper *o = value.as<QV4::QObjectWrapper>())
return QQuickStackElement::fromObject(o->object(), q, error);
+ if (const QV4::UrlObject *u = value.as<QV4::UrlObject>())
+ return QQuickStackElement::fromString(resolvedUrl(u->href(), context), q, error);
+
+ if (const QV4::Object *v = value.as<QV4::Object>()) {
+ const QVariant data = v->engine()->toVariant(value, QMetaType::QUrl);
+ if (data.typeId() == QMetaType::QUrl) {
+ return QQuickStackElement::fromString(resolvedUrl(data.toUrl(), context).toString(), q,
+ error);
+ }
+ }
+
return nullptr;
}