diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2011-12-14 11:27:18 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-15 12:17:28 +0100 |
commit | b21f63763d43cecf96c9359d95705411dbdc4ecd (patch) | |
tree | a7172e42145431a0b0cede37a02d5517f6f98c09 /tests/auto/declarative | |
parent | b6291c914d9a6f24dbfb0e92e8caedae889b709b (diff) |
Add support for QUrl types to V4
Extended the V4 instruction set with instructions to
`fast convert' url registers to string and bool registers
and `resolve' urls using QDeclarativeContext::resolvedUrl.
Also, made IR::UrlType a special `string' type. It's a little trick
to ensure that the compiler will generate correct conversions for
the binary expressions.
Change-Id: Ibc9e5b99302bd513f0cc52b598a1b198b11d4d30
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/declarative')
3 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/urlProperty.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/urlProperty.1.qml new file mode 100644 index 0000000000..451cb03206 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/urlProperty.1.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + property bool result + urlProperty: stringProperty + "/index.html" + intProperty: if (urlProperty) 123; else 321 + value: urlProperty == stringProperty + "/index.html" + result: urlProperty == urlProperty +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index cd5bac5253..2f1d3f9414 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -93,6 +93,7 @@ class MyQmlObject : public QObject Q_PROPERTY(int value READ value WRITE setValue) Q_PROPERTY(int console READ console CONSTANT) Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged) + Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty NOTIFY urlChanged) Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged) Q_PROPERTY(QDeclarativeListProperty<QObject> objectListProperty READ objectListProperty CONSTANT) Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty) @@ -118,6 +119,15 @@ public: emit stringChanged(); } + QUrl urlProperty() const { return m_url; } + void setUrlProperty(const QUrl &url) + { + if (url == m_url) + return; + m_url = url; + emit urlChanged(); + } + QObject *objectProperty() const { return m_object; } void setObjectProperty(QObject *obj) { if (obj == m_object) @@ -171,6 +181,7 @@ signals: void basicSignal(); void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e); void stringChanged(); + void urlChanged(); void objectChanged(); void anotherBasicSignal(); void thirdBasicSignal(); @@ -196,6 +207,7 @@ private: QObject *m_object; QString m_string; + QUrl m_url; QList<QObject *> m_objectQList; int m_value; int m_resetProperty; diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index a01c80b7e3..f3d810ed9d 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -220,6 +220,7 @@ private slots: void aliasWritesOverrideBindings(); void aliasToCompositeElement(); void realToInt(); + void urlProperty(); void dynamicString(); void include(); void signalHandlers(); @@ -5462,6 +5463,21 @@ void tst_qdeclarativeecmascript::realToInt() QMetaObject::invokeMethod(object, "test2"); QCOMPARE(object->value(), int(8)); } + +void tst_qdeclarativeecmascript::urlProperty() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("urlProperty.1.qml")); + MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); + QVERIFY(object != 0); + object->setStringProperty("http://qt-project.org"); + QCOMPARE(object->urlProperty(), QUrl("http://qt-project.org/index.html")); + QCOMPARE(object->intProperty(), 123); + QCOMPARE(object->value(), 1); + QCOMPARE(object->property("result").toBool(), true); + } +} + void tst_qdeclarativeecmascript::dynamicString() { QDeclarativeComponent component(&engine, TEST_FILE("dynamicString.qml")); |