summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativeitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativeitem.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp62
1 files changed, 60 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 11f9179..53a4710 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -44,6 +44,7 @@
#include "private/qdeclarativeevents_p_p.h"
#include <private/qdeclarativeengine_p.h>
+#include <private/qgraphicsitem_p.h>
#include <qdeclarativeengine.h>
#include <qdeclarativeopenmetaobject_p.h>
@@ -1619,6 +1620,50 @@ void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *pro
}
}
+static inline int children_count_helper(QDeclarativeListProperty<QObject> *prop)
+{
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object));
+ return d->children.count();
+}
+
+static inline QObject *children_at_helper(QDeclarativeListProperty<QObject> *prop, int index)
+{
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object));
+ if (index >= 0 && index < d->children.count())
+ return d->children.at(index)->toGraphicsObject();
+ else
+ return 0;
+}
+
+static inline void children_clear_helper(QDeclarativeListProperty<QObject> *prop)
+{
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object));
+ for (int index = 0 ;index < d->children.count();index++)
+ QGraphicsItemPrivate::get(d->children.at(index))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0);
+}
+
+int QDeclarativeItemPrivate::data_count(QDeclarativeListProperty<QObject> *prop)
+{
+ return resources_count(prop) + children_count_helper(prop);
+}
+
+QObject *QDeclarativeItemPrivate::data_at(QDeclarativeListProperty<QObject> *prop, int i)
+{
+ int resourcesCount = resources_count(prop);
+ if (i < resourcesCount)
+ return resources_at(prop, i);
+ const int j = i - resourcesCount;
+ if (j < children_count_helper(prop))
+ children_at_helper(prop, j);
+ return 0;
+}
+
+void QDeclarativeItemPrivate::data_clear(QDeclarativeListProperty<QObject> *prop)
+{
+ resources_clear(prop);
+ children_clear_helper(prop);
+}
+
QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index)
{
const QObjectList children = prop->object->children();
@@ -1638,6 +1683,13 @@ int QDeclarativeItemPrivate::resources_count(QDeclarativeListProperty<QObject> *
return prop->object->children().count();
}
+void QDeclarativeItemPrivate::resources_clear(QDeclarativeListProperty<QObject> *prop)
+{
+ const QObjectList children = prop->object->children();
+ for (int index = 0; index < children.count(); index++)
+ children.at(index)->setParent(0);
+}
+
int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty<QGraphicsTransform> *list)
{
QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
@@ -1724,7 +1776,11 @@ void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeN
QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::data()
{
- return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::data_append);
+ return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::data_append,
+ QDeclarativeItemPrivate::data_count,
+ QDeclarativeItemPrivate::data_at,
+ QDeclarativeItemPrivate::data_clear
+ );
}
/*!
@@ -2413,7 +2469,9 @@ QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::resources()
{
return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::resources_append,
QDeclarativeItemPrivate::resources_count,
- QDeclarativeItemPrivate::resources_at);
+ QDeclarativeItemPrivate::resources_at,
+ QDeclarativeItemPrivate::resources_clear
+ );
}
/*!