diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2019-02-28 14:24:04 +0100 |
---|---|---|
committer | Aapo Keskimolo <aapo.keskimolo@qt.io> | 2019-03-05 12:04:03 +0000 |
commit | ff30fc5f5f637da6a06a33ae0e55d5e4b798099d (patch) | |
tree | 864327b54d6cddf1afb8cc63e91509e2a9380569 /tests | |
parent | 9fdbdea176007ed7b470e317e9002aa77ddd4ead (diff) |
QQuickScrollView: respect the content size set on/by the flickable
If the flickable inside a scrollview has an explicit content
size assigned, or if the flickable was created by the
application, then don't fall back to calculate the content
size. The reason is that it should not try to change the content
size of a flickable that is controlled by the application (or by
the flickable itself, in the case of ListView, ScrollView and
TextArea). Sometimes e.g ListView will report a negative
contentWidth, which is not considered illegal.
From before we used to just check if the child flickable had
a negative content size, and if so, take that as a evidence
that the flickable was owned by the scrollview. But with this
patch, we instead add two extra variables that keeps explicit
track of whether or not we should read the content size from the
flickable, regardless of the values it might return.
With the two new variables, we also no longer need the
"ownsFlickable" property, as we can instead use the new
variables to check for the same.
Fixes: QTBUG-72536
Fixes: QTBUG-74000
Fixes: QTBUG-72940
Change-Id: Iec87cc953557bf8c1bdb32a3c11b721c607fc19a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_scrollview.qml | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_scrollview.qml b/tests/auto/controls/data/tst_scrollview.qml index 4d5b1e5b..87c39509 100644 --- a/tests/auto/controls/data/tst_scrollview.qml +++ b/tests/auto/controls/data/tst_scrollview.qml @@ -146,6 +146,40 @@ TestCase { } Component { + id: scrollableFlickable + ScrollView { + Flickable { + Item { + width: 100 + height: 100 + } + } + } + } + + Component { + id: scrollableWithContentSize + ScrollView { + contentWidth: 1000 + contentHeight: 1000 + Flickable { + } + } + } + + Component { + id: scrollableAndFlicableWithContentSize + ScrollView { + contentWidth: 1000 + contentHeight: 1000 + Flickable { + contentWidth: 200 + contentHeight: 200 + } + } + } + + Component { id: scrollableTextArea ScrollView { TextArea { @@ -257,6 +291,61 @@ TestCase { compare(control.contentHeight, listview.contentHeight) } + function test_scrollableFlickable() { + // Check that if the application adds a flickable as a child of a + // scrollview, the scrollview doesn't try to calculate and change + // the flickables contentWidth/Height based on the flickables + // children, even if the flickable has an empty or negative content + // size. Some flickables (e.g ListView) sets a negative + // contentWidth on purpose, which should be respected. + var scrollview = createTemporaryObject(scrollableFlickable, testCase) + verify(scrollview) + + var flickable = scrollview.contentItem + verify(flickable.hasOwnProperty("contentX")) + verify(flickable.hasOwnProperty("contentY")) + + compare(flickable.contentWidth, -1) + compare(flickable.contentHeight, -1) + compare(scrollview.contentWidth, -1) + compare(scrollview.contentHeight, -1) + } + + function test_scrollableWithContentSize() { + // Check that if the scrollview has contentWidth/Height set, but + // not the flickable, then those values will be forwarded and used + // by the flickable (rather than trying to calculate the content size + // based on the flickables children). + var scrollview = createTemporaryObject(scrollableWithContentSize, testCase) + verify(scrollview) + + var flickable = scrollview.contentItem + verify(flickable.hasOwnProperty("contentX")) + verify(flickable.hasOwnProperty("contentY")) + + compare(flickable.contentWidth, 1000) + compare(flickable.contentHeight, 1000) + compare(scrollview.contentWidth, 1000) + compare(scrollview.contentHeight, 1000) + } + + function test_scrollableAndFlickableWithContentSize() { + // Check that if both the scrollview and the flickable has + // contentWidth/Height set (which is an inconsistency/fault + // by the app), the content size of the scrollview wins. + var scrollview = createTemporaryObject(scrollableAndFlicableWithContentSize, testCase) + verify(scrollview) + + var flickable = scrollview.contentItem + verify(flickable.hasOwnProperty("contentX")) + verify(flickable.hasOwnProperty("contentY")) + + compare(flickable.contentWidth, 1000) + compare(flickable.contentHeight, 1000) + compare(scrollview.contentWidth, 1000) + compare(scrollview.contentHeight, 1000) + } + function test_flickableWithExplicitContentSize() { var control = createTemporaryObject(emptyFlickable, testCase) verify(control) |