diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2024-02-15 15:26:59 +0800 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2024-02-21 21:27:53 +0800 |
commit | 5f7b25a694eb46cc520b6dd2651f1e3f99e310f0 (patch) | |
tree | d623be2be6da36a104bc860b7a3358fe65300b55 /src/quickcontrols | |
parent | 55bc6f360927b73a9ece6c5ac5b8e2e07b0d8bb9 (diff) |
QQuickAttachedPropertyPropagator: fix child window propagation
After the recent changes to window code, a child window's transient
parent is not available as early as it used to be. Account for this
by listening to changes in the window's parent as we do for items.
Fixes: QTBUG-122008
Change-Id: I2cd93e3c487e7ce4567e740886ef65a756c1350f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/quickcontrols')
-rw-r--r-- | src/quickcontrols/qquickattachedpropertypropagator.cpp | 53 | ||||
-rw-r--r-- | src/quickcontrols/qquickattachedpropertypropagator.h | 4 |
2 files changed, 47 insertions, 10 deletions
diff --git a/src/quickcontrols/qquickattachedpropertypropagator.cpp b/src/quickcontrols/qquickattachedpropertypropagator.cpp index 855f48ad0a..d7af27663a 100644 --- a/src/quickcontrols/qquickattachedpropertypropagator.cpp +++ b/src/quickcontrols/qquickattachedpropertypropagator.cpp @@ -227,6 +227,7 @@ public: void setAttachedParent(QQuickAttachedPropertyPropagator *parent); void itemWindowChanged(QQuickWindow *window); + void transientParentWindowChanged(QWindow *newTransientParent); void itemParentChanged(QQuickItem *item, QQuickItem *parent) override; QList<QQuickAttachedPropertyPropagator *> attachedChildren; @@ -235,19 +236,23 @@ public: void QQuickAttachedPropertyPropagatorPrivate::attachTo(QObject *object) { - QQuickItem *item = findAttachedItem(object); - if (item) { + if (QQuickItem *item = findAttachedItem(object)) { connect(item, &QQuickItem::windowChanged, this, &QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged); QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent); + } else if (auto *window = qobject_cast<QQuickWindow *>(object)) { + QObjectPrivate::connect(window, &QWindow::transientParentChanged, this, + &QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged); } } void QQuickAttachedPropertyPropagatorPrivate::detachFrom(QObject *object) { - QQuickItem *item = findAttachedItem(object); - if (item) { + if (QQuickItem *item = findAttachedItem(object)) { disconnect(item, &QQuickItem::windowChanged, this, &QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged); QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent); + } else if (auto *window = qobject_cast<QQuickWindow *>(object)) { + QObjectPrivate::disconnect(window, &QWindow::transientParentChanged, + this, &QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged); } } @@ -276,14 +281,14 @@ void QQuickAttachedPropertyPropagatorPrivate::setAttachedParent(QQuickAttachedPr return; QQuickAttachedPropertyPropagator *oldParent = attachedParent; - qCDebug(lcAttached) << "setAttachedParent called on" << q->parent(); + qCDebug(lcAttached).noquote() << "setAttachedParent called on" << q << "with parent" << parent; if (attachedParent) { - qCDebug(lcAttached) << "- removing ourselves as an attached child of" << attachedParent->parent() << attachedParent; + qCDebug(lcAttached).noquote() << "- removing ourselves as an attached child of" << attachedParent; QQuickAttachedPropertyPropagatorPrivate::get(attachedParent)->attachedChildren.removeOne(q); } attachedParent = parent; if (parent) { - qCDebug(lcAttached) << "- adding ourselves as an attached child of" << parent->parent() << parent; + qCDebug(lcAttached).noquote() << "- adding ourselves as an attached child of" << parent; QQuickAttachedPropertyPropagatorPrivate::get(parent)->attachedChildren.append(q); } q->attachedParentChange(parent, oldParent); @@ -293,13 +298,24 @@ void QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged(QQuickWindow *wi { Q_Q(QQuickAttachedPropertyPropagator); QQuickAttachedPropertyPropagator *attachedParent = nullptr; - qCDebug(lcAttached) << "window of" << q->parent() << "changed to" << window; + qCDebug(lcAttached).noquote() << "window of" << q << "changed to" << window; attachedParent = findAttachedParent(q->metaObject(), q->parent()); if (!attachedParent) attachedParent = attachedObject(q->metaObject(), window); setAttachedParent(attachedParent); } +void QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged(QWindow *newTransientParent) +{ + Q_Q(QQuickAttachedPropertyPropagator); + QQuickAttachedPropertyPropagator *attachedParent = nullptr; + qCDebug(lcAttached).noquote() << "transient parent window of" << q << "changed to" << newTransientParent; + attachedParent = findAttachedParent(q->metaObject(), q->parent()); + if (!attachedParent) + attachedParent = attachedObject(q->metaObject(), newTransientParent); + setAttachedParent(attachedParent); +} + void QQuickAttachedPropertyPropagatorPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent) { Q_Q(QQuickAttachedPropertyPropagator); @@ -383,14 +399,15 @@ QQuickAttachedPropertyPropagator *QQuickAttachedPropertyPropagator::attachedPare void QQuickAttachedPropertyPropagator::initialize() { Q_D(QQuickAttachedPropertyPropagator); + qCDebug(lcAttached) << "initialize called for" << parent() << "- looking for attached parent..."; QQuickAttachedPropertyPropagator *attachedParent = findAttachedParent(metaObject(), parent()); if (attachedParent) d->setAttachedParent(attachedParent); const QList<QQuickAttachedPropertyPropagator *> attachedChildren = findAttachedChildren(metaObject(), parent()); - qCDebug(lcAttached) << "initialize called for" << parent() << "- found" << attachedChildren.size() << "attached children"; + qCDebug(lcAttached) << "- found" << attachedChildren.size() << "attached children:"; for (QQuickAttachedPropertyPropagator *child : attachedChildren) { - qCDebug(lcAttached) << "-" << child->parent(); + qCDebug(lcAttached) << " -" << child->parent(); QQuickAttachedPropertyPropagatorPrivate::get(child)->setAttachedParent(this); } } @@ -413,6 +430,22 @@ void QQuickAttachedPropertyPropagator::attachedParentChange(QQuickAttachedProper Q_UNUSED(oldParent); } +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug debug, const QQuickAttachedPropertyPropagator *propagator) +{ + QDebugStateSaver saver(debug); + debug.nospace().noquote(); + if (!propagator) { + debug << "QQuickAttachedPropertyPropagator(nullptr)"; + return debug; + } + + // Cast to QObject to avoid recursion. + debug << static_cast<const QObject *>(propagator) << " (which is attached to " << propagator->parent() << ')'; + return debug; +} +#endif + QT_END_NAMESPACE #include "moc_qquickattachedpropertypropagator.cpp" diff --git a/src/quickcontrols/qquickattachedpropertypropagator.h b/src/quickcontrols/qquickattachedpropertypropagator.h index ec5ff7991a..de3e20bf3f 100644 --- a/src/quickcontrols/qquickattachedpropertypropagator.h +++ b/src/quickcontrols/qquickattachedpropertypropagator.h @@ -29,6 +29,10 @@ protected: virtual void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent); private: +#ifndef QT_NO_DEBUG_STREAM + friend Q_QUICKCONTROLS2_EXPORT QDebug operator<<(QDebug debug, const QQuickAttachedPropertyPropagator *propagator); +#endif + Q_DECLARE_PRIVATE(QQuickAttachedPropertyPropagator) }; |