summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qmlcontext.cpp16
-rw-r--r--src/declarative/qml/qmlcontext_p.h3
-rw-r--r--tests/auto/declarative/behaviors/data/simple.qml5
-rw-r--r--tests/auto/declarative/behaviors/tst_behaviors.cpp43
-rw-r--r--tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp49
5 files changed, 97 insertions, 19 deletions
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp
index d37d959..f8e685a 100644
--- a/src/declarative/qml/qmlcontext.cpp
+++ b/src/declarative/qml/qmlcontext.cpp
@@ -88,18 +88,6 @@ void QmlContextPrivate::addScript(const QString &script, QObject *scopeObject,
scripts.append(scope);
}
-void QmlContextPrivate::dump()
-{
- dump(0);
-}
-
-void QmlContextPrivate::dump(int depth)
-{
- QByteArray ba(depth * 4, ' ');
- if (parent)
- parent->d_func()->dump(depth + 1);
-}
-
void QmlContextPrivate::destroyed(ContextGuard *guard)
{
Q_Q(QmlContext);
@@ -382,8 +370,8 @@ void QmlContext::setContextProperty(const QString &name, const QVariant &value)
if (d->notifyIndex == -1)
d->notifyIndex = this->metaObject()->methodCount();
- if (QmlMetaType::isObject(value.userType())) {
- QObject *o = QmlMetaType::toQObject(value);
+ if (d->engine && QmlEnginePrivate::get(d->engine)->isObject(value.userType())) {
+ QObject *o = *(QObject **)value.constData();
setContextProperty(name, o);
} else {
diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h
index cc8fcc6..7f9be0f 100644
--- a/src/declarative/qml/qmlcontext_p.h
+++ b/src/declarative/qml/qmlcontext_p.h
@@ -101,9 +101,6 @@ public:
void init();
- void dump();
- void dump(int depth);
-
void invalidateEngines();
void refreshExpressions();
QSet<QmlContext *> childContexts;
diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml
index a715f7b..37c3915 100644
--- a/tests/auto/declarative/behaviors/data/simple.qml
+++ b/tests/auto/declarative/behaviors/data/simple.qml
@@ -6,7 +6,10 @@ Rectangle {
id: rect
objectName: "MyRect"
width: 100; height: 100; color: "green"
- x: Behavior { NumberAnimation { duration: 200; } }
+ x: Behavior {
+ objectName: "MyBehavior";
+ NumberAnimation { duration: 200; }
+ }
}
MouseRegion {
id: clicker
diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp
index 9803a9d..29c631d 100644
--- a/tests/auto/declarative/behaviors/tst_behaviors.cpp
+++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp
@@ -43,6 +43,7 @@
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qmlview.h>
#include <private/qmlgraphicsrectangle_p.h>
+#include <private/qmlbehavior_p.h>
#include <private/qmlanimation_p.h>
class tst_behaviors : public QObject
@@ -60,6 +61,9 @@ private slots:
void replaceBinding();
//void transitionOverrides();
void group();
+ void emptyBehavior();
+ void nonSelectingBehavior();
+ void reassignedAnimation();
};
void tst_behaviors::simpleBehavior()
@@ -68,6 +72,7 @@ void tst_behaviors::simpleBehavior()
QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml"));
QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create());
QVERIFY(rect);
+ QVERIFY(qobject_cast<QmlBehavior*>(rect->findChild<QmlBehavior*>("MyBehavior"))->animation());
rect->setState("moved");
QTest::qWait(100);
@@ -189,6 +194,44 @@ void tst_behaviors::group()
}
}
+void tst_behaviors::emptyBehavior()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/empty.qml"));
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("moved");
+ qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x();
+ QCOMPARE(x, qreal(200)); //should change immediately
+}
+
+void tst_behaviors::nonSelectingBehavior()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting.qml"));
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("moved");
+ qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x();
+ QCOMPARE(x, qreal(200)); //should change immediately
+}
+
+void tst_behaviors::reassignedAnimation()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/reassignedAnimation.qml"));
+ QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior.");
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("moved");
+ QTest::qWait(200 + 100);
+ qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x();
+ QCOMPARE(x, qreal(200)); //i.e. the right behavior has been triggered
+}
+
QTEST_MAIN(tst_behaviors)
#include "tst_behaviors.moc"
diff --git a/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp b/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp
index 69d9091..3c60b2b 100644
--- a/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp
+++ b/tests/auto/declarative/qmlcontext/tst_qmlcontext.cpp
@@ -44,6 +44,7 @@
#include <QmlEngine>
#include <QmlContext>
#include <QmlComponent>
+#include <QmlExpression>
class tst_qmlcontext : public QObject
{
@@ -58,6 +59,7 @@ private slots:
void parentContext();
void setContextProperty();
void addDefaultObject();
+ void destruction();
private:
QmlEngine engine;
@@ -111,6 +113,14 @@ void tst_qmlcontext::resolvedUrl()
QCOMPARE(ctxt2.resolvedUrl(QUrl("main2.qml")), QUrl());
}
+
+ // Absolute
+ {
+ QmlContext ctxt(&engine);
+
+ QCOMPARE(ctxt.resolvedUrl(QUrl("http://www.nokia.com/main2.qml")), QUrl("http://www.nokia.com/main2.qml"));
+ QCOMPARE(ctxt.resolvedUrl(QUrl("file:///main2.qml")), QUrl("file:///main2.qml"));
+ }
}
void tst_qmlcontext::engineMethod()
@@ -256,10 +266,10 @@ void tst_qmlcontext::setContextProperty()
// Static context properties
ctxt.setContextProperty("a", QVariant(10));
ctxt.setContextProperty("b", QVariant(9));
+ ctxt2.setContextProperty("d", &obj2);
ctxt2.setContextProperty("b", QVariant(19));
ctxt2.setContextProperty("c", QVariant(QString("Hello World!")));
ctxt.setContextProperty("d", &obj1);
- ctxt2.setContextProperty("d", &obj2);
ctxt.setContextProperty("e", &obj1);
TEST_CONTEXT_PROPERTY(&ctxt2, a, QVariant(10));
@@ -334,6 +344,26 @@ void tst_qmlcontext::setContextProperty()
delete obj;
}
+
+ // Setting an object-variant context property
+ {
+ QmlComponent component(&engine);
+ component.setData("import Qt 4.6; Object { id: root; property int a: 10; property int test: ctxtProp.a; property var obj: root; }", QUrl());
+
+ QmlContext ctxt(engine.rootContext());
+ ctxt.setContextProperty("ctxtProp", QVariant());
+
+ QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:1: TypeError: Result of expression 'ctxtProp' [undefined] is not an object.");
+ QObject *obj = component.create(&ctxt);
+
+ QVariant v = obj->property("obj");
+
+ ctxt.setContextProperty("ctxtProp", v);
+
+ QCOMPARE(obj->property("test"), QVariant(10));
+
+ delete obj;
+ }
}
void tst_qmlcontext::addDefaultObject()
@@ -382,6 +412,23 @@ void tst_qmlcontext::addDefaultObject()
}
}
+void tst_qmlcontext::destruction()
+{
+ QmlContext *ctxt = new QmlContext(&engine);
+
+ QObject obj;
+ QmlEngine::setContextForObject(&obj, ctxt);
+ QmlExpression expr(ctxt, "a", 0);
+
+ QCOMPARE(ctxt, QmlEngine::contextForObject(&obj));
+ QCOMPARE(ctxt, expr.context());
+
+ delete ctxt; ctxt = 0;
+
+ QCOMPARE(ctxt, QmlEngine::contextForObject(&obj));
+ QCOMPARE(ctxt, expr.context());
+}
+
QTEST_MAIN(tst_qmlcontext)
#include "tst_qmlcontext.moc"