summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Hartmann <Thomas.Hartmann@nokia.com>2010-09-14 14:49:57 (GMT)
committerThomas Hartmann <Thomas.Hartmann@nokia.com>2010-09-14 14:49:57 (GMT)
commit34b805d66c09fb324d1b6a7bcf259e8743ef3894 (patch)
tree3567ce5e2e8b0463c2e932e38940a92b814ab00c /src
parenta8085e53f15f88aa108d2e7e6473094105d0fdcb (diff)
downloadQt-34b805d66c09fb324d1b6a7bcf259e8743ef3894.zip
Qt-34b805d66c09fb324d1b6a7bcf259e8743ef3894.tar.gz
Qt-34b805d66c09fb324d1b6a7bcf259e8743ef3894.tar.bz2
Completing the interface for children/data/resources
This patch makes the handling of properties like children and data easier in Bauhaus. Especially in the case of property alias Reviewed-by: Aaron Kennedy
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp54
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable_p_p.h3
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp62
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem_p.h4
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp9
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h1
6 files changed, 129 insertions, 4 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index c0b664f..bf3d88b 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -1051,10 +1051,62 @@ void QDeclarativeFlickablePrivate::data_append(QDeclarativeListProperty<QObject>
o->setParent(prop->object);
}
+static inline int children_count_helper(QGraphicsObject *object)
+{
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
+ return d->children.count();
+}
+
+static inline QObject *children_at_helper(QGraphicsObject *object, int index)
+{
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
+ if (index >= 0 && index < d->children.count())
+ return d->children.at(index)->toGraphicsObject();
+ else
+ return 0;
+}
+
+static inline void children_clear_helper(QGraphicsObject *object)
+{
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
+ for (int index = 0 ;index < d->children.count();index++)
+ QGraphicsItemPrivate::get(d->children.at(index))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0);
+}
+
+int QDeclarativeFlickablePrivate::data_count(QDeclarativeListProperty<QObject> *prop)
+{
+ return QDeclarativeItemPrivate::resources_count(prop) +
+ children_count_helper(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem);
+}
+
+QObject *QDeclarativeFlickablePrivate::data_at(QDeclarativeListProperty<QObject> *prop, int i)
+{
+ int resourcesCount = QDeclarativeItemPrivate::resources_count(prop);
+ if (i < resourcesCount)
+ return QDeclarativeItemPrivate::resources_at(prop, i);
+ const int j = i - resourcesCount;
+ QGraphicsObject *contentObject = static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem;
+ if (j < children_count_helper(contentObject))
+ children_at_helper(contentObject, j);
+ return 0;
+}
+
+void QDeclarativeFlickablePrivate::data_clear(QDeclarativeListProperty<QObject> *prop)
+{
+ QDeclarativeItemPrivate::resources_clear(prop);
+ QGraphicsObject *contentObject =
+ static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem;
+ children_clear_helper(contentObject);
+}
+
QDeclarativeListProperty<QObject> QDeclarativeFlickable::flickableData()
{
Q_D(QDeclarativeFlickable);
- return QDeclarativeListProperty<QObject>(this, (void *)d, QDeclarativeFlickablePrivate::data_append);
+ return QDeclarativeListProperty<QObject>(this, (void *)d, QDeclarativeFlickablePrivate::data_append,
+ QDeclarativeFlickablePrivate::data_count,
+ QDeclarativeFlickablePrivate::data_at,
+ QDeclarativeFlickablePrivate::data_clear
+ );
}
QDeclarativeListProperty<QGraphicsObject> QDeclarativeFlickable::flickableChildren()
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
index 2da034c..beee741 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
@@ -173,6 +173,9 @@ public:
// flickableData property
static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
+ static int data_count(QDeclarativeListProperty<QObject> *);
+ static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
+ static void data_clear(QDeclarativeListProperty<QObject> *);
};
class QDeclarativeFlickableVisibleArea : public QObject
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
+ );
}
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h
index fffb4f7..f85fa27 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h
@@ -176,11 +176,15 @@ public:
// data property
static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
+ static int data_count(QDeclarativeListProperty<QObject> *);
+ static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
+ static void data_clear(QDeclarativeListProperty<QObject> *);
// resources property
static QObject *resources_at(QDeclarativeListProperty<QObject> *, int);
static void resources_append(QDeclarativeListProperty<QObject> *, QObject *);
static int resources_count(QDeclarativeListProperty<QObject> *);
+ static void resources_clear(QDeclarativeListProperty<QObject> *);
// transform property
static int transform_count(QDeclarativeListProperty<QGraphicsTransform> *list);
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 7a5b8de..9e43f2f 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -7676,6 +7676,13 @@ QGraphicsObject *QGraphicsItemPrivate::children_at(QDeclarativeListProperty<QGra
return 0;
}
+void QGraphicsItemPrivate::children_clear(QDeclarativeListProperty<QGraphicsObject> *list)
+{
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));
+ for (int index = 0 ;index < d->children.count();index++)
+ QGraphicsItemPrivate::get(d->children.at(index))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0);
+}
+
/*!
Returns a list of this item's children.
@@ -7689,7 +7696,7 @@ QDeclarativeListProperty<QGraphicsObject> QGraphicsItemPrivate::childrenList()
if (isObject) {
QGraphicsObject *that = static_cast<QGraphicsObject *>(q);
return QDeclarativeListProperty<QGraphicsObject>(that, &children, children_append,
- children_count, children_at);
+ children_count, children_at, children_clear);
} else {
//QGraphicsItem is not supported for this property
return QDeclarativeListProperty<QGraphicsObject>();
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index d60dffb..cce9439 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -487,6 +487,7 @@ public:
static void children_append(QDeclarativeListProperty<QGraphicsObject> *list, QGraphicsObject *item);
static int children_count(QDeclarativeListProperty<QGraphicsObject> *list);
static QGraphicsObject *children_at(QDeclarativeListProperty<QGraphicsObject> *list, int);
+ static void children_clear(QDeclarativeListProperty<QGraphicsObject> *list);
inline QTransform transformToParent() const;
inline void ensureSortedChildren();