diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-09-28 15:59:39 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-09-28 14:10:11 +0000 |
commit | c5050daa16860b800dbc9782e94e0bacffd6bbf2 (patch) | |
tree | bbe8d3cadb3c1d130fc9b0b33a197e6347440938 | |
parent | ed9a677c3a27d1c2eeddb71b66f00bfc691df3fd (diff) |
QQuickScrollView: fix binding loop with wrapping TextArea
Start keeping track of the content size only after the component is
complete, to avoid creation time ping pong with content size updates
and content item resizing.
Task-number: QTBUG-62325
Change-Id: I4b75dc398d0b746dd7e0b04291270f47f91bb7e6
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickscrollview.cpp | 12 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_scrollview.qml | 25 |
2 files changed, 34 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickscrollview.cpp b/src/quicktemplates2/qquickscrollview.cpp index c05e4848..fa9a6c3b 100644 --- a/src/quicktemplates2/qquickscrollview.cpp +++ b/src/quicktemplates2/qquickscrollview.cpp @@ -205,7 +205,7 @@ bool QQuickScrollViewPrivate::setFlickable(QQuickFlickable *item, bool content) void QQuickScrollViewPrivate::updateContentWidth() { Q_Q(QQuickScrollView); - if (!flickable) + if (!flickable || !componentComplete) return; const qreal cw = flickable->contentWidth(); @@ -219,7 +219,7 @@ void QQuickScrollViewPrivate::updateContentWidth() void QQuickScrollViewPrivate::updateContentHeight() { Q_Q(QQuickScrollView); - if (!flickable) + if (!flickable || !componentComplete) return; const qreal ch = flickable->contentHeight(); @@ -551,8 +551,14 @@ void QQuickScrollView::componentComplete() { Q_D(QQuickScrollView); QQuickControl::componentComplete(); - if (!d->contentItem) + if (!d->contentItem) { d->ensureFlickable(true); + } else { + if (d->contentWidth <= 0) + d->updateContentWidth(); + if (d->contentHeight <= 0) + d->updateContentHeight(); + } } void QQuickScrollView::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) diff --git a/tests/auto/controls/data/tst_scrollview.qml b/tests/auto/controls/data/tst_scrollview.qml index c0b1a401..80110b5a 100644 --- a/tests/auto/controls/data/tst_scrollview.qml +++ b/tests/auto/controls/data/tst_scrollview.qml @@ -129,6 +129,16 @@ TestCase { } } + Component { + id: scrollableTextArea + ScrollView { + TextArea { + text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas id dignissim ipsum. Nam molestie nisl turpis." + wrapMode: TextArea.WordWrap + } + } + } + function test_scrollBars() { var control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200}) verify(control) @@ -339,4 +349,19 @@ TestCase { } compare(horizontal.position, 0.0) } + + function test_textArea() { + // TODO: verify no binding loop warnings (QTBUG-62325) + var control = createTemporaryObject(scrollableTextArea, testCase) + verify(control) + + var flickable = control.contentItem + verify(flickable && flickable.hasOwnProperty("contentX")) + + var textArea = flickable.contentItem.children[0] + verify(textArea && textArea.hasOwnProperty("text")) + + compare(control.contentWidth, flickable.contentWidth) + compare(control.contentHeight, flickable.contentHeight) + } } |