From aa634f86429ad15fced74a5a65e7d170b5e7e9ff Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 11 Oct 2015 00:04:55 +0200 Subject: Fix StackView attached property The attached properties weren't initialized at all for the initial item. Furthermore, the properties were initialized lazily, which made them work for imperative tests, but not correctly in bindings. Change-Id: I783c406dcf4e1cf27a6b4e6ddd43214cb06a3c7a Reviewed-by: J-P Nurmi --- src/templates/qquickstackview_p.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/templates/qquickstackview_p.cpp') diff --git a/src/templates/qquickstackview_p.cpp b/src/templates/qquickstackview_p.cpp index 498cc44c..a66e7d21 100644 --- a/src/templates/qquickstackview_p.cpp +++ b/src/templates/qquickstackview_p.cpp @@ -48,9 +48,12 @@ QT_BEGIN_NAMESPACE -static QQuickStackAttached *attachedStackObject(QQuickItem *item) +static QQuickStackAttached *attachedStackObject(QQuickStackElement *element) { - return qobject_cast(qmlAttachedPropertiesObject(item, false)); + QQuickStackAttached *attached = qobject_cast(qmlAttachedPropertiesObject(element->item, false)); + if (attached) + QQuickStackAttachedPrivate::get(attached)->element = element; + return attached; } class QQuickStackIncubator : public QQmlIncubator @@ -74,14 +77,9 @@ QQuickStackElement::QQuickStackElement() : QQuickItemViewTransitionableItem(Q_NU QQuickStackElement::~QQuickStackElement() { - if (item) { + if (item) QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed); - QQuickStackAttached *attached = attachedStackObject(item); - if (attached) - QQuickStackAttachedPrivate::get(attached)->reset(); - } - if (ownComponent) delete component; @@ -91,7 +89,13 @@ QQuickStackElement::~QQuickStackElement() item = Q_NULLPTR; } else if (item) { item->setVisible(false); - item->setParentItem(originalParent); + if (item->parentItem() != originalParent) { + item->setParentItem(originalParent); + } else { + QQuickStackAttached *attached = attachedStackObject(this); + if (attached) + QQuickStackAttachedPrivate::get(attached)->itemParentChanged(item, Q_NULLPTR); + } } delete context; @@ -182,7 +186,7 @@ void QQuickStackElement::setIndex(int value) { if (index != value) { index = value; - QQuickStackAttached *attached = attachedStackObject(item); + QQuickStackAttached *attached = attachedStackObject(this); if (attached) emit attached->indexChanged(); } @@ -192,7 +196,7 @@ void QQuickStackElement::setView(QQuickStackView *value) { if (view != value) { view = value; - QQuickStackAttached *attached = attachedStackObject(item); + QQuickStackAttached *attached = attachedStackObject(this); if (attached) emit attached->viewChanged(); } @@ -202,7 +206,7 @@ void QQuickStackElement::setStatus(QQuickStackView::Status value) { if (status != value) { status = value; - QQuickStackAttached *attached = attachedStackObject(item); + QQuickStackAttached *attached = attachedStackObject(this); if (attached) emit attached->statusChanged(); } -- cgit v1.2.3