diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-02-22 04:56:49 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-02-22 05:53:27 (GMT) |
commit | 33eb76f050b45718d87926a8ff7afc89d6201c16 (patch) | |
tree | 935ddc2337b3891aab1ad7edcb06a62aabf14668 /src/declarative/graphicsitems | |
parent | 5f63321e3fe2b436d469d2722dc464ea4c7830c4 (diff) | |
download | Qt-33eb76f050b45718d87926a8ff7afc89d6201c16.zip Qt-33eb76f050b45718d87926a8ff7afc89d6201c16.tar.gz Qt-33eb76f050b45718d87926a8ff7afc89d6201c16.tar.bz2 |
Replace QmlList* and QList* support with a single QmlListProperty type
As a value type QmlListProperty doesn't consume any memory in the object.
It also has a companion QmlListReference class that is part of the public
API for C++ developers to interact with that also manages memory issues
that existed with previous solutions (if the containing QObject was
destroyed it left a dangling pointer).
Diffstat (limited to 'src/declarative/graphicsitems')
14 files changed, 136 insertions, 265 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index bfee8d4..e92fea4 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -945,51 +945,22 @@ void QmlGraphicsFlickable::cancelFlick() movementEnding(); } -void QmlGraphicsFlickablePrivate::data_removeAt(int) +void QmlGraphicsFlickablePrivate::data_append(QmlListProperty<QObject> *prop, QObject *o) { - // ### -} - -int QmlGraphicsFlickablePrivate::data_count() const -{ - // ### - return 0; -} - -void QmlGraphicsFlickablePrivate::data_append(QObject *o) -{ - Q_Q(QmlGraphicsFlickable); QmlGraphicsItem *i = qobject_cast<QmlGraphicsItem *>(o); if (i) - viewport->fxChildren()->append(i); + i->setParentItem(static_cast<QmlGraphicsFlickablePrivate*>(prop->data)->viewport); else - o->setParent(q); + o->setParent(prop->object); } -void QmlGraphicsFlickablePrivate::data_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsFlickablePrivate::data_at(int) const -{ - // ### - return 0; -} - -void QmlGraphicsFlickablePrivate::data_clear() -{ - // ### -} - - -QmlList<QObject *> *QmlGraphicsFlickable::flickableData() +QmlListProperty<QObject> QmlGraphicsFlickable::flickableData() { Q_D(QmlGraphicsFlickable); - return &d->data; + return QmlListProperty<QObject>(this, (void *)d, QmlGraphicsFlickablePrivate::data_append); } -QmlList<QmlGraphicsItem *> *QmlGraphicsFlickable::flickableChildren() +QmlListProperty<QmlGraphicsItem> QmlGraphicsFlickable::flickableChildren() { Q_D(QmlGraphicsFlickable); return d->viewport->fxChildren(); diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable_p.h b/src/declarative/graphicsitems/qmlgraphicsflickable_p.h index 373815b..580d01e 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsflickable_p.h @@ -82,8 +82,8 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem Q_PROPERTY(QmlGraphicsFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) - Q_PROPERTY(QmlList<QObject *>* flickableData READ flickableData) - Q_PROPERTY(QmlList<QmlGraphicsItem *>* flickableChildren READ flickableChildren) + Q_PROPERTY(QmlListProperty<QObject> flickableData READ flickableData) + Q_PROPERTY(QmlListProperty<QmlGraphicsItem> flickableChildren READ flickableChildren) Q_CLASSINFO("DefaultProperty", "flickableData") Q_ENUMS(FlickDirection) @@ -92,8 +92,8 @@ public: QmlGraphicsFlickable(QmlGraphicsItem *parent=0); ~QmlGraphicsFlickable(); - QmlList<QObject *> *flickableData(); - QmlList<QmlGraphicsItem *> *flickableChildren(); + QmlListProperty<QObject> flickableData(); + QmlListProperty<QmlGraphicsItem> flickableChildren(); bool overShoot() const; void setOverShoot(bool); diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h b/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h index a76ee8a..e58cc0c 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h @@ -149,15 +149,7 @@ public: void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *); // flickableData property - void data_removeAt(int); - int data_count() const; - void data_append(QObject *); - void data_insert(int, QObject *); - QObject *data_at(int) const; - void data_clear(); - - friend class QmlGraphicsFlickableVisibleArea; - QML_DECLARE_LIST_PROXY(QmlGraphicsFlickablePrivate, QObject *, data) + static void data_append(QmlListProperty<QObject> *, QObject *); }; class QmlGraphicsFlickableVisibleArea : public QObject diff --git a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp index f5abc18..5bab868 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp @@ -149,7 +149,7 @@ void QmlGraphicsFlipable::setFront(QmlGraphicsItem *front) return; } d->front = front; - fxChildren()->append(d->front); + d->front->setParentItem(this); if (Back == d->current) d->front->setOpacity(0.); } @@ -168,7 +168,7 @@ void QmlGraphicsFlipable::setBack(QmlGraphicsItem *back) return; } d->back = back; - fxChildren()->append(d->back); + d->back->setParentItem(this); if (Front == d->current) d->back->setOpacity(0.); } diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 22beb12..2e68264 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -892,7 +892,6 @@ void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event) parameter provides information about the event. */ - const QmlGraphicsKeysAttached::SigMap QmlGraphicsKeysAttached::sigMap[] = { { Qt::Key_Left, "leftPressed" }, { Qt::Key_Right, "rightPressed" }, @@ -1420,154 +1419,95 @@ QmlGraphicsAnchors *QmlGraphicsItem::anchors() return d->anchors(); } -void QmlGraphicsItemPrivate::data_removeAt(int) -{ - // ### -} - -int QmlGraphicsItemPrivate::data_count() const +void QmlGraphicsItemPrivate::data_append(QmlListProperty<QObject> *prop, QObject *o) { - // ### - return 0; -} - -void QmlGraphicsItemPrivate::data_append(QObject *o) -{ - Q_Q(QmlGraphicsItem); QmlGraphicsItem *i = qobject_cast<QmlGraphicsItem *>(o); - if (i) - q->fxChildren()->append(i); + if (i) + i->setParentItem(static_cast<QmlGraphicsItem *>(prop->object)); else - resources_append(o); -} - -void QmlGraphicsItemPrivate::data_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsItemPrivate::data_at(int) const -{ - // ### - return 0; + o->setParent(static_cast<QmlGraphicsItem *>(prop->object)); } -void QmlGraphicsItemPrivate::data_clear() +QObject *QmlGraphicsItemPrivate::resources_at(QmlListProperty<QObject> *prop, int index) { - // ### -} - -void QmlGraphicsItemPrivate::resources_removeAt(int) -{ - // ### -} - -int QmlGraphicsItemPrivate::resources_count() const -{ - Q_Q(const QmlGraphicsItem); - return q->children().count(); -} - -void QmlGraphicsItemPrivate::resources_append(QObject *o) -{ - Q_Q(QmlGraphicsItem); - o->setParent(q); -} - -void QmlGraphicsItemPrivate::resources_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsItemPrivate::resources_at(int idx) const -{ - Q_Q(const QmlGraphicsItem); - QObjectList children = q->children(); - if (idx < children.count()) - return children.at(idx); + QObjectList children = prop->object->children(); + if (index < children.count()) + return children.at(index); else return 0; } -void QmlGraphicsItemPrivate::resources_clear() +void QmlGraphicsItemPrivate::resources_append(QmlListProperty<QObject> *prop, QObject *o) { - // ### + o->setParent(prop->object); } -void QmlGraphicsItemPrivate::children_removeAt(int) +int QmlGraphicsItemPrivate::resources_count(QmlListProperty<QObject> *prop) { - // ### + return prop->object->children().count(); } -int QmlGraphicsItemPrivate::children_count() const +QmlGraphicsItem *QmlGraphicsItemPrivate::children_at(QmlListProperty<QmlGraphicsItem> *prop, int index) { - Q_Q(const QmlGraphicsItem); - return q->childItems().count(); -} + QList<QGraphicsItem *> children = static_cast<QmlGraphicsItem*>(prop->object)->childItems(); -void QmlGraphicsItemPrivate::children_append(QmlGraphicsItem *i) -{ - Q_Q(QmlGraphicsItem); - i->setParentItem(q); -} - -void QmlGraphicsItemPrivate::children_insert(int, QmlGraphicsItem *) -{ - // ### -} - -QmlGraphicsItem *QmlGraphicsItemPrivate::children_at(int idx) const -{ - Q_Q(const QmlGraphicsItem); - QList<QGraphicsItem *> children = q->childItems(); - if (idx < children.count()) - return qobject_cast<QmlGraphicsItem *>(children.at(idx)); + if (index < children.count()) + return qobject_cast<QmlGraphicsItem *>(children.at(index)); else return 0; } -void QmlGraphicsItemPrivate::children_clear() +void QmlGraphicsItemPrivate::children_append(QmlListProperty<QmlGraphicsItem> *prop, QmlGraphicsItem *i) { - // ### -} - - -void QmlGraphicsItemPrivate::transform_removeAt(int i) -{ - if (!transformData) - return; - transformData->graphicsTransforms.removeAt(i); - dirtySceneTransform = 1; + if (i) + i->setParentItem(static_cast<QmlGraphicsItem*>(prop->object)); } -int QmlGraphicsItemPrivate::transform_count() const +int QmlGraphicsItemPrivate::children_count(QmlListProperty<QmlGraphicsItem> *prop) { - return transformData ? transformData->graphicsTransforms.size() : 0; + return static_cast<QmlGraphicsItem*>(prop->object)->childItems().count(); } -void QmlGraphicsItemPrivate::transform_append(QGraphicsTransform *item) +int QmlGraphicsItemPrivate::transform_count(QmlListProperty<QGraphicsTransform> *list) { - appendGraphicsTransform(item); + QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object); + if (object) { + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object); + return d->transformData ? d->transformData->graphicsTransforms.size() : 0; + } else { + return 0; + } } -void QmlGraphicsItemPrivate::transform_insert(int, QGraphicsTransform *) +void QmlGraphicsItemPrivate::transform_append(QmlListProperty<QGraphicsTransform> *list, QGraphicsTransform *item) { - // ### + QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object); + if (object) + QGraphicsItemPrivate::get(object)->appendGraphicsTransform(item); } -QGraphicsTransform *QmlGraphicsItemPrivate::transform_at(int idx) const +QGraphicsTransform *QmlGraphicsItemPrivate::transform_at(QmlListProperty<QGraphicsTransform> *list, int idx) { - if (!transformData) + QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object); + if (object) { + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object); + if (!d->transformData) + return 0; + return d->transformData->graphicsTransforms.at(idx); + } else { return 0; - return transformData->graphicsTransforms.at(idx); + } } -void QmlGraphicsItemPrivate::transform_clear() +void QmlGraphicsItemPrivate::transform_clear(QmlListProperty<QGraphicsTransform> *list) { - if (!transformData) - return; - Q_Q(QmlGraphicsItem); - q->setTransformations(QList<QGraphicsTransform *>()); + QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object); + if (object) { + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object); + if (!d->transformData) + return; + object->setTransformations(QList<QGraphicsTransform *>()); + } } /*! @@ -1610,10 +1550,9 @@ void QmlGraphicsItemPrivate::transform_clear() */ /*! \internal */ -QmlList<QObject *> *QmlGraphicsItem::data() +QmlListProperty<QObject> QmlGraphicsItem::data() { - Q_D(QmlGraphicsItem); - return &d->data; + return QmlListProperty<QObject>(this, 0, QmlGraphicsItemPrivate::data_append); } /*! @@ -2215,17 +2154,19 @@ void QmlGraphicsItem::focusChanged(bool flag) } /*! \internal */ -QmlList<QmlGraphicsItem *> *QmlGraphicsItem::fxChildren() +QmlListProperty<QmlGraphicsItem> QmlGraphicsItem::fxChildren() { - Q_D(QmlGraphicsItem); - return &(d->children); + return QmlListProperty<QmlGraphicsItem>(this, 0, QmlGraphicsItemPrivate::children_append, + QmlGraphicsItemPrivate::children_count, + QmlGraphicsItemPrivate::children_at); } /*! \internal */ -QmlList<QObject *> *QmlGraphicsItem::resources() +QmlListProperty<QObject> QmlGraphicsItem::resources() { - Q_D(QmlGraphicsItem); - return &(d->resources); + return QmlListProperty<QObject>(this, 0, QmlGraphicsItemPrivate::resources_append, + QmlGraphicsItemPrivate::resources_count, + QmlGraphicsItemPrivate::resources_at); } /*! @@ -2250,7 +2191,7 @@ QmlList<QObject *> *QmlGraphicsItem::resources() \internal */ /*! \internal */ -QmlList<QmlState *>* QmlGraphicsItem::states() +QmlListProperty<QmlState> QmlGraphicsItem::states() { Q_D(QmlGraphicsItem); return d->states()->statesProperty(); @@ -2279,7 +2220,7 @@ QmlList<QmlState *>* QmlGraphicsItem::states() */ /*! \internal */ -QmlList<QmlTransition *>* QmlGraphicsItem::transitions() +QmlListProperty<QmlTransition> QmlGraphicsItem::transitions() { Q_D(QmlGraphicsItem); return d->states()->transitionsProperty(); @@ -2387,10 +2328,11 @@ void QmlGraphicsItem::setState(const QString &state) */ /*! \internal */ -QmlList<QGraphicsTransform *>* QmlGraphicsItem::transform() +QmlListProperty<QGraphicsTransform> QmlGraphicsItem::transform() { Q_D(QmlGraphicsItem); - return &(d->transform); + return QmlListProperty<QGraphicsTransform>(this, 0, d->transform_append, d->transform_count, + d->transform_at, d->transform_clear); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.h b/src/declarative/graphicsitems/qmlgraphicsitem.h index e1cf035..891fc88 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem.h @@ -70,11 +70,11 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlP Q_INTERFACES(QmlParserStatus) Q_PROPERTY(QmlGraphicsItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) - Q_PROPERTY(QmlList<QObject *> *data READ data DESIGNABLE false) - Q_PROPERTY(QmlList<QmlGraphicsItem *>* children READ fxChildren DESIGNABLE false NOTIFY childrenChanged) - Q_PROPERTY(QmlList<QObject *>* resources READ resources DESIGNABLE false) - Q_PROPERTY(QmlList<QmlState *>* states READ states DESIGNABLE false) - Q_PROPERTY(QmlList<QmlTransition *>* transitions READ transitions DESIGNABLE false) + Q_PROPERTY(QmlListProperty<QObject> data READ data DESIGNABLE false) + Q_PROPERTY(QmlListProperty<QmlGraphicsItem> children READ fxChildren DESIGNABLE false NOTIFY childrenChanged) + Q_PROPERTY(QmlListProperty<QObject> resources READ resources DESIGNABLE false) + Q_PROPERTY(QmlListProperty<QmlState> states READ states DESIGNABLE false) + Q_PROPERTY(QmlListProperty<QmlTransition> transitions READ transitions DESIGNABLE false) Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL) Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL) @@ -91,7 +91,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlP Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged) // ### move to QGI/QGO, NOTIFY Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) - Q_PROPERTY(QmlList<QGraphicsTransform *>* transform READ transform DESIGNABLE false FINAL) + Q_PROPERTY(QmlListProperty<QGraphicsTransform> transform READ transform DESIGNABLE false FINAL) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged) Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect) @@ -112,9 +112,9 @@ public: void setParentItem(QmlGraphicsItem *parent); void setParent(QmlGraphicsItem *parent) { setParentItem(parent); } - QmlList<QObject *> *data(); - QmlList<QmlGraphicsItem *> *fxChildren(); - QmlList<QObject *> *resources(); + QmlListProperty<QObject> data(); + QmlListProperty<QmlGraphicsItem> fxChildren(); + QmlListProperty<QObject> resources(); QmlGraphicsAnchors *anchors(); QRectF childrenRect(); @@ -122,8 +122,8 @@ public: bool clip() const; void setClip(bool); - QmlList<QmlState *>* states(); - QmlList<QmlTransition *>* transitions(); + QmlListProperty<QmlState> states(); + QmlListProperty<QmlTransition> transitions(); QString state() const; void setState(const QString &); @@ -131,7 +131,7 @@ public: qreal baselineOffset() const; void setBaselineOffset(qreal); - QmlList<QGraphicsTransform *> *transform(); + QmlListProperty<QGraphicsTransform> transform(); qreal width() const; void setWidth(qreal); diff --git a/src/declarative/graphicsitems/qmlgraphicsitem_p.h b/src/declarative/graphicsitems/qmlgraphicsitem_p.h index 7662a3b..4860b83 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem_p.h @@ -137,40 +137,23 @@ public: QString _id; // data property - void data_removeAt(int); - int data_count() const; - void data_append(QObject *); - void data_insert(int, QObject *); - QObject *data_at(int) const; - void data_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, data) + static void data_append(QmlListProperty<QObject> *, QObject *); // resources property - void resources_removeAt(int); - int resources_count() const; - void resources_append(QObject *); - void resources_insert(int, QObject *); - QObject *resources_at(int) const; - void resources_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, resources) + static QObject *resources_at(QmlListProperty<QObject> *, int); + static void resources_append(QmlListProperty<QObject> *, QObject *); + static int resources_count(QmlListProperty<QObject> *); // children property - void children_removeAt(int); - int children_count() const; - void children_append(QmlGraphicsItem *); - void children_insert(int, QmlGraphicsItem *); - QmlGraphicsItem *children_at(int) const; - void children_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QmlGraphicsItem *, children) + static QmlGraphicsItem *children_at(QmlListProperty<QmlGraphicsItem> *, int); + static void children_append(QmlListProperty<QmlGraphicsItem> *, QmlGraphicsItem *); + static int children_count(QmlListProperty<QmlGraphicsItem> *); // transform property - void transform_removeAt(int); - int transform_count() const; - void transform_append(QGraphicsTransform *); - void transform_insert(int, QGraphicsTransform *); - QGraphicsTransform *transform_at(int) const; - void transform_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QGraphicsTransform *, transform) + static int transform_count(QmlListProperty<QGraphicsTransform> *list); + static void transform_append(QmlListProperty<QGraphicsTransform> *list, QGraphicsTransform *); + static QGraphicsTransform *transform_at(QmlListProperty<QGraphicsTransform> *list, int); + static void transform_clear(QmlListProperty<QGraphicsTransform> *list); QmlGraphicsAnchors *anchors() { if (!_anchors) { @@ -381,7 +364,7 @@ class QmlGraphicsKeysAttached : public QObject, public QmlGraphicsItemKeyFilter Q_DECLARE_PRIVATE(QmlGraphicsKeysAttached) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QList<QmlGraphicsItem *> *forwardTo READ forwardTo) + Q_PROPERTY(QmlListProperty<QmlGraphicsItem> forwardTo READ forwardTo) public: QmlGraphicsKeysAttached(QObject *parent=0); @@ -396,9 +379,9 @@ public: } } - QList<QmlGraphicsItem *> *forwardTo() { + QmlListProperty<QmlGraphicsItem> forwardTo() { Q_D(QmlGraphicsKeysAttached); - return &d->targets; + return QmlListProperty<QmlGraphicsItem>(this, d->targets); } virtual void componentComplete(); diff --git a/src/declarative/graphicsitems/qmlgraphicspath.cpp b/src/declarative/graphicsitems/qmlgraphicspath.cpp index 7916bd3..4e4459d 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspath.cpp @@ -155,10 +155,10 @@ bool QmlGraphicsPath::isClosed() const \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 2 */ -QList<QmlGraphicsPathElement *>* QmlGraphicsPath::pathElements() +QmlListProperty<QmlGraphicsPathElement> QmlGraphicsPath::pathElements() { Q_D(QmlGraphicsPath); - return &(d->_pathElements); + return QmlListProperty<QmlGraphicsPathElement>(this, d->_pathElements); } void QmlGraphicsPath::interpolate(int idx, const QString &name, qreal value) diff --git a/src/declarative/graphicsitems/qmlgraphicspath_p.h b/src/declarative/graphicsitems/qmlgraphicspath_p.h index 51b7262..7ba5bbc 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspath_p.h @@ -189,7 +189,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserSta Q_OBJECT Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QList<QmlGraphicsPathElement *>* pathElements READ pathElements) + Q_PROPERTY(QmlListProperty<QmlGraphicsPathElement> pathElements READ pathElements) Q_PROPERTY(qreal startX READ startX WRITE setStartX) Q_PROPERTY(qreal startY READ startY WRITE setStartY) Q_PROPERTY(bool closed READ isClosed NOTIFY changed) @@ -199,7 +199,7 @@ public: QmlGraphicsPath(QObject *parent=0); ~QmlGraphicsPath(); - QList<QmlGraphicsPathElement *>* pathElements(); + QmlListProperty<QmlGraphicsPathElement> pathElements(); qreal startX() const; void setStartX(qreal x); diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h index c566027..66552f6 100644 --- a/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h @@ -107,14 +107,14 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject { Q_OBJECT - Q_PROPERTY(QList<QmlGraphicsGradientStop *> *stops READ stops) + Q_PROPERTY(QmlListProperty<QmlGraphicsGradientStop> stops READ stops) Q_CLASSINFO("DefaultProperty", "stops") public: QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} ~QmlGraphicsGradient() { delete m_gradient; } - QList<QmlGraphicsGradientStop *> *stops() { return &m_stops; } + QmlListProperty<QmlGraphicsGradientStop> stops() { return QmlListProperty<QmlGraphicsGradientStop>(this, m_stops); } const QGradient *gradient() const; diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 4ced2c3..b96f399 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -71,16 +71,14 @@ class QmlGraphicsVisualItemModelPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlGraphicsVisualItemModel) public: - QmlGraphicsVisualItemModelPrivate() : QObjectPrivate(), children(this) {} + QmlGraphicsVisualItemModelPrivate() : QObjectPrivate() {} - struct ItemList : public QmlConcreteList<QmlGraphicsItem *> - { - ItemList(QmlGraphicsVisualItemModelPrivate *m) : QmlConcreteList<QmlGraphicsItem *>(), model(m) {} - - void append(QmlGraphicsItem *item); - - QmlGraphicsVisualItemModelPrivate *model; - }; + static void children_append(QmlListProperty<QmlGraphicsItem> *prop, QmlGraphicsItem *item) { + item->QObject::setParent(prop->object); + static_cast<QmlGraphicsVisualItemModelPrivate *>(prop->data)->children.append(item); + static_cast<QmlGraphicsVisualItemModelPrivate *>(prop->data)->itemAppended(); + static_cast<QmlGraphicsVisualItemModelPrivate *>(prop->data)->emitChildrenChanged(); + } void itemAppended() { Q_Q(QmlGraphicsVisualItemModel); @@ -94,7 +92,8 @@ public: Q_Q(QmlGraphicsVisualItemModel); emit q->childrenChanged(); } - ItemList children; + + QList<QmlGraphicsItem *> children; }; @@ -132,10 +131,10 @@ QmlGraphicsVisualItemModel::QmlGraphicsVisualItemModel() { } -QmlList<QmlGraphicsItem *> *QmlGraphicsVisualItemModel::children() +QmlListProperty<QmlGraphicsItem> QmlGraphicsVisualItemModel::children() { Q_D(QmlGraphicsVisualItemModel); - return &(d->children); + return QmlListProperty<QmlGraphicsItem>(this, d, QmlGraphicsVisualItemModelPrivate::children_append); } /*! @@ -200,15 +199,6 @@ int QmlGraphicsVisualItemModel::indexOf(QmlGraphicsItem *item, QObject *) const return d->children.indexOf(item); } -void QmlGraphicsVisualItemModelPrivate::ItemList::append(QmlGraphicsItem *item) -{ - QmlConcreteList<QmlGraphicsItem*>::append(item); - item->QObject::setParent(model->q_ptr); - model->itemAppended(); - - model->emitChildrenChanged(); -} - QmlGraphicsVisualItemModelAttached *QmlGraphicsVisualItemModel::qmlAttachedProperties(QObject *obj) { return QmlGraphicsVisualItemModelAttached::properties(obj); @@ -422,8 +412,7 @@ int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, c QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { - if (model->m_listAccessor->type() == QmlListAccessor::QmlList - || model->m_listAccessor->type() == QmlListAccessor::QListPtr) { + if (model->m_listAccessor->type() == QmlListAccessor::ListProperty) { model->ensureRoles(); QObject *object = model->m_listAccessor->at(data->m_index).value<QObject*>(); if (object && object->property(name).isValid()) @@ -685,7 +674,7 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) } d->m_listAccessor = new QmlListAccessor; d->m_listAccessor->setList(model, d->m_context?d->m_context->engine():qmlEngine(this)); - if (d->m_listAccessor->type() != QmlListAccessor::QmlList && d->m_listAccessor->type() != QmlListAccessor::QListPtr) + if (d->m_listAccessor->type() != QmlListAccessor::ListProperty) d->m_metaDataCacheable = true; if (d->m_delegate && d->modelCount()) { emit itemsInserted(0, d->modelCount()); diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h index c0ea499..49f9b27 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h @@ -109,7 +109,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsVisualItemModel : public QmlGraphicsVisual Q_OBJECT Q_DECLARE_PRIVATE(QmlGraphicsVisualItemModel) - Q_PROPERTY(QmlList<QmlGraphicsItem *>* children READ children NOTIFY childrenChanged DESIGNABLE false) + Q_PROPERTY(QmlListProperty<QmlGraphicsItem> children READ children NOTIFY childrenChanged DESIGNABLE false) Q_CLASSINFO("DefaultProperty", "children") public: @@ -126,7 +126,7 @@ public: virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; - QmlList<QmlGraphicsItem *> *children(); + QmlListProperty<QmlGraphicsItem> children(); static QmlGraphicsVisualItemModelAttached *qmlAttachedProperties(QObject *obj); diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index 515f896..0c21f75 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -77,7 +77,6 @@ public: progress(1.0), status(QmlGraphicsWebView::Null), pending(PendingNone), newWindowComponent(0), newWindowParent(0), pressTime(400), - windowObjects(this), rendering(true) { } @@ -101,19 +100,14 @@ public: QPoint pressPoint; int pressTime; // milliseconds before it's a "hold" + + static void windowObjects_append(QmlListProperty<QObject> *prop, QObject *o) { + static_cast<QmlGraphicsWebViewPrivate *>(prop->data)->windowObjects.append(o); + static_cast<QmlGraphicsWebViewPrivate *>(prop->data)->updateWindowObjects(); + } + void updateWindowObjects(); - class WindowObjectList : public QmlConcreteList<QObject *> - { - public: - WindowObjectList(QmlGraphicsWebViewPrivate *p) - : priv(p) {} - virtual void append(QObject *v) { - QmlConcreteList<QObject *>::append(v); - priv->updateWindowObjects(); - } - private: - QmlGraphicsWebViewPrivate *priv; - } windowObjects; + QObjectList windowObjects; bool rendering; }; @@ -451,10 +445,10 @@ void QmlGraphicsWebView::paintPage(const QRect& r) If Javascript is not enabled for this page, then this property does nothing. */ -QmlList<QObject *> *QmlGraphicsWebView::javaScriptWindowObjects() +QmlListProperty<QObject> QmlGraphicsWebView::javaScriptWindowObjects() { Q_D(QmlGraphicsWebView); - return &d->windowObjects; + return QmlListProperty<QObject>(this, d, &QmlGraphicsWebViewPrivate::windowObjects_append); } QmlGraphicsWebViewAttached *QmlGraphicsWebView::qmlAttachedProperties(QObject *o) diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h index 1822ddb..30ba0e4 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h @@ -114,7 +114,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem Q_PROPERTY(QmlGraphicsWebSettings* settings READ settingsObject CONSTANT) - Q_PROPERTY(QmlList<QObject *>* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) + Q_PROPERTY(QmlListProperty<QObject> javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) @@ -174,7 +174,7 @@ public: bool renderingEnabled() const; void setRenderingEnabled(bool); - QmlList<QObject *> *javaScriptWindowObjects(); + QmlListProperty<QObject> javaScriptWindowObjects(); static QmlGraphicsWebViewAttached *qmlAttachedProperties(QObject *); |