aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/testtypes.cpp
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-07-29 12:49:37 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-07-29 12:49:37 +0200
commit8b88e37bf79a53eb0cb34226aacb25ad9b01d7cf (patch)
tree6087ee08b55f69f9c4981d9026d3162f2ee50c31 /tests/auto/qml/qqmlecmascript/testtypes.cpp
parent61edb86ed4cc0ac31d77d3793936fa1e8476b504 (diff)
parent7ceca6ac0535a957e9f87f789119c288f6d93837 (diff)
Merge remote-tracking branch 'origin/5.3' into dev
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/testtypes.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp
index 56e733a423..c4e6709958 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.cpp
+++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp
@@ -338,6 +338,62 @@ static QObject *create_singletonWithEnum(QQmlEngine *, QJSEngine *)
return new SingletonWithEnum;
}
+QObjectContainer::QObjectContainer()
+ : widgetParent(0)
+ , gcOnAppend(false)
+{}
+
+QQmlListProperty<QObject> QObjectContainer::data()
+{
+ return QQmlListProperty<QObject>(this, 0, children_append, children_count, children_at, children_clear);
+}
+
+void QObjectContainer::children_append(QQmlListProperty<QObject> *prop, QObject *o)
+{
+ QObjectContainer *that = static_cast<QObjectContainer*>(prop->object);
+ that->dataChildren.append(o);
+ QObject::connect(o, SIGNAL(destroyed(QObject*)), prop->object, SLOT(childDestroyed(QObject*)));
+
+ if (that->gcOnAppend) {
+ QQmlEngine *engine = qmlEngine(that);
+ engine->collectGarbage();
+ QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::processEvents();
+ }
+}
+
+int QObjectContainer::children_count(QQmlListProperty<QObject> *prop)
+{
+ return static_cast<QObjectContainer*>(prop->object)->dataChildren.count();
+}
+
+QObject *QObjectContainer::children_at(QQmlListProperty<QObject> *prop, int index)
+{
+ return static_cast<QObjectContainer*>(prop->object)->dataChildren.at(index);
+}
+
+void QObjectContainer::children_clear(QQmlListProperty<QObject> *prop)
+{
+ QObjectContainer *that = static_cast<QObjectContainer*>(prop->object);
+ foreach (QObject *c, that->dataChildren)
+ QObject::disconnect(c, SIGNAL(destroyed(QObject*)), that, SLOT(childDestroyed(QObject*)));
+ that->dataChildren.clear();
+}
+
+void QObjectContainer::childDestroyed(QObject *child) {
+ dataChildren.removeAll(child);
+}
+
+void FloatingQObject::classBegin()
+{
+ setParent(0);
+}
+
+void FloatingQObject::componentComplete()
+{
+ Q_ASSERT(!parent());
+}
+
void registerTypes()
{
qmlRegisterType<MyQmlObject>("Qt.test", 1,0, "MyQmlObjectAlias");
@@ -422,6 +478,10 @@ void registerTypes()
qmlRegisterSingletonType<testImportOrderApi>("Qt.test.importOrderApi2",1,0,"Data",testImportOrder_api2);
qmlRegisterSingletonType<SingletonWithEnum>("Qt.test.singletonWithEnum", 1, 0, "SingletonWithEnum", create_singletonWithEnum);
+
+ qmlRegisterType<QObjectContainer>("Qt.test", 1, 0, "QObjectContainer");
+ qmlRegisterType<QObjectContainerWithGCOnAppend>("Qt.test", 1, 0, "QObjectContainerWithGCOnAppend");
+ qmlRegisterType<FloatingQObject>("Qt.test", 1, 0, "FloatingQObject");
}
#include "testtypes.moc"