diff options
Diffstat (limited to 'src/quicktemplates2/qquickpopupanchors.cpp')
-rw-r--r-- | src/quicktemplates2/qquickpopupanchors.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickpopupanchors.cpp b/src/quicktemplates2/qquickpopupanchors.cpp index 5acc2934..c7ac038d 100644 --- a/src/quicktemplates2/qquickpopupanchors.cpp +++ b/src/quicktemplates2/qquickpopupanchors.cpp @@ -47,6 +47,15 @@ QQuickPopupAnchors::QQuickPopupAnchors(QQuickPopup *popup) d->popup = popup; } +QQuickPopupAnchors::~QQuickPopupAnchors() +{ + Q_D(const QQuickPopupAnchors); + if (d->centerIn) { + auto centerInPrivate = QQuickItemPrivate::get(d->centerIn); + centerInPrivate->removeItemChangeListener(this, QQuickItemPrivate::Destroyed); + } +} + QQuickItem *QQuickPopupAnchors::centerIn() const { Q_D(const QQuickPopupAnchors); @@ -59,8 +68,20 @@ void QQuickPopupAnchors::setCenterIn(QQuickItem *item) if (item == d->centerIn) return; + if (d->centerIn) { + auto centerInPrivate = QQuickItemPrivate::get(d->centerIn); + centerInPrivate->removeItemChangeListener(this, QQuickItemPrivate::Destroyed); + } + d->centerIn = item; + + if (d->centerIn) { + auto centerInPrivate = QQuickItemPrivate::get(d->centerIn); + centerInPrivate->addItemChangeListener(this, QQuickItemPrivate::Destroyed); + } + QQuickPopupPrivate::get(d->popup)->reposition(); + emit centerInChanged(); } @@ -69,4 +90,9 @@ void QQuickPopupAnchors::resetCenterIn() setCenterIn(nullptr); } +void QQuickPopupAnchors::itemDestroyed(QQuickItem *) +{ + resetCenterIn(); +} + QT_END_NAMESPACE |