10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
81Q_STATIC_LOGGING_CATEGORY(lcLayouts,
"qt.quick.layouts")
84QQuickLayoutItemProxy::QQuickLayoutItemProxy(QQuickItem *parent)
85 : QQuickItem(*
new QQuickLayoutItemProxyPrivate, parent)
92 Q_D(QQuickLayoutItemProxy);
102 d->target->setParentItem(
nullptr);
111
112
113
116 QQuickItem::geometryChange(newGeom, oldGeom);
120 const QSizeF sz = newGeom.size();
123 if (QQuickItem *t = effectiveTarget()) {
131 if (t->parentItem() !=
this)
132 pos = t->parentItem()->mapFromGlobal(mapToGlobal(0, 0));
134 if (t->size() == sz && t->position() == pos && newGeom == oldGeom)
143
144
145
148 if (c == QQuickItem::ItemVisibleHasChanged)
152 QQuickItem::itemChange(c, d);
161#define propertyForwarding(property, Property)
162 void QQuickLayoutItemProxy::target##Property##Changed() {
163 Q_D(QQuickLayoutItemProxy);
164 QQuickLayoutAttached *attTarget = attachedLayoutObject(target(), false);
165 QQuickLayoutAttached *attProxy = attachedLayoutObject(this, false);
166 if (!attTarget) return;
167 if (attProxy->property() == attTarget->property())
169 d->m_expectProxy##Property##Change = true;
170 attProxy->set##Property(attTarget->property());
172 void QQuickLayoutItemProxy::proxy##Property##Changed() {
173 Q_D(QQuickLayoutItemProxy);
174 if (d->m_expectProxy##Property##Change) {
175 d->m_expectProxy##Property##Change = false;
178 QQuickLayoutAttached *attTarget = attachedLayoutObject(target(), false);
179 if (!attTarget) return;
180 disconnect(attTarget, &QQuickLayoutAttached::property##Changed, this, &QQuickLayoutItemProxy::target##Property##Changed);
200#undef propertyForwarding
203
204
205
206
207
210
211
212
215 Q_D(
const QQuickLayoutItemProxy);
220
221
222
223
224
225
226
229 Q_D(QQuickLayoutItemProxy);
231 if (newTarget == d->target)
234 if (d->target && d->target->property(
"QQuickLayoutItemProxyAttachedData").isValid()) {
235 QQuickLayoutItemProxyAttachedData *attachedData = d->target->property(
"QQuickLayoutItemProxyAttachedData").value<QQuickLayoutItemProxyAttachedData*>();
236 attachedData->releaseProxy(
this);
238 d->target = newTarget;
242 QQuickLayoutItemProxyAttachedData *attachedData;
243 if (newTarget->property(
"QQuickLayoutItemProxyAttachedData").isValid()) {
244 attachedData = newTarget->property(
"QQuickLayoutItemProxyAttachedData").value<QQuickLayoutItemProxyAttachedData*>();
246 attachedData =
new QQuickLayoutItemProxyAttachedData(newTarget);
248 v.setValue(attachedData);
249 newTarget->setProperty(
"QQuickLayoutItemProxyAttachedData", v);
251 attachedData->registerProxy(
this);
254 if (!attachedData->proxyHasControl())
255 newTarget->setVisible(
false);
259 if (QQuickLayoutAttached *attTarget = attachedLayoutObject(newTarget)) {
260 QQuickLayoutAttached *attProxy = attachedLayoutObject(
this,
true);
262 disconnect(attTarget,
nullptr, attProxy,
nullptr);
266#define connectPropertyForwarding(property, Property)
267 if (!attProxy->is##Property##Set()) {
268 connect(attTarget, &QQuickLayoutAttached::property##Changed, this, &QQuickLayoutItemProxy::target##Property##Changed);
269 connect(attProxy, &QQuickLayoutAttached::property##Changed, this, &QQuickLayoutItemProxy::proxy##Property##Changed);
270 target##Property##Changed();
288#undef connectPropertyForwarding
291 auto fnBindImplW = [newTarget,
this](){
this->setImplicitWidth(newTarget->implicitWidth()); };
293 connect(newTarget, &QQuickItem::implicitWidthChanged, fnBindImplW);
296 auto fnBindImplH = [newTarget,
this](){
this->setImplicitHeight(newTarget->implicitHeight()); };
298 connect(newTarget, &QQuickItem::implicitHeightChanged, fnBindImplH);
305 emit targetChanged();
309
310
311
314 if (target() ==
nullptr)
318 return (attachedData->getControllingProxy() ==
this) ? target() :
nullptr;
322
323
324
325
326
333
334
335
336
337
338
339
340
343 Q_D(QQuickLayoutItemProxy);
350 d->target->setVisible(
true);
351 d->target->setParentItem(
this);
356 if (d->target->parentItem() ==
this) {
357 d->target->setParentItem(
nullptr);
359 qCDebug(lcLayouts) <<
"Parent was changed to" << d->target->parentItem() <<
"while an ItemProxy had control";
360 d->target->setVisible(
false);
366
367
368
375 if (attachedData->getControllingProxy() ==
this)
376 geometryChange(boundingRect(), boundingRect());
382 : QQuickItemPrivate(),
404
405
406
407
408
409
410
411
413 : QObject(parent), controllingProxy(
nullptr)
420 if (QObject *par = parent())
421 par->setProperty(
"QQuickLayoutItemProxyAttachedData", QVariant());
425 for (
auto &proxy: std::as_const(proxies))
426 proxy->clearTarget();
430
431
432
433
434
435
438 if (proxies.contains(proxy))
441 proxies.append(proxy);
442 emit proxiesChanged();
446
447
448
451 if (proxy == controllingProxy)
454 proxies.removeAll(proxy);
456 if (proxies.isEmpty())
459 emit proxiesChanged();
463
464
465
466
467
468
469
470
473 if (controllingProxy || !proxies.contains(proxy))
476 qCDebug(lcLayouts) << proxy
477 <<
"takes control of"
480 controllingProxy = proxy;
482 emit controllingProxyChanged();
487
488
489
490
491
494 if (controllingProxy != proxy)
497 qCDebug(lcLayouts) << proxy
498 <<
"no longer controls"
501 controllingProxy =
nullptr;
502 emit controlReleased();
503 emit controllingProxyChanged();
505 for (
auto &otherProxy: std::as_const(proxies)) {
506 if (proxy != otherProxy)
507 otherProxy->maybeTakeControl();
512
513
514
515
518 return controllingProxy;
522
523
524
528 using Property = QQmlListProperty<Type>;
532 [](Property *p) {
return static_cast<QList<Type *> *>(p->data)->size(); },
533 [](Property *p, qsizetype i) {
return static_cast<QList<Type *> *>(p->data)->at(i); }
538
539
540
543 return controllingProxy !=
nullptr;
Provides attached properties for items that are managed by one or more LayoutItemProxy.
QQmlListProperty< QQuickLayoutItemProxy > getProxies()
QQuickLayoutItemProxyAttachedData::getProxies.
void registerProxy(QQuickLayoutItemProxy *proxy)
QQuickLayoutItemProxyAttachedData::registerProxy registers a proxy that manages the item this data is...
void releaseControl(QQuickLayoutItemProxy *proxy)
QQuickLayoutItemProxyAttachedData::releaseControl is called by LayoutItemProxies when they try no lon...
bool proxyHasControl() const
QQuickLayoutItemProxyAttachedData::proxyHasControl.
~QQuickLayoutItemProxyAttachedData() override
bool takeControl(QQuickLayoutItemProxy *proxy)
QQuickLayoutItemProxyAttachedData::takeControl is called by LayoutItemProxies when they try to take c...
void releaseProxy(QQuickLayoutItemProxy *proxy)
QQuickLayoutItemProxyAttachedData::releaseProxy removes a proxy from a list of known proxies that man...
QQuickLayoutItemProxy * getControllingProxy() const
QQuickLayoutItemProxyAttachedData::getControllingProxy.
unsigned m_expectProxyMarginsChange
unsigned m_expectProxyFillHeightChange
unsigned m_expectProxyPreferredHeightChange
unsigned m_expectProxyMaximumHeightChange
unsigned m_expectProxyTopMarginChange
unsigned m_expectProxyBottomMarginChange
unsigned m_expectProxyFillWidthChange
unsigned m_expectProxyMinimumHeightChange
unsigned m_expectProxyRightMarginChange
unsigned m_expectProxyLeftMarginChange
unsigned m_expectProxyMinimumWidthChange
unsigned m_expectProxyPreferredWidthChange
unsigned m_expectProxyVerticalStretchFactorChange
unsigned m_expectProxyMaximumWidthChange
unsigned m_expectProxyHorizontalStretchFactorChange
unsigned m_expectProxyAlignmentChange
void clearTarget()
QQuickLayoutItemProxy::clearTarget sets the target to null.
void geometryChange(const QRectF &newGeom, const QRectF &oldGeom) override
QQuickLayoutItemProxy::geometryChange Reimplementation of QQuickItem::geometryChange to update the ta...
QQuickItem * target() const
\qmlproperty Item LayoutItemProxy::target
void itemChange(ItemChange c, const ItemChangeData &d) override
QQuickLayoutItemProxy::itemChange is a reimplementation of QQuickItem::itemChange to react to changes...
void maybeTakeControl()
QQuickLayoutItemProxy::maybeTakeControl checks and takes over control of the item.
~QQuickLayoutItemProxy() override
Combined button and popup list for selecting options.
#define connectPropertyForwarding(property, Property)
#define propertyForwarding(property, Property)