From 10b440d4621dc5b6b0380c566458facef2942085 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 2 Sep 2009 10:18:14 +1000 Subject: Rework script binding method --- demos/declarative/samegame/content/samegame.js | 3 + src/declarative/qml/qmlengine.cpp | 183 ++++++++++++++----------- src/declarative/qml/qmlengine_p.h | 21 +++ 3 files changed, 126 insertions(+), 81 deletions(-) diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index f04fb4c..91a436f 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -15,6 +15,7 @@ function index(xIdx,yIdx){ function initBoard() { + var a = new Date; for(i = 0; i, bool> FunctionCache; Q_GLOBAL_STATIC(FunctionCache, functionCache); +QScriptClass::QueryFlags +QmlEnginePrivate::queryContext(const QString &propName, uint *id, + QmlContext *bindContext) +{ + resolveData.safetyCheckId++; + *id = resolveData.safetyCheckId; + resolveData.clear(); + + QScriptClass::QueryFlags rv = 0; + QHash::Iterator contextProperty = + bindContext->d_func()->propertyNames.find(propName); + + if (contextProperty != bindContext->d_func()->propertyNames.end()) { + rv |= QScriptClass::HandlesReadAccess; + + resolveData.context = bindContext; + resolveData.contextIndex = *contextProperty; + + return rv; + } + + for (int ii = 0; !rv && ii < bindContext->d_func()->defaultObjects.count(); ++ii) { + rv = queryObject(propName, id, + bindContext->d_func()->defaultObjects.at(ii)); + } + + return rv; +} + +QScriptValue +QmlEnginePrivate::propertyContext(const QScriptString &name, + QmlContext *bindContext, + uint id) +{ + Q_ASSERT(id == resolveData.safetyCheckId); + + + if (resolveData.context) { + QmlContext *bindContext = resolveData.context; + QmlContextPrivate *contextPrivate = bindContext->d_func(); + int index = resolveData.contextIndex; + + QScriptValue rv; + if (index < contextPrivate->idValueCount) { + rv = scriptEngine.newObject(objectClass, scriptEngine.newVariant(QVariant::fromValue(contextPrivate->idValues[index].data()))); + } else { + QVariant value = contextPrivate->propertyValues.at(index); + if (QmlMetaType::isObject(value.userType())) { + rv = scriptEngine.newObject(objectClass, scriptEngine.newVariant(value)); + } else { + rv = scriptEngine.newVariant(value); + } + } + capturedProperties << QmlEnginePrivate::CapturedProperty(bindContext, -1, index + contextPrivate->notifyIndex); + return rv; + + } else { + + return propertyObject(name, resolveData.object, id); + + } + + return QScriptValue(); +} + +void QmlEnginePrivate::setPropertyContext(const QScriptValue &value, uint id) +{ + // As context properties cannot be written, we can assume that the + // write is a object property write + setPropertyObject(value, id); +} + +void QmlEnginePrivate::setPropertyObject(const QScriptValue &value, uint id) +{ + Q_ASSERT(id == resolveData.safetyCheckId); + Q_Q(QmlEngine); + + resolveData.property.write(QmlScriptClass::toVariant(q, value)); +} + QScriptClass::QueryFlags QmlEnginePrivate::queryObject(const QString &propName, uint *id, QObject *obj) { + resolveData.safetyCheckId++; + *id = resolveData.safetyCheckId; + resolveData.clear(); + QScriptClass::QueryFlags rv = 0; QmlContext *ctxt = QmlEngine::contextForObject(obj); if (!ctxt) ctxt = rootContext; QmlMetaProperty prop(obj, propName, ctxt); + if (prop.type() == QmlMetaProperty::Invalid) { QPair key = qMakePair(obj->metaObject(), propName); @@ -232,12 +317,13 @@ QmlEnginePrivate::queryObject(const QString &propName, } if (isFunction) { - *id = QmlScriptClass::FunctionId; + resolveData.object = obj; + resolveData.isFunction = true; rv |= QScriptClass::HandlesReadAccess; - } + } } else { - *id = QmlScriptClass::PropertyId; - *id |= prop.save(); + resolveData.object = obj; + resolveData.property = prop; rv |= QScriptClass::HandlesReadAccess; if (prop.isWritable()) @@ -257,15 +343,16 @@ Q_DECLARE_METATYPE(QmlValueTypeReference); QScriptValue QmlEnginePrivate::propertyObject(const QScriptString &propName, QObject *obj, uint id) { - if (id == QmlScriptClass::FunctionId) { + Q_ASSERT(id == resolveData.safetyCheckId); + Q_ASSERT(resolveData.object); + + if (resolveData.isFunction) { + // ### Optimize QScriptValue sobj = scriptEngine.newQObject(obj); QScriptValue func = sobj.property(propName); return func; } else { - QmlMetaProperty prop; - prop.restore(id, obj); - if (!prop.isValid()) - return QScriptValue(); + const QmlMetaProperty &prop = resolveData.property; if (prop.needsChangedNotifier()) capturedProperties << CapturedProperty(prop); @@ -856,23 +943,11 @@ QmlContextScriptClass::queryProperty(const QScriptValue &object, Q_UNUSED(flags); QmlContext *bindContext = static_cast(object.data().toQObject()); - QueryFlags rv = 0; QString propName = name.toString(); - *id = InvalidId; - if (bindContext->d_func()->propertyNames.contains(propName)) { - rv |= HandlesReadAccess; - *id = VariantPropertyId; - } - - for (int ii = 0; !rv && ii < bindContext->d_func()->defaultObjects.count(); ++ii) { - rv = QmlEnginePrivate::get(engine)->queryObject(propName, id, bindContext->d_func()->defaultObjects.at(ii)); - if (rv) - *id |= (ii << 24); - } - - return rv; + QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); + return ep->queryContext(propName, id, bindContext); } QScriptValue QmlContextScriptClass::property(const QScriptValue &object, @@ -882,46 +957,8 @@ QScriptValue QmlContextScriptClass::property(const QScriptValue &object, QmlContext *bindContext = static_cast(object.data().toQObject()); - uint basicId = id & QmlScriptClass::ClassIdMask; - - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); - - switch (basicId) { - case VariantPropertyId: - { - QmlContextPrivate *contextPrivate = bindContext->d_func(); - QString propName = name.toString(); - int index = contextPrivate->propertyNames.value(propName); - - QScriptValue rv; - if (index < contextPrivate->idValueCount) { - rv = scriptEngine->newObject(ep->objectClass, scriptEngine->newVariant(QVariant::fromValue(contextPrivate->idValues[index].data()))); - } else { - QVariant value = contextPrivate->propertyValues.at(index); - if (QmlMetaType::isObject(value.userType())) { - rv = scriptEngine->newObject(ep->objectClass, scriptEngine->newVariant(value)); - } else { - rv = scriptEngine->newVariant(value); - } - } - ep->capturedProperties << QmlEnginePrivate::CapturedProperty(bindContext, -1, index + bindContext->d_func()->notifyIndex); - return rv; - } - default: - { - int objId = (id & ClassIdSelectorMask) >> 24; - QObject *obj = bindContext->d_func()->defaultObjects.at(objId); - QScriptValue rv = ep->propertyObject(name, obj, - id & ~QmlScriptClass::ClassIdSelectorMask); - if (rv.isValid()) { - return rv; - } - break; - } - } - - return QScriptValue(); + return ep->propertyContext(name, bindContext, id); } void QmlContextScriptClass::setProperty(QScriptValue &object, @@ -931,17 +968,7 @@ void QmlContextScriptClass::setProperty(QScriptValue &object, { Q_UNUSED(name); - QmlContext *bindContext = - static_cast(object.data().toQObject()); - - int objIdx = (id & QmlScriptClass::ClassIdSelectorMask) >> 24; - QObject *obj = bindContext->d_func()->defaultObjects.at(objIdx); - - QmlMetaProperty prop; - prop.restore(id, obj); - - QVariant v = QmlScriptClass::toVariant(engine, value); - prop.write(v); + QmlEnginePrivate::get(engine)->setPropertyContext(value, id); } ///////////////////////////////////////////////////////////// @@ -1119,14 +1146,8 @@ void QmlObjectScriptClass::setProperty(QScriptValue &object, const QScriptValue &value) { Q_UNUSED(name); - - QObject *obj = object.data().toQObject(); - - QmlMetaProperty prop; - prop.restore(id, obj); - - QVariant v = QmlScriptClass::toVariant(engine, value); - prop.write(v); + Q_UNUSED(object); + QmlEnginePrivate::get(engine)->setPropertyObject(value, id); } diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index b595e7c..2c7409b 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -97,10 +97,17 @@ public: void init(); + QScriptClass::QueryFlags queryContext(const QString &name, uint *id, + QmlContext *); + QScriptValue propertyContext(const QScriptString &propName, QmlContext *, + uint id); + void setPropertyContext(const QScriptValue &, uint id); QScriptClass::QueryFlags queryObject(const QString &name, uint *id, QObject *); QScriptValue propertyObject(const QScriptString &propName, QObject *, uint id = 0); + void setPropertyObject(const QScriptValue &, uint id); + struct CapturedProperty { CapturedProperty(QObject *o, int c, int n) @@ -120,6 +127,20 @@ public: QScriptEngineDebugger *debugger; #endif + struct ResolveData { + ResolveData() : safetyCheckId(0) {} + int safetyCheckId; + + void clear() { + object = 0; context = 0; contextIndex = -1; isFunction = false; + } + QObject *object; + QmlContext *context; + + int contextIndex; + bool isFunction; + QmlMetaProperty property; + } resolveData; QmlContextScriptClass *contextClass; QmlObjectScriptClass *objectClass; QmlValueTypeScriptClass *valueTypeClass; -- cgit v0.12 From ed417f18023f1bbd0636c9724b8f79e08c77d51a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 3 Sep 2009 09:06:46 +1000 Subject: Add basic autotests for state handling. --- .../auto/declarative/states/data/basicBinding.qml | 12 + .../auto/declarative/states/data/basicBinding2.qml | 12 + .../auto/declarative/states/data/basicBinding3.qml | 13 + .../auto/declarative/states/data/basicBinding4.qml | 17 ++ .../auto/declarative/states/data/basicChanges.qml | 10 + .../auto/declarative/states/data/basicChanges2.qml | 15 ++ .../auto/declarative/states/data/basicChanges3.qml | 15 ++ .../declarative/states/data/basicExtension.qml | 16 ++ .../auto/declarative/states/data/fakeExtension.qml | 16 ++ tests/auto/declarative/states/states.pro | 6 + tests/auto/declarative/states/tst_states.cpp | 267 +++++++++++++++++++++ 11 files changed, 399 insertions(+) create mode 100644 tests/auto/declarative/states/data/basicBinding.qml create mode 100644 tests/auto/declarative/states/data/basicBinding2.qml create mode 100644 tests/auto/declarative/states/data/basicBinding3.qml create mode 100644 tests/auto/declarative/states/data/basicBinding4.qml create mode 100644 tests/auto/declarative/states/data/basicChanges.qml create mode 100644 tests/auto/declarative/states/data/basicChanges2.qml create mode 100644 tests/auto/declarative/states/data/basicChanges3.qml create mode 100644 tests/auto/declarative/states/data/basicExtension.qml create mode 100644 tests/auto/declarative/states/data/fakeExtension.qml create mode 100644 tests/auto/declarative/states/states.pro create mode 100644 tests/auto/declarative/states/tst_states.cpp diff --git a/tests/auto/declarative/states/data/basicBinding.qml b/tests/auto/declarative/states/data/basicBinding.qml new file mode 100644 index 0000000..930a6b2 --- /dev/null +++ b/tests/auto/declarative/states/data/basicBinding.qml @@ -0,0 +1,12 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + + property color sourceColor: "blue" + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: MyRectangle; color: sourceColor } + } +} diff --git a/tests/auto/declarative/states/data/basicBinding2.qml b/tests/auto/declarative/states/data/basicBinding2.qml new file mode 100644 index 0000000..6bfaf5a --- /dev/null +++ b/tests/auto/declarative/states/data/basicBinding2.qml @@ -0,0 +1,12 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + + property color sourceColor: "red" + width: 100; height: 100 + color: sourceColor + states: State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue" } + } +} \ No newline at end of file diff --git a/tests/auto/declarative/states/data/basicBinding3.qml b/tests/auto/declarative/states/data/basicBinding3.qml new file mode 100644 index 0000000..344bfae --- /dev/null +++ b/tests/auto/declarative/states/data/basicBinding3.qml @@ -0,0 +1,13 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + + property color sourceColor: "red" + property color sourceColor2: "blue" + width: 100; height: 100 + color: sourceColor + states: State { + name: "blue" + PropertyChanges { target: MyRectangle; color: sourceColor2 } + } +} \ No newline at end of file diff --git a/tests/auto/declarative/states/data/basicBinding4.qml b/tests/auto/declarative/states/data/basicBinding4.qml new file mode 100644 index 0000000..f0b72bd --- /dev/null +++ b/tests/auto/declarative/states/data/basicBinding4.qml @@ -0,0 +1,17 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + + property color sourceColor: "blue" + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: MyRectangle; color: sourceColor } + }, + State { + name: "green" + PropertyChanges { target: MyRectangle; color: "green" } + }] +} diff --git a/tests/auto/declarative/states/data/basicChanges.qml b/tests/auto/declarative/states/data/basicChanges.qml new file mode 100644 index 0000000..8d560c6 --- /dev/null +++ b/tests/auto/declarative/states/data/basicChanges.qml @@ -0,0 +1,10 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue" } + } +} \ No newline at end of file diff --git a/tests/auto/declarative/states/data/basicChanges2.qml b/tests/auto/declarative/states/data/basicChanges2.qml new file mode 100644 index 0000000..0f8783a --- /dev/null +++ b/tests/auto/declarative/states/data/basicChanges2.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue" } + }, + State { + name: "green" + PropertyChanges { target: MyRectangle; color: "green" } + }] +} \ No newline at end of file diff --git a/tests/auto/declarative/states/data/basicChanges3.qml b/tests/auto/declarative/states/data/basicChanges3.qml new file mode 100644 index 0000000..2a5ca5d --- /dev/null +++ b/tests/auto/declarative/states/data/basicChanges3.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue" } + }, + State { + name: "bordered" + PropertyChanges { target: MyRectangle; border.width: 2 } + }] +} diff --git a/tests/auto/declarative/states/data/basicExtension.qml b/tests/auto/declarative/states/data/basicExtension.qml new file mode 100644 index 0000000..230e00b --- /dev/null +++ b/tests/auto/declarative/states/data/basicExtension.qml @@ -0,0 +1,16 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue" } + }, + State { + name: "bordered" + extend: "blue" + PropertyChanges { target: MyRectangle; border.width: 2 } + }] +} \ No newline at end of file diff --git a/tests/auto/declarative/states/data/fakeExtension.qml b/tests/auto/declarative/states/data/fakeExtension.qml new file mode 100644 index 0000000..3d85c4f --- /dev/null +++ b/tests/auto/declarative/states/data/fakeExtension.qml @@ -0,0 +1,16 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue" } + }, + State { + name: "green" + extend: "blue" + PropertyChanges { target: MyRectangle; color: "green" } + }] +} \ No newline at end of file diff --git a/tests/auto/declarative/states/states.pro b/tests/auto/declarative/states/states.pro new file mode 100644 index 0000000..0474ea5 --- /dev/null +++ b/tests/auto/declarative/states/states.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_states.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp new file mode 100644 index 0000000..3a61bd6 --- /dev/null +++ b/tests/auto/declarative/states/tst_states.cpp @@ -0,0 +1,267 @@ +#include +#include +#include +#include + +class tst_states : public QObject +{ + Q_OBJECT +public: + tst_states() {} + +private slots: + void basicChanges(); + void basicExtension(); + void basicBinding(); +}; + +void tst_states::basicChanges() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges2.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges3.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("bordered"); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),2); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + //### we should be checking that this is an implicit rather than explicit 1 (which currently fails) + + rect->setState("bordered"); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),2); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),1); + + } +} + +void tst_states::basicExtension() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicExtension.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("bordered"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),2); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),1); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("bordered"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),2); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/fakeExtension.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + } +} + +void tst_states::basicBinding() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor", QColor("green")); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("yellow")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding2.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor", QColor("green")); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("green")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("yellow")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("yellow")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding3.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor", QColor("green")); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor", QColor("red")); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor2", QColor("yellow")); + QCOMPARE(rect->color(),QColor("yellow")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor2", QColor("green")); + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("yellow")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding4.qml"); + QFxRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("yellow")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + rect->setProperty("sourceColor", QColor("purple")); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("purple")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + } +} + +QTEST_MAIN(tst_states) + +#include "tst_states.moc" -- cgit v0.12 From 48b47f9d242f76e944986df08a16c083bce47bef Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 3 Sep 2009 09:32:38 +1000 Subject: Make it easier to test examples with EGL. Currently -graphicssystem opengl is not very reliable with EGL, so we've added a -opengl option to qmlviewer which sets the viewport of the view to a QGLWidget and allows for GL testing. --- tools/qmlviewer/main.cpp | 5 +++++ tools/qmlviewer/qmlviewer.cpp | 18 ++++++++++++++++++ tools/qmlviewer/qmlviewer.h | 1 + tools/qmlviewer/qmlviewer.pro | 5 +++++ 4 files changed, 29 insertions(+) diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index a4ed054..87d1232 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -41,6 +41,7 @@ void usage() qWarning(" -netcache ......................... set disk cache to size bytes"); qWarning(" -translation ........... set the language to run in"); qWarning(" -L ........................... prepend to the library search path"); + qWarning(" -opengl .................................. use a QGLWidget for the viewport"); qWarning(" "); qWarning(" Press F1 for interactive help"); exit(1); @@ -79,6 +80,7 @@ int main(int argc, char ** argv) bool devkeys = false; int cache = 0; QString translationFile; + bool useGL = false; for (int i = 1; i < argc; ++i) { QString arg = argv[i]; @@ -114,6 +116,8 @@ int main(int argc, char ** argv) usage(); translationFile = argv[i + 1]; ++i; + } else if (arg == "-opengl") { + useGL = true; } else if (arg == "-L") { libraries << QString(argv[++i]); } else if (arg[0] != '-') { @@ -130,6 +134,7 @@ int main(int argc, char ** argv) } QmlViewer viewer(0, frameless ? Qt::FramelessWindowHint : Qt::Widget); + viewer.setUseGL(useGL); foreach (QString lib, libraries) viewer.addLibraryPath(lib); viewer.setNetworkCacheSize(cache); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 272ebcb..3ae9a97 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -45,6 +45,10 @@ #include #include "proxysettings.h" +#ifdef GL_SUPPORTED +#include +#endif + QT_BEGIN_NAMESPACE class PreviewDeviceSkin : public DeviceSkin @@ -1003,6 +1007,20 @@ void QmlViewer::setNetworkCacheSize(int size) } } +void QmlViewer::setUseGL(bool useGL) +{ +#ifdef GL_SUPPORTED + if (useGL) { + QGLFormat format = QGLFormat::defaultFormat(); + format.setSampleBuffers(false); + + QGLWidget *glWidget = new QGLWidget(format); + glWidget->setAutoFillBackground(false); + canvas->setViewport(glWidget); + } +#endif +} + QT_END_NAMESPACE #include "qmlviewer.moc" diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index c03c09f..e85acfa 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -43,6 +43,7 @@ public: void setDeviceKeys(bool); void setNetworkCacheSize(int size); void addLibraryPath(const QString& lib); + void setUseGL(bool use); QStringList builtinSkins() const; diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index bcf361e..77cae97 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -7,6 +7,11 @@ QT += declarative \ network \ sql +contains(QT_CONFIG, opengl) { + QT += opengl + DEFINES += GL_SUPPORTED +} + # Input HEADERS += qmlviewer.h \ proxysettings.h -- cgit v0.12 From b9c834048d6dc6e04567c1c73212ecb1b9c96664 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 3 Sep 2009 10:14:54 +1000 Subject: Add QML enum support Enums are accessed as . Currently this is highly unoptimal - enum assignments are not detected in the compiler, nor are they cached in the script engine. --- src/declarative/qml/qmlcompiler.cpp | 2 + src/declarative/qml/qmlcompiler_p.h | 1 + src/declarative/qml/qmlcomponent.cpp | 1 + src/declarative/qml/qmlcontext_p.h | 2 + src/declarative/qml/qmlengine.cpp | 135 ++++++++++++++++++--- src/declarative/qml/qmlengine_p.h | 33 ++++- tests/auto/declarative/qmlbindengine/enums.1.qml | 20 +++ tests/auto/declarative/qmlbindengine/testtypes.h | 19 +++ .../qmlbindengine/tst_qmlbindengine.cpp | 19 +++ 9 files changed, 213 insertions(+), 19 deletions(-) create mode 100644 tests/auto/declarative/qmlbindengine/enums.1.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index c0f7bfd..6519dff 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -642,6 +642,8 @@ void QmlCompiler::compileTree(Object *tree) def.type = QmlInstruction::SetDefault; output->bytecode << def; + output->imports = unit->imports; + if (tree->metatype) static_cast(output->root) = *tree->metaObject(); else diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h index c42c2d9..83c415c 100644 --- a/src/declarative/qml/qmlcompiler_p.h +++ b/src/declarative/qml/qmlcompiler_p.h @@ -76,6 +76,7 @@ public: QByteArray name; QUrl url; + QmlEnginePrivate::Imports imports; struct TypeReference { diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index c844a32..e897cce 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -488,6 +488,7 @@ QObject *QmlComponent::beginCreate(QmlContext *context) static_cast(QObjectPrivate::get(context)); QmlContext *ctxt = new QmlContext(context, 0, true); static_cast(ctxt->d_func())->url = d->cc->url; + static_cast(ctxt->d_func())->imports = d->cc->imports; QmlVME vme; QObject *rv = vme.run(ctxt, d->cc, d->start, d->count); diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index 84d990c..b305408 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -60,6 +60,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -91,6 +92,7 @@ public: QScriptValueList scopeChain; QUrl url; + QmlEnginePrivate::Imports imports; void init(); diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 0d6e281..3d8b2c4 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -181,6 +181,7 @@ void QmlEnginePrivate::init() contextClass = new QmlContextScriptClass(q); objectClass = new QmlObjectScriptClass(q); valueTypeClass = new QmlValueTypeScriptClass(q); + typeNameClass = new QmlTypeNameScriptClass(q); rootContext = new QmlContext(q,true); #ifdef QT_SCRIPTTOOLS_LIB if (qmlDebugger()){ @@ -211,10 +212,22 @@ QmlEnginePrivate::CapturedProperty::CapturedProperty(const QmlMetaProperty &p) { } -//////////////////////////////////////////////////////////////////// -typedef QHash, bool> FunctionCache; -Q_GLOBAL_STATIC(FunctionCache, functionCache); +struct QmlTypeNameBridge +{ + QObject *object; + QmlType *type; + QmlEnginePrivate::ImportedNamespace *ns; +}; +Q_DECLARE_METATYPE(QmlTypeNameBridge); + +struct QmlValueTypeReference { + QmlValueType *type; + QGuard object; + int property; +}; +Q_DECLARE_METATYPE(QmlValueTypeReference); +//////////////////////////////////////////////////////////////////// QScriptClass::QueryFlags QmlEnginePrivate::queryContext(const QString &propName, uint *id, QmlContext *bindContext) @@ -223,19 +236,32 @@ QmlEnginePrivate::queryContext(const QString &propName, uint *id, *id = resolveData.safetyCheckId; resolveData.clear(); - QScriptClass::QueryFlags rv = 0; QHash::Iterator contextProperty = bindContext->d_func()->propertyNames.find(propName); if (contextProperty != bindContext->d_func()->propertyNames.end()) { - rv |= QScriptClass::HandlesReadAccess; resolveData.context = bindContext; resolveData.contextIndex = *contextProperty; - return rv; + return QScriptClass::HandlesReadAccess; } + QmlType *type = 0; ImportedNamespace *ns = 0; + if (currentExpression && bindContext == currentExpression->context() && + propName.at(0).isUpper() && resolveType(bindContext->d_func()->imports, propName.toUtf8(), &type, 0, 0, 0, &ns)) { + + if (type || ns) { + // Must be either an attached property, or an enum + resolveData.object = bindContext->d_func()->defaultObjects.first(); + resolveData.type = type; + resolveData.ns = ns; + return QScriptClass::HandlesReadAccess; + } + + } + + QScriptClass::QueryFlags rv = 0; for (int ii = 0; !rv && ii < bindContext->d_func()->defaultObjects.count(); ++ii) { rv = queryObject(propName, id, bindContext->d_func()->defaultObjects.at(ii)); @@ -252,7 +278,14 @@ QmlEnginePrivate::propertyContext(const QScriptString &name, Q_ASSERT(id == resolveData.safetyCheckId); - if (resolveData.context) { + if (resolveData.type || resolveData.ns) { + QmlTypeNameBridge tnb = { + resolveData.object, + resolveData.type, + resolveData.ns + }; + return scriptEngine.newObject(typeNameClass, scriptEngine.newVariant(qVariantFromValue(tnb))); + } else if (resolveData.context) { QmlContext *bindContext = resolveData.context; QmlContextPrivate *contextPrivate = bindContext->d_func(); int index = resolveData.contextIndex; @@ -314,13 +347,13 @@ QmlEnginePrivate::queryObject(const QString &propName, QPair key = qMakePair(obj->metaObject(), propName); bool isFunction = false; - if (functionCache()->contains(key)) { - isFunction = functionCache()->value(key); + if (functionCache.contains(key)) { + isFunction = functionCache.value(key); } else { QScriptValue sobj = scriptEngine.newQObject(obj); QScriptValue func = sobj.property(propName); isFunction = func.isFunction(); - functionCache()->insert(key, isFunction); + functionCache.insert(key, isFunction); } if (isFunction) { @@ -340,13 +373,6 @@ QmlEnginePrivate::queryObject(const QString &propName, return rv; } -struct QmlValueTypeReference { - QmlValueType *type; - QGuard object; - int property; -}; -Q_DECLARE_METATYPE(QmlValueTypeReference); - QScriptValue QmlEnginePrivate::propertyObject(const QScriptString &propName, QObject *obj, uint id) { @@ -1084,6 +1110,81 @@ void QmlContextScriptClass::setProperty(QScriptValue &object, } ///////////////////////////////////////////////////////////// +QmlTypeNameScriptClass::QmlTypeNameScriptClass(QmlEngine *engine) +: QmlScriptClass(engine), object(0), type(0) +{ +} + +QmlTypeNameScriptClass::~QmlTypeNameScriptClass() +{ +} + +QmlTypeNameScriptClass::QueryFlags +QmlTypeNameScriptClass::queryProperty(const QScriptValue &scriptObject, + const QScriptString &name, + QueryFlags flags, uint *id) +{ + QmlTypeNameBridge bridge = + qvariant_cast(scriptObject.data().toVariant()); + + object = 0; + type = 0; + QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); + + if (bridge.ns) { + QmlType *type = 0; + ep->resolveTypeInNamespace(bridge.ns, name.toString().toUtf8(), + &type, 0, 0, 0); + if (type) { + object = bridge.object; + this->type = type; + return HandlesReadAccess; + } else { + return 0; + } + + } else { + Q_ASSERT(bridge.type); + QString strName = name.toString(); + if (strName.at(0).isUpper()) { + // Must be an enum + // ### Optimize + const char *enumName = strName.toUtf8().constData(); + const QMetaObject *metaObject = bridge.type->baseMetaObject(); + for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) { + QMetaEnum e = metaObject->enumerator(ii); + int value = e.keyToValue(enumName); + if (value != -1) { + enumValue = value; + return HandlesReadAccess; + } + } + return 0; + } else { + // Must be an attached property + this->object = qmlAttachedPropertiesObjectById(bridge.type->index(), bridge.object); + Q_ASSERT(this->object); + return ep->queryObject(strName, id, this->object); + } + } +} + +QScriptValue QmlTypeNameScriptClass::property(const QScriptValue &, + const QScriptString &propName, + uint id) +{ + QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); + if (type) { + QmlTypeNameBridge tnb = { object, type, 0 }; + return ep->scriptEngine.newObject(ep->typeNameClass, ep->scriptEngine.newVariant(qVariantFromValue(tnb))); + } else if (object) { + return ep->propertyObject(propName, object, id); + } else { + return QScriptValue(enumValue); + } +} + +///////////////////////////////////////////////////////////// QmlValueTypeScriptClass::QmlValueTypeScriptClass(QmlEngine *bindEngine) : QmlScriptClass(bindEngine) { diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 451276d..f492ccb 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -82,6 +82,7 @@ class QmlExpression; class QmlBasicScriptNodeCache; class QmlContextScriptClass; class QmlObjectScriptClass; +class QmlTypeNameScriptClass; class QmlValueTypeScriptClass; class QScriptEngineDebugger; class QNetworkReply; @@ -127,16 +128,22 @@ public: QScriptEngineDebugger *debugger; #endif + struct ImportedNamespace; struct ResolveData { ResolveData() : safetyCheckId(0) {} int safetyCheckId; void clear() { - object = 0; context = 0; contextIndex = -1; isFunction = false; + object = 0; context = 0; + type = 0; ns = 0; + contextIndex = -1; isFunction = false; } QObject *object; QmlContext *context; + QmlType *type; + QmlEnginePrivate::ImportedNamespace *ns; + int contextIndex; bool isFunction; QmlMetaProperty property; @@ -144,6 +151,7 @@ public: QmlContextScriptClass *contextClass; QmlObjectScriptClass *objectClass; QmlValueTypeScriptClass *valueTypeClass; + QmlTypeNameScriptClass *typeNameClass; // Used by DOM Core 3 API QScriptClass *nodeListClass; QScriptClass *namedNodeMapClass; @@ -199,6 +207,9 @@ public: } QmlValueTypeFactory valueTypes; + // ### Fixme + typedef QHash, bool> FunctionCache; + FunctionCache functionCache; QHash propertyCache; static QmlMetaObjectCache *cache(QmlEnginePrivate *priv, QObject *obj) { if (!priv || !obj || QObjectPrivate::get(obj)->metaObject) return 0; @@ -219,7 +230,6 @@ public: QmlImportsPrivate *d; }; - struct ImportedNamespace; bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, @@ -313,6 +323,25 @@ public: const QScriptValue &value); }; +class QmlTypeNameScriptClass : public QmlScriptClass +{ +public: + QmlTypeNameScriptClass(QmlEngine *); + ~QmlTypeNameScriptClass(); + + virtual QueryFlags queryProperty(const QScriptValue &object, + const QScriptString &name, + QueryFlags flags, uint *id); + virtual QScriptValue property(const QScriptValue &object, + const QScriptString &name, + uint id); + +private: + QObject *object; + QmlType *type; + quint32 enumValue; +}; + class QmlValueTypeScriptClass : public QmlScriptClass { public: diff --git a/tests/auto/declarative/qmlbindengine/enums.1.qml b/tests/auto/declarative/qmlbindengine/enums.1.qml new file mode 100644 index 0000000..6351823 --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/enums.1.qml @@ -0,0 +1,20 @@ +import Qt.test 1.0 +import Qt.test 1.0 as Namespace + +MyQmlObject { + // Enums from non-namespaced type + property int a: MyQmlObject.EnumValue1 + property int b: MyQmlObject.EnumValue2 + property int c: MyQmlObject.EnumValue3 + property int d: MyQmlObject.EnumValue4 + + // Enums from namespaced type + property int e: Namespace.MyQmlObject.EnumValue1 + property int f: Namespace.MyQmlObject.EnumValue2 + property int g: Namespace.MyQmlObject.EnumValue3 + property int h: Namespace.MyQmlObject.EnumValue4 + + // Test that enums don't mask attached properties + property int i: MyQmlObject.value + property int j: Namespace.MyQmlObject.value +} diff --git a/tests/auto/declarative/qmlbindengine/testtypes.h b/tests/auto/declarative/qmlbindengine/testtypes.h index f5b309e..f27c0b0 100644 --- a/tests/auto/declarative/qmlbindengine/testtypes.h +++ b/tests/auto/declarative/qmlbindengine/testtypes.h @@ -5,9 +5,21 @@ #include #include +class MyQmlAttachedObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int value READ value CONSTANT) +public: + MyQmlAttachedObject(QObject *parent) : QObject(parent) {} + + int value() const { return 19; } +}; + class MyQmlObject : public QObject { Q_OBJECT + Q_ENUMS(MyEnum) + Q_ENUMS(MyEnum2) Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT) Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT) Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged) @@ -15,6 +27,9 @@ class MyQmlObject : public QObject public: MyQmlObject(): m_methodCalled(false), m_methodIntCalled(false), m_object(0) {} + enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 }; + enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 }; + bool trueProperty() const { return true; } bool falseProperty() const { return false; } @@ -39,6 +54,10 @@ public: bool methodIntCalled() const { return m_methodIntCalled; } QString string() const { return m_string; } + + static MyQmlAttachedObject *qmlAttachedProperties(QObject *o) { + return new MyQmlAttachedObject(o); + } signals: void basicSignal(); void argumentSignal(int a, QString b, qreal c); diff --git a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp index 01cb54b..80373fe 100644 --- a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp +++ b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp @@ -38,6 +38,7 @@ private slots: void objectPropertiesTriggerReeval(); void deferredProperties(); void extensionObjects(); + void enums(); private: QmlEngine engine; @@ -366,6 +367,24 @@ void tst_qmlbindengine::extensionObjects() QCOMPARE(object->baseProperty(), 92); } +void tst_qmlbindengine::enums() +{ + QmlComponent component(&engine, TEST_FILE("enums.1.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("a").toInt(), 0); + QCOMPARE(object->property("b").toInt(), 1); + QCOMPARE(object->property("c").toInt(), 2); + QCOMPARE(object->property("d").toInt(), 3); + QCOMPARE(object->property("e").toInt(), 0); + QCOMPARE(object->property("f").toInt(), 1); + QCOMPARE(object->property("g").toInt(), 2); + QCOMPARE(object->property("h").toInt(), 3); + QCOMPARE(object->property("i").toInt(), 19); + QCOMPARE(object->property("j").toInt(), 19); +} + QTEST_MAIN(tst_qmlbindengine) #include "tst_qmlbindengine.moc" -- cgit v0.12 From 8ac9c707306f0eb8804310f47894d4723e190bce Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 3 Sep 2009 10:27:34 +1000 Subject: Remove dead test --- .../declarative/simplecanvasitem/data/test.qml | 60 ---------------- .../simplecanvasitem/simplecanvasitem.pro | 7 -- .../simplecanvasitem/tst_simplecanvasitem.cpp | 79 ---------------------- 3 files changed, 146 deletions(-) delete mode 100644 tests/auto/declarative/simplecanvasitem/data/test.qml delete mode 100644 tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro delete mode 100644 tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp diff --git a/tests/auto/declarative/simplecanvasitem/data/test.qml b/tests/auto/declarative/simplecanvasitem/data/test.qml deleted file mode 100644 index 8fbbc2e..0000000 --- a/tests/auto/declarative/simplecanvasitem/data/test.qml +++ /dev/null @@ -1,60 +0,0 @@ -import Qt 4.6 - -Item { - width: 320 - height: 480 - Rect { - color: "blue" - x: 20 - y: 20 - width: 20 - height: 20 - Rect { - color: "black" - x: 20 - y: 20 - width: 10 - height: 10 - } - } - Rect { - color: "red" - x: 40 - y: 20 - width: 20 - height: 20 - } - Rect { - color: "green" - x: 60 - y: 20 - width: 20 - height: 20 - } - Rect { - color: "yellow" - x: 20 - y: 40 - width: 20 - height: 20 - } - Rect { - color: "purple" - x: 20 - y: 60 - width: 20 - height: 20 - } - Rect { - color: "white" - x: 40 - y: 40 - width: 20 - height: 20 - } - Rect { - anchors.fill: parent - color: "gray" - z: -1 - } -} diff --git a/tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro b/tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro deleted file mode 100644 index f4aea32..0000000 --- a/tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -contains(QT_CONFIG, opengles2)|contains(QT_CONFIG, opengles1): QT += opengl -SOURCES += tst_simplecanvasitem.cpp - -# Define SRCDIR equal to test's source directory -DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp b/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp deleted file mode 100644 index cce4df1..0000000 --- a/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include - -/* - Note: this autotest is specifically to test SimpleCanvasItem as a component of - Qt Declarative, and therefore will have all items created in XML. -*/ -class tst_SimpleCanvasItem : public QObject -{ - Q_OBJECT -public: - tst_SimpleCanvasItem(); - -private slots: - void test_pos(); - void test_scenePos(); -private: - QFxView *createView(const QString &filename); -}; - -tst_SimpleCanvasItem::tst_SimpleCanvasItem() -{ -} - -void tst_SimpleCanvasItem::test_pos() -{ - QFxView *canvas = createView(SRCDIR "/data/test.qml"); - canvas->execute(); - qApp->processEvents(); - QSimpleCanvasItem* root = qobject_cast(canvas->root()); - QVERIFY(root); - - QCOMPARE(root->pos(), QPointF(0,0)); - QCOMPARE(root->children().at(0)->pos(), QPointF(20,20)); - QCOMPARE(root->children().at(0)->children().at(0)->pos(), QPointF(20,20)); - QCOMPARE(root->children().at(2)->pos(), QPointF(60,20)); - QCOMPARE(root->children().at(3)->pos(), QPointF(20,40)); - QCOMPARE(root->children().at(5)->pos(), QPointF(40,40)); -} - -void tst_SimpleCanvasItem::test_scenePos() -{ - QFxView *canvas = createView(SRCDIR "/data/test.qml"); - canvas->execute(); - qApp->processEvents(); - QSimpleCanvasItem* root = qobject_cast(canvas->root()); - QVERIFY(root); - -#ifdef CANVAS_GL - QCOMPARE(root->transform(), QMatrix4x4()); -#else - QCOMPARE(root->transform(), QTransform()); -#endif - QCOMPARE(root->scenePos(), QPointF(0,0)); - QCOMPARE(root->children().at(0)->scenePos(), QPointF(20,20)); - QCOMPARE(root->children().at(0)->children().at(0)->scenePos(), QPointF(40,40)); - QCOMPARE(root->children().at(2)->scenePos(), QPointF(60,20)); - QCOMPARE(root->children().at(3)->scenePos(), QPointF(20,40)); - QCOMPARE(root->children().at(5)->scenePos(), QPointF(40,40)); -} - -QFxView *tst_SimpleCanvasItem::createView(const QString &filename) -{ - QFxView *canvas = new QFxView(0); - canvas->setFixedSize(240,320); - - QFile file(filename); - file.open(QFile::ReadOnly); - QString xml = file.readAll(); - canvas->setQml(xml, filename); - - return canvas; -} - -QTEST_MAIN(tst_SimpleCanvasItem) - -#include "tst_simplecanvasitem.moc" -- cgit v0.12