diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-12-04 14:24:24 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-05 10:06:08 +0100 |
commit | 32d05752e00218a40516d43069fca2bee0d9894e (patch) | |
tree | a5078b1a864aa872f0762e4369ced45768a984c9 /tests/auto | |
parent | 268f4615dcf19aad3603833af83ba28eca886aa5 (diff) |
Fix dynamic properties in QQmlPropertyMap not always being visible in QML
QQmlPropertyMap is a fully dynamic class that can add properties at any point
in time. In order for these properties to be visible inside QML, we must
disable the property cache (instead of trying to unsuccessfully re-fresh it).
What happened in this particular case is that the QQmlPropertyMap derived type
was instantiated and the VME instruction for creating it would also assign the
property cache the compiler determined. There's no way for QQmlPropertyMap
itself to access this property cache instance (stored in
output->types[id].typePropertyCache) or invalidate it, so instead don't use the
compiler's property cache when instantiating the type.
This patch also disallows the adding properties to QQmlPropertyMap when it
is used as base type for a new QML type, as we cannot provide the derived
type to the QQmlPropertyMap constructor - this is only possible in C++.
Task-number: QTBUG-35233
Change-Id: I7fa9e4a2224ccfdd7ccb3fd9f73919ecd46058a8
Reviewed-by: Alberto Mardegan <mardy@users.sourceforge.net>
Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index ca212d333b..17f54508a3 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -55,6 +55,8 @@ public: tst_QQmlPropertyMap() {} private slots: + void initTestCase(); + void insert(); void operatorInsert(); void operatorValue(); @@ -68,8 +70,39 @@ private slots: void metaObjectAccessibility(); void QTBUG_31226(); void QTBUG_29836(); + void QTBUG_35233(); + void disallowExtending(); +}; + +class LazyPropertyMap : public QQmlPropertyMap, public QQmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QQmlParserStatus) + + Q_PROPERTY(int someFixedProperty READ someFixedProperty WRITE setSomeFixedProperty) +public: + LazyPropertyMap() + : QQmlPropertyMap(this, /*parent*/0) + , value(0) + {} + + virtual void classBegin() {} + virtual void componentComplete() { + insert(QStringLiteral("lateProperty"), QStringLiteral("lateValue")); + } + + int someFixedProperty() const { return value; } + void setSomeFixedProperty(int v) { value = v; } + +private: + int value; }; +void tst_QQmlPropertyMap::initTestCase() +{ + qmlRegisterType<LazyPropertyMap>("QTBUG_35233", 1, 0, "LazyPropertyMap"); +} + void tst_QQmlPropertyMap::insert() { QQmlPropertyMap map; @@ -369,6 +402,54 @@ void tst_QQmlPropertyMap::QTBUG_29836() } +void tst_QQmlPropertyMap::QTBUG_35233() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQml 2.0\n" + "import QTBUG_35233 1.0\n" + "QtObject {\n" + " property QtObject testMap: LazyPropertyMap {\n" + " id: map\n" + " }\n" + " property QtObject sibling: QtObject {\n" + " objectName: \"sibling\"\n" + " property string testValue: map.lateProperty\n" + " }\n" + "}", QUrl()); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + + QObject *sibling = obj->findChild<QObject*>("sibling"); + QVERIFY(sibling); + QCOMPARE(sibling->property("testValue").toString(), QString("lateValue")); +} + +void tst_QQmlPropertyMap::disallowExtending() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQml 2.0\n" + "import QTBUG_35233 1.0\n" + "LazyPropertyMap {\n" + " id: blah\n" + " someFixedProperty: 42\n" + "}\n", QUrl()); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + + component.setData("import QtQml 2.0\n" + "import QTBUG_35233 1.0\n" + "LazyPropertyMap {\n" + " id: blah\n" + " property int someNewProperty;\n" + "}\n", QUrl()); + obj.reset(component.create()); + QVERIFY(obj.isNull()); + QCOMPARE(component.errors().count(), 1); + QCOMPARE(component.errors().at(0).toString(), QStringLiteral("<Unknown File>: Fully dynamic types cannot declare new properties.")); +} + QTEST_MAIN(tst_QQmlPropertyMap) #include "tst_qqmlpropertymap.moc" |