diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-03-16 15:58:28 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-03-22 21:22:17 +0000 |
commit | 2b0e33692b949ebaed034c72d0ea3da9f0ef6de2 (patch) | |
tree | 4ca7dace8012aae0dad5080362884fec4f64703f /src/quicktemplates2 | |
parent | 1abc7fcbabcc5a89ceaaf69173d077e22ed2d658 (diff) |
QQuickPane: fix a regression in implicit size calculation
Caused by 87dec64. Previously, the bindings were:
contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0)
contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0)
That is, if contentItem does not have implicit size, Pane uses the
implicit size of the first content child (if there's one). When the
new automatic content size calculation was implemented, I forgot to
install a listener on the content child (in addition to contentItem).
Consequently, if the imlicit size of the first content child changed
after construction, the content size was not updated as appropriate.
Change-Id: Ib3d81f4e08a4d0822849d5db12429a2dd036e206
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickpane.cpp | 24 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpane_p_p.h | 1 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickpane.cpp b/src/quicktemplates2/qquickpane.cpp index 98c4d1f3..60f27159 100644 --- a/src/quicktemplates2/qquickpane.cpp +++ b/src/quicktemplates2/qquickpane.cpp @@ -112,7 +112,8 @@ QQuickPanePrivate::QQuickPanePrivate() : hasContentWidth(false), hasContentHeight(false), contentWidth(0), - contentHeight(0) + contentHeight(0), + firstChild(nullptr) { } @@ -143,14 +144,14 @@ void QQuickPanePrivate::removeImplicitSizeListener(QQuickItem *item) void QQuickPanePrivate::itemImplicitWidthChanged(QQuickItem *item) { Q_Q(QQuickPane); - if (item == contentItem && updateContentWidth(item)) + if ((item == contentItem || item == firstChild) && updateContentWidth(contentItem)) emit q->contentWidthChanged(); } void QQuickPanePrivate::itemImplicitHeightChanged(QQuickItem *item) { Q_Q(QQuickPane); - if (item == contentItem && updateContentHeight(item)) + if ((item == contentItem || item == firstChild) && updateContentHeight(contentItem)) emit q->contentHeightChanged(); } @@ -163,6 +164,15 @@ void QQuickPanePrivate::itemDestroyed(QQuickItem *item) void QQuickPanePrivate::contentChildrenChange() { Q_Q(QQuickPane); + QQuickItem *newFirstChild = contentItem->childItems().value(0); + if (newFirstChild != firstChild) { + if (firstChild) + removeImplicitSizeListener(firstChild); + if (newFirstChild) + addImplicitSizeListener(newFirstChild); + firstChild = newFirstChild; + } + updateContentSize(contentItem); emit q->contentChildrenChanged(); } @@ -244,6 +254,7 @@ QQuickPane::~QQuickPane() { Q_D(QQuickPane); d->removeImplicitSizeListener(d->contentItem); + d->removeImplicitSizeListener(d->firstChild); } QQuickPane::QQuickPane(QQuickPanePrivate &dd, QQuickItem *parent) @@ -383,10 +394,17 @@ void QQuickPane::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) QQuickControl::contentItemChange(newItem, oldItem); if (oldItem) { d->removeImplicitSizeListener(oldItem); + if (d->firstChild) { + d->removeImplicitSizeListener(d->firstChild); + d->firstChild = nullptr; + } QObjectPrivate::disconnect(oldItem, &QQuickItem::childrenChanged, d, &QQuickPanePrivate::contentChildrenChange); } if (newItem) { d->addImplicitSizeListener(newItem); + d->firstChild = newItem->childItems().value(0); + if (d->firstChild) + d->addImplicitSizeListener(d->firstChild); QObjectPrivate::connect(newItem, &QQuickItem::childrenChanged, d, &QQuickPanePrivate::contentChildrenChange); } d->updateContentSize(newItem); diff --git a/src/quicktemplates2/qquickpane_p_p.h b/src/quicktemplates2/qquickpane_p_p.h index 4d9a1747..cb347e85 100644 --- a/src/quicktemplates2/qquickpane_p_p.h +++ b/src/quicktemplates2/qquickpane_p_p.h @@ -81,6 +81,7 @@ public: bool hasContentHeight; qreal contentWidth; qreal contentHeight; + QQuickItem *firstChild; }; QT_END_NAMESPACE |