Fix list functions for the data property
authorMarco Bubke <marco.bubke@digia.com>
Mon, 15 Oct 2012 16:34:10 +0000 (18:34 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 18 Oct 2012 16:46:30 +0000 (18:46 +0200)
The Qml Designer needs this functions.

Task-number: QTCREATORBUG-8039
Change-Id: I6e072723630cf971ad3eda921497699611ae934e
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
src/quick/items/qquickitem.cpp

index 8985b7b..62fc81f 100644 (file)
@@ -2509,25 +2509,41 @@ void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
     automatically assigned to this property.
  */
 
-int QQuickItemPrivate::data_count(QQmlListProperty<QObject> *prop)
+int QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
 {
-    Q_UNUSED(prop);
-    // XXX todo
-    return 0;
+    QQuickItem *item = static_cast<QQuickItem*>(property->object);
+    QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
+    QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
+    QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
+
+    return resources_count(&resourcesProperty) + children_count(&childrenProperty);
 }
 
-QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *prop, int i)
+QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, int i)
 {
-    Q_UNUSED(prop);
-    Q_UNUSED(i);
-    // XXX todo
+    QQuickItem *item = static_cast<QQuickItem*>(property->object);
+    QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
+    QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
+    QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
+
+    int resourcesCount = resources_count(&resourcesProperty);
+    if (i < resourcesCount)
+        return resources_at(&resourcesProperty, i);
+    const int j = i - resourcesCount;
+    if (j < children_count(&childrenProperty))
+        return children_at(&childrenProperty, j);
     return 0;
 }
 
-void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *prop)
+void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
 {
-    Q_UNUSED(prop);
-    // XXX todo
+    QQuickItem *item = static_cast<QQuickItem*>(property->object);
+    QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
+    QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
+    QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
+
+    resources_clear(&resourcesProperty);
+    children_clear(&childrenProperty);
 }
 
 QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, int index)