112 qCDebug(lcAttached).noquote() <<
"findAttachedParent called with" << ourAttachedType->className() << objectWeAreAttachedTo;
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 auto popupItem = qobject_cast<QQuickPopupItem *>(objectWeAreAttachedTo);
134 qCDebug(lcAttached).noquote() <<
"- attachee is a popup item" << popupItem <<
"- checking if it has an attached object";
135 auto popupItemPrivate = QQuickPopupItemPrivate::get(popupItem);
136 QQuickAttachedPropertyPropagator *popupAttached = attachedObject(ourAttachedType, popupItemPrivate->popup);
138 qCDebug(lcAttached).noquote() <<
"- popup item has attached object" << popupAttached <<
"- returning";
139 return popupAttached;
141 qCDebug(lcAttached).noquote() <<
"- popup item does not have attached object";
144 qCDebug(lcAttached).noquote() <<
"- attachee is not a popup item";
147 QQuickItem *item = qobject_cast<QQuickItem *>(objectWeAreAttachedTo);
149 qCDebug(lcAttached).noquote() <<
"- attachee is an item; checking its parent items and popups";
151 QQuickItem *parent = item->parentItem();
153 qCDebug(lcAttached).noquote() <<
" - checking parent item" << parent;
154 QQuickAttachedPropertyPropagator *attached = attachedObject(ourAttachedType, parent);
156 qCDebug(lcAttached).noquote() <<
" - parent item has attached object" << attached <<
"- returning";
160 QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent->parent());
162 qCDebug(lcAttached).noquote() <<
" - parent popup has attached object" << attached <<
"- returning";
163 return attachedObject(ourAttachedType, popup);
166 parent = parent->parentItem();
170 qCDebug(lcAttached).noquote() <<
"- checking parent window" << item->window();
171 QQuickAttachedPropertyPropagator *attached = attachedObject(ourAttachedType, item->window());
173 qCDebug(lcAttached).noquote() <<
"- parent window has attached object" << attached <<
"- returning";
178 QQuickPopup *popup = qobject_cast<QQuickPopup *>(objectWeAreAttachedTo);
180 qCDebug(lcAttached).noquote() <<
"- attachee is a popup; checking its window";
181 auto *window = popup->popupItem()->window();
182 auto *object = attachedObject(ourAttachedType, window);
185 if (!object && qobject_cast<QQuickPopupWindow *>(window)) {
186 auto *transientParentWnd = window->transientParent();
188 object = attachedObject(ourAttachedType, transientParentWnd);
191 transientParentWnd = transientParentWnd->transientParent();
192 }
while (transientParentWnd);
193 qCDebug(lcAttached).noquote() <<
"- attached object of the transient parent window: " << object;
200 QQuickWindow *window = qobject_cast<QQuickWindow *>(objectWeAreAttachedTo);
203 QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(window->transientParent());
204 qCDebug(lcAttached).noquote() <<
"- attachee is a window; checking its parent window" << parentWindow;
206 QQuickAttachedPropertyPropagator *attached = attachedObject(ourAttachedType, parentWindow);
208 qCDebug(lcAttached).noquote() <<
"- parent window has attached object" << attached <<
"- returning";
215 if (objectWeAreAttachedTo) {
216 QQmlEngine *engine = qmlEngine(objectWeAreAttachedTo);
217 qCDebug(lcAttached).noquote() <<
"- falling back to engine" << engine;
219 QByteArray name = QByteArray(
"_q_") + ourAttachedType->className();
220 QQuickAttachedPropertyPropagator *attached = engine->property(name).value<QQuickAttachedPropertyPropagator *>();
222 attached = attachedObject(ourAttachedType, engine,
true);
223 engine->setProperty(name, QVariant::fromValue(attached));
234 QList<QQuickAttachedPropertyPropagator *> children;
236 QQuickItem *item = qobject_cast<QQuickItem *>(object);
238 QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
240 item = window->contentItem();
251 const auto childItems = item->childItems();
252 for (QQuickItem *child : childItems) {
253 QQuickAttachedPropertyPropagator *attached = attachedObject(type, child);
255 children += attached;
257 children += findAttachedChildren(type, child);
264 const auto &windowChildren = item->children();
265 for (QObject *child : windowChildren) {
266 QQuickWindow *childWindow = qobject_cast<QQuickWindow *>(child);
268 QQuickAttachedPropertyPropagator *attached = attachedObject(type, childWindow);
270 children += attached;
313 if (QQuickItem *item = findAttachedItem(object)) {
314 connect(item, &QQuickItem::windowChanged,
this, &QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged);
315 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickItemPrivate::Parent);
316 }
else if (
auto *window = qobject_cast<QQuickWindow *>(object)) {
317 QObjectPrivate::connect(window, &QWindow::transientParentChanged,
this,
318 &QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged);
324 if (QQuickItem *item = findAttachedItem(object)) {
325 disconnect(item, &QQuickItem::windowChanged,
this, &QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged);
326 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Parent);
327 }
else if (
auto *window = qobject_cast<QQuickWindow *>(object)) {
328 QObjectPrivate::disconnect(window, &QWindow::transientParentChanged,
329 this, &QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged);
353 Q_Q(QQuickAttachedPropertyPropagator);
354 if (attachedParent == parent)
357 QQuickAttachedPropertyPropagator *oldParent = attachedParent;
358 qCDebug(lcAttached).noquote() <<
"setAttachedParent called on" << q <<
"with parent" << parent;
359 if (attachedParent) {
360 qCDebug(lcAttached).noquote() <<
"- removing ourselves as an attached child of" << attachedParent;
361 QQuickAttachedPropertyPropagatorPrivate::get(attachedParent)->attachedChildren.removeOne(q);
363 attachedParent = parent;
365 qCDebug(lcAttached).noquote() <<
"- adding ourselves as an attached child of" << parent;
366 QQuickAttachedPropertyPropagatorPrivate::get(parent)->attachedChildren.append(q);
368 q->attachedParentChange(parent, oldParent);
490void QQuickAttachedPropertyPropagator::initialize()
492 Q_D(QQuickAttachedPropertyPropagator);
493 qCDebug(lcAttached) <<
"initialize called for" << parent() <<
"- looking for attached parent...";
494 QQuickAttachedPropertyPropagator *attachedParent = findAttachedParent(metaObject(), parent());
496 d->setAttachedParent(attachedParent);
498 const QList<QQuickAttachedPropertyPropagator *> attachedChildren = findAttachedChildren(metaObject(), parent());
499 qCDebug(lcAttached) <<
"- found" << attachedChildren.size() <<
"attached children:";
500 for (QQuickAttachedPropertyPropagator *child : attachedChildren) {
501 qCDebug(lcAttached) <<
" -" << child->parent();
502 QQuickAttachedPropertyPropagatorPrivate::get(child)->setAttachedParent(
this);
505 qCDebug(lcAttached) <<
"... finished initializing";