From 0d31b86d1fd0fdbcc95c80ce91f505a2c8b0bc26 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 30 Sep 2010 17:23:27 +0200 Subject: Use setParentItem() instead of setParentItemHelper if componentComplete is true This ensures that if the component has already been completed, itemChange() is called. This is required to modify QDeclarativePositions in the visual editor, while keeping a legal state. Without this patch notifications are missing and the Positioner keeps track of already deleted children. This resulted in a crash. Reviewed-by: Thomas Hartmann (cherry picked from commit 1f8bb573f06234a3d13fb57de5eb644824d5024f) --- .../graphicsitems/qdeclarativeflickable.cpp | 24 +++++++++++++++++----- src/declarative/graphicsitems/qdeclarativeitem.cpp | 19 +++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 84b0ccf..29879fe 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -1046,10 +1046,16 @@ void QDeclarativeFlickable::cancelFlick() void QDeclarativeFlickablePrivate::data_append(QDeclarativeListProperty *prop, QObject *o) { QGraphicsObject *i = qobject_cast(o); - if (i) - i->setParentItem(static_cast(prop->data)->contentItem); - else + if (i) { + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(i); + if (static_cast(d)->componentComplete) { + i->setParentItem(static_cast(prop->data)->contentItem); + } else { + d->setParentItemHelper(static_cast(prop->data)->contentItem, 0, 0); + } + } else { o->setParent(prop->object); + } } static inline int children_count_helper(QGraphicsObject *object) @@ -1071,8 +1077,16 @@ static inline void children_clear_helper(QGraphicsObject *object) { QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object); int childCount = d->children.count(); - for (int index = 0 ;index < childCount; index++) - QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0); + if (static_cast(d)->componentComplete) { + for (int index = 0 ;index < childCount; index++) { + d->children.at(0)->setParentItem(0); + } + } else { + for (int index = 0 ;index < childCount; index++) { + QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0); + } + } + } int QDeclarativeFlickablePrivate::data_count(QDeclarativeListProperty *prop) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 3c2f0a8..830f8e3 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1614,7 +1614,13 @@ void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty *pro while (mo && mo != &QGraphicsObject::staticMetaObject) mo = mo->d.superdata; if (mo) { - QGraphicsItemPrivate::get(static_cast(o))->setParentItemHelper(that, 0, 0); + QGraphicsObject *graphicsObject = static_cast(o); + QDeclarativeItemPrivate *contentItemPrivate = static_cast(QGraphicsItemPrivate::get(graphicsObject)); + if (contentItemPrivate->componentComplete) { + graphicsObject->setParentItem(that); + } else { + contentItemPrivate->setParentItemHelper(that, /*newParentVariant=*/0, /*thisPointerVariant=*/0); + } } else { o->setParent(that); } @@ -1637,10 +1643,15 @@ static inline QObject *children_at_helper(QDeclarativeListProperty *pro static inline void children_clear_helper(QDeclarativeListProperty *prop) { - QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast(prop->object)); + QDeclarativeItemPrivate *d = static_cast(QGraphicsItemPrivate::get(static_cast(prop->object))); int childCount = d->children.count(); - for (int index = 0 ;index < childCount; index++) - QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0); + if (d->componentComplete) { + for (int index = 0 ;index < childCount; index++) + d->children.at(0)->setParentItem(0); + } else { + for (int index = 0 ;index < childCount; index++) + QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0); + } } int QDeclarativeItemPrivate::data_count(QDeclarativeListProperty *prop) -- cgit v0.12