diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-12-17 08:14:25 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-12-17 08:14:25 (GMT) |
commit | b6849d90388ffd415d398923ce8f8d5d8d549bd6 (patch) | |
tree | 4d210d5bbec19406749e8e66fc535cf1b0500dea | |
parent | f79e0e89ea9061bbe93f43405a1ec954a41da1cc (diff) | |
parent | fd222fa269db8797ad35c23d7298df7c8a81751e (diff) | |
download | Qt-b6849d90388ffd415d398923ce8f8d5d8d549bd6.zip Qt-b6849d90388ffd415d398923ce8f8d5d8d549bd6.tar.gz Qt-b6849d90388ffd415d398923ce8f8d5d8d549bd6.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r-- | src/declarative/qml/qmlcompiler.cpp | 15 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 10 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlpropertycache.cpp | 7 | ||||
-rw-r--r-- | src/declarative/qml/qmlpropertycache_p.h | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/data/Alias3.qml | 12 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/data/Alias4.qml | 5 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/data/alias.8.qml | 9 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/data/alias.9.qml | 9 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 24 | ||||
-rw-r--r-- | tests/benchmarks/declarative/qmltime/qmltime.cpp | 41 |
11 files changed, 128 insertions, 7 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index bd46bbe..9147c4a 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2440,6 +2440,21 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder, typeName = aliasProperty.typeName(); } else { typeName = idObject->metaObject()->className(); + + //use the base type since it has been registered with metatype system + int index = typeName.indexOf("_QML_"); + if (index != -1) { + typeName = typeName.left(index); + } else { + index = typeName.indexOf("_QMLTYPE_"); + const QMetaObject *mo = idObject->metaObject(); + while (index != -1 && mo) { + typeName = mo->superClass()->className(); + index = typeName.indexOf("_QMLTYPE_"); + mo = mo->superClass(); + } + } + typeName += '*'; } diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 6b66095..f541631 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1527,6 +1527,16 @@ int QmlEnginePrivate::qmlListType(int t) const return QmlMetaType::qmlListType(t); } +QmlMetaType::TypeCategory QmlEnginePrivate::typeCategory(int t) const +{ + if (m_compositeTypes.contains(t)) + return QmlMetaType::Object; + else if (m_qmlLists.contains(t)) + return QmlMetaType::QmlList; + else + return QmlMetaType::typeCategory(t); +} + const QMetaObject *QmlEnginePrivate::rawMetaObjectForType(int t) const { QHash<int, QmlCompiledData*>::ConstIterator iter = m_compositeTypes.find(t); diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index c3db6cf..96297ea 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -263,6 +263,7 @@ public: bool isQmlList(int) const; bool isObject(int); int qmlListType(int) const; + QmlMetaType::TypeCategory typeCategory(int) const; const QMetaObject *rawMetaObjectForType(int) const; const QMetaObject *metaObjectForType(int) const; QHash<int, int> m_qmlLists; diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index 6ba6028..bc7d7de 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE Q_DECLARE_METATYPE(QScriptValue); -void QmlPropertyCache::Data::load(const QMetaProperty &p) +void QmlPropertyCache::Data::load(const QMetaProperty &p, QmlEngine *engine) { propType = p.userType(); if (QVariant::Type(propType) == QVariant::LastType) @@ -69,7 +69,8 @@ void QmlPropertyCache::Data::load(const QMetaProperty &p) } else if (p.isEnumType()) { flags |= Data::IsEnumType; } else { - QmlMetaType::TypeCategory cat = QmlMetaType::typeCategory(propType); + QmlMetaType::TypeCategory cat = engine ? QmlEnginePrivate::get(engine)->typeCategory(propType) + : QmlMetaType::typeCategory(propType); if (cat == QmlMetaType::Object) flags |= Data::IsQObjectDerived; else if (cat == QmlMetaType::List) @@ -174,7 +175,7 @@ void QmlPropertyCache::update(QmlEngine *engine, const QMetaObject *metaObject) RData *data = new RData; data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName); - data->load(p); + data->load(p, engine); indexCache[ii] = data; diff --git a/src/declarative/qml/qmlpropertycache_p.h b/src/declarative/qml/qmlpropertycache_p.h index 613f4dd..50b4cf2 100644 --- a/src/declarative/qml/qmlpropertycache_p.h +++ b/src/declarative/qml/qmlpropertycache_p.h @@ -97,7 +97,7 @@ public: int coreIndex; int notifyIndex; - void load(const QMetaProperty &); + void load(const QMetaProperty &, QmlEngine *engine = 0); void load(const QMetaMethod &); QString name(QObject *); QString name(const QMetaObject *); diff --git a/tests/auto/declarative/qmllanguage/data/Alias3.qml b/tests/auto/declarative/qmllanguage/data/Alias3.qml new file mode 100644 index 0000000..d1e78f8 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/Alias3.qml @@ -0,0 +1,12 @@ +import Test 1.0 +import Qt 4.6 + +QtObject { + property alias obj : otherObj + property var child + child: QtObject { + id: otherObj + property int myValue: 10 + } +} + diff --git a/tests/auto/declarative/qmllanguage/data/Alias4.qml b/tests/auto/declarative/qmllanguage/data/Alias4.qml new file mode 100644 index 0000000..573674c --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/Alias4.qml @@ -0,0 +1,5 @@ +import Test 1.0 +import Qt 4.6 + +Alias3 {} + diff --git a/tests/auto/declarative/qmllanguage/data/alias.8.qml b/tests/auto/declarative/qmllanguage/data/alias.8.qml new file mode 100644 index 0000000..38dc10f --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/alias.8.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property var other + other: Alias3 { id: MyAliasObject } + + property int value: MyAliasObject.obj.myValue +} + diff --git a/tests/auto/declarative/qmllanguage/data/alias.9.qml b/tests/auto/declarative/qmllanguage/data/alias.9.qml new file mode 100644 index 0000000..8061f99 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/alias.9.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property var other + other: Alias4 { id: MyAliasObject } + + property int value: MyAliasObject.obj.myValue +} + diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 160998f..56c500c 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -889,6 +889,30 @@ void tst_qmllanguage::aliasProperties() object->metaObject()->indexOfProperty("aliasedObject"), a); QVERIFY(alias2 == 0); } + + // Simple composite type + { + QmlComponent component(&engine, TEST_FILE("alias.8.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("value").toInt(), 10); + + delete object; + } + + // Complex composite type + { + QmlComponent component(&engine, TEST_FILE("alias.9.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("value").toInt(), 10); + + delete object; + } } // Test that the root element in a composite type can be a Component diff --git a/tests/benchmarks/declarative/qmltime/qmltime.cpp b/tests/benchmarks/declarative/qmltime/qmltime.cpp index f065444..7f41c07 100644 --- a/tests/benchmarks/declarative/qmltime/qmltime.cpp +++ b/tests/benchmarks/declarative/qmltime/qmltime.cpp @@ -4,6 +4,8 @@ #include <QApplication> #include <QTime> #include <QmlContext> +#include <QGraphicsScene> +#include <QGraphicsRectItem> class Timer : public QObject { @@ -20,11 +22,18 @@ public: void run(uint); + bool willParent() const; + void setWillParent(bool p); + private: void runTest(QmlContext *, uint); QmlComponent *m_component; static Timer *m_timer; + + bool m_willparent; + QGraphicsScene m_scene; + QGraphicsRectItem m_item; }; QML_DECLARE_TYPE(Timer); QML_DEFINE_TYPE(QmlTime, 1, 0, Timer, Timer); @@ -32,11 +41,14 @@ QML_DEFINE_TYPE(QmlTime, 1, 0, Timer, Timer); Timer *Timer::m_timer = 0; Timer::Timer() -: m_component(0) +: m_component(0), m_willparent(false) { if (m_timer) qWarning("Timer: Timer already registered"); m_timer = this; + + m_scene.setItemIndexMethod(QGraphicsScene::NoIndex); + m_scene.addItem(&m_item); } QmlComponent *Timer::component() const @@ -59,18 +71,33 @@ void Timer::run(uint iterations) QmlContext context(qmlContext(this)); QObject *o = m_component->create(&context); + QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o); + if (m_willparent && go) + go->setParentItem(&m_item); delete o; - runTest(&context, iterations); } +bool Timer::willParent() const +{ + return m_willparent; +} + +void Timer::setWillParent(bool p) +{ + m_willparent = p; +} + void Timer::runTest(QmlContext *context, uint iterations) { QTime t; t.start(); for (uint ii = 0; ii < iterations; ++ii) { QObject *o = m_component->create(context); + QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o); + if (m_willparent && go) + go->setParentItem(&m_item); delete o; } @@ -82,7 +109,7 @@ void Timer::runTest(QmlContext *context, uint iterations) void usage(const char *name) { - qWarning("Usage: %s [-iterations <count>] <qml file>", name); + qWarning("Usage: %s [-iterations <count>] [-parent] <qml file>", name); exit(-1); } @@ -92,6 +119,7 @@ int main(int argc, char ** argv) uint iterations = 1024; QString filename; + bool willParent = false; for (int ii = 1; ii < argc; ++ii) { QByteArray arg(argv[ii]); @@ -107,11 +135,16 @@ int main(int argc, char ** argv) } else { usage(argv[0]); } + } else if (arg == "-parent") { + willParent = true; } else { filename = QLatin1String(argv[ii]); } } + if (filename.isEmpty()) + usage(argv[0]); + QmlEngine engine; QmlComponent component(&engine, filename); if (component.isError()) { @@ -131,6 +164,8 @@ int main(int argc, char ** argv) return -1; } + timer->setWillParent(willParent); + if (!timer->component()) { qWarning() << "The timer has no component"; return -1; |