diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-10-11 00:04:55 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-10-11 13:05:28 +0000 |
commit | aa634f86429ad15fced74a5a65e7d170b5e7e9ff (patch) | |
tree | 21e24400e65ff10e5f45a6b93230de77b9f36aa1 /src/templates/qquickstackview.cpp | |
parent | 9d4c6278217fecefa15c52073f8de0e6f0e7700d (diff) |
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 <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickstackview.cpp')
-rw-r--r-- | src/templates/qquickstackview.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/templates/qquickstackview.cpp b/src/templates/qquickstackview.cpp index 4439e176..1883d9d0 100644 --- a/src/templates/qquickstackview.cpp +++ b/src/templates/qquickstackview.cpp @@ -673,6 +673,7 @@ void QQuickStackView::componentComplete() if (d->pushElement(element)) { emit depthChanged(); d->setCurrentItem(element->item); + element->setStatus(QQuickStackView::Active); } } @@ -702,39 +703,40 @@ bool QQuickStackView::childMouseEventFilter(QQuickItem *, QEvent *) return true; } -void QQuickStackAttachedPrivate::init() -{ - QQuickItem *item = qobject_cast<QQuickItem *>(parent); - if (item) { - QQuickStackView *view = qobject_cast<QQuickStackView *>(item->parentItem()); - if (view) { - element = QQuickStackViewPrivate::get(view)->findElement(item); - if (element) - initialized = true; - } - } -} - -void QQuickStackAttachedPrivate::reset() +void QQuickStackAttachedPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent) { Q_Q(QQuickStackAttached); int oldIndex = element ? element->index : -1; QQuickStackView *oldView = element ? element->view : Q_NULLPTR; QQuickStackView::Status oldStatus = element ? element->status : QQuickStackView::Inactive; - element = Q_NULLPTR; + QQuickStackView *newView = qobject_cast<QQuickStackView *>(parent); + element = newView ? QQuickStackViewPrivate::get(newView)->findElement(item) : Q_NULLPTR; - if (oldIndex != -1) + int newIndex = element ? element->index : -1; + QQuickStackView::Status newStatus = element ? element->status : QQuickStackView::Inactive; + + if (oldIndex != newIndex) emit q->indexChanged(); - if (oldView) + if (oldView != newView) emit q->viewChanged(); - if (oldStatus != QQuickStackView::Inactive) + if (oldStatus != newStatus) emit q->statusChanged(); } QQuickStackAttached::QQuickStackAttached(QQuickItem *parent) : QObject(*(new QQuickStackAttachedPrivate), parent) { + Q_D(QQuickStackAttached); + QQuickItemPrivate::get(parent)->addItemChangeListener(d, QQuickItemPrivate::Parent); + d->itemParentChanged(parent, parent->parentItem()); +} + +QQuickStackAttached::~QQuickStackAttached() +{ + Q_D(QQuickStackAttached); + QQuickItem *parentItem = static_cast<QQuickItem *>(parent()); + QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent); } /*! @@ -745,8 +747,6 @@ QQuickStackAttached::QQuickStackAttached(QQuickItem *parent) : int QQuickStackAttached::index() const { Q_D(const QQuickStackAttached); - if (!d->initialized) - const_cast<QQuickStackAttachedPrivate *>(d)->init(); return d->element ? d->element->index : -1; } @@ -758,8 +758,6 @@ int QQuickStackAttached::index() const QQuickStackView *QQuickStackAttached::view() const { Q_D(const QQuickStackAttached); - if (!d->initialized) - const_cast<QQuickStackAttachedPrivate *>(d)->init(); return d->element ? d->element->view : Q_NULLPTR; } @@ -771,8 +769,6 @@ QQuickStackView *QQuickStackAttached::view() const QQuickStackView::Status QQuickStackAttached::status() const { Q_D(const QQuickStackAttached); - if (!d->initialized) - const_cast<QQuickStackAttachedPrivate *>(d)->init(); return d->element ? d->element->status : QQuickStackView::Inactive; } |