chore(DoubleFlickableWithFolding): Inline component moved to separate file

Otherwise it would crash tests under Qt 5.15.2
Additionally Storybook page has been extended by adding footers.
This commit is contained in:
Michał Cieślak 2024-01-30 11:33:44 +01:00 committed by Michał
parent 9fe60e650f
commit 8509dd9c67
4 changed files with 84 additions and 32 deletions

View File

@ -1,6 +1,7 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls 2.15 import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import QtQml 2.15
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Utils 0.1 import StatusQ.Core.Utils 0.1
@ -15,6 +16,8 @@ SplitView {
readonly property int header1Size: 40 readonly property int header1Size: 40
readonly property int header2Size: 40 readonly property int header2Size: 40
readonly property int footerSize: 60
function fillModel(model, count) { function fillModel(model, count) {
const content = [] const content = []
@ -104,6 +107,29 @@ SplitView {
} }
} }
footer: Rectangle {
z: 1
height: root.footerSize
width: grid1.width
Label {
anchors.centerIn: parent
text: "placeholder 1"
}
color: "yellow"
}
Binding {
target: grid1
property: "footer"
when: !grid1.model || grid1.count !== 0
//when: grid1.count !== 0
value: null
restoreMode: Binding.RestoreBindingOrValue
}
delegate: Rectangle { delegate: Rectangle {
width: grid1.cellWidth width: grid1.cellWidth
height: grid1.cellHeight height: grid1.cellHeight
@ -156,6 +182,28 @@ SplitView {
} }
} }
footer: Rectangle {
z: 1
height: root.footerSize
width: grid2.width
Label {
anchors.centerIn: parent
text: "placeholder 2"
}
color: "yellow"
}
Binding {
target: grid2
property: "footer"
when: !grid2.model || grid2.count !== 0
value: null
restoreMode: Binding.RestoreBindingOrValue
}
delegate: Rectangle { delegate: Rectangle {
width: grid2.cellWidth width: grid2.cellWidth
height: grid2.cellHeight height: grid2.cellHeight

View File

@ -1,6 +1,8 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQml 2.15 import QtQml 2.15
import "internal"
DoubleFlickable { DoubleFlickable {
readonly property bool flickable1Folded: !d.grid1ContentInViewport readonly property bool flickable1Folded: !d.grid1ContentInViewport
readonly property bool flickable2Folded: d.grid2HeaderAtEnd || d.model2Blocked readonly property bool flickable2Folded: d.grid2HeaderAtEnd || d.model2Blocked
@ -49,50 +51,22 @@ DoubleFlickable {
} }
} }
// The Flickable component (ListView or GridView) controls y positioning
// of the header and it cannot be effectively overriden. As a solution to
// this problem, the header can be reparented to a wrapper compensating
// for the y offset.
HeaderWrapper { HeaderWrapper {
id: header1Wrapper
parent: contentItem parent: contentItem
flickable: flickable1 flickable: flickable1
y: contentY y: contentY
} }
HeaderWrapper { HeaderWrapper {
id: header2Wrapper
parent: contentItem parent: contentItem
flickable: flickable2 flickable: flickable2
y: contentY + d.grid2HeaderOffset y: contentY + d.grid2HeaderOffset
} }
// The Flickable component (ListView or GridView) controls y positioning
// of the header and it cannot be effectively overriden. As a solution to
// this problem, the header can be reparented to a wrapper compensating
// for the y offset.
component HeaderWrapper: Item {
property Flickable flickable
z: 1
Binding {
when: flickable.headerItem
target: flickable.headerItem
property: "parent"
value: container
restoreMode: Binding.RestoreBindingOrValue
}
Binding {
when: flickable.headerItem
target: container
property: "y"
value: -flickable.headerItem.y
restoreMode: Binding.RestoreBindingOrValue
}
Item { id: container }
}
QtObject { QtObject {
id: d id: d

View File

@ -0,0 +1,29 @@
import QtQuick 2.15
import QtQml 2.15
// This component is implementation detail of DoubleFlickableWithFolding
// Moved to external file instead of using inline component because a bug
// in Qt 5.15.2 causing tests crash.
Item {
property Flickable flickable
z: 1
Binding {
when: flickable.headerItem
target: flickable.headerItem
property: "parent"
value: container
restoreMode: Binding.RestoreBindingOrValue
}
Binding {
when: flickable.headerItem
target: container
property: "y"
value: -flickable.headerItem.y
restoreMode: Binding.RestoreBindingOrValue
}
Item { id: container }
}

View File

@ -181,6 +181,7 @@
<file>StatusQ/Core/Utils/ClippingWrapper.qml</file> <file>StatusQ/Core/Utils/ClippingWrapper.qml</file>
<file>StatusQ/Core/Utils/DoubleFlickable.qml</file> <file>StatusQ/Core/Utils/DoubleFlickable.qml</file>
<file>StatusQ/Core/Utils/DoubleFlickableWithFolding.qml</file> <file>StatusQ/Core/Utils/DoubleFlickableWithFolding.qml</file>
<file>StatusQ/Core/Utils/internal/HeaderWrapper.qml</file>
<file>StatusQ/Core/Utils/Emoji.qml</file> <file>StatusQ/Core/Utils/Emoji.qml</file>
<file>StatusQ/Core/Utils/JSONListModel.qml</file> <file>StatusQ/Core/Utils/JSONListModel.qml</file>
<file>StatusQ/Core/Utils/ModelChangeGuard.qml</file> <file>StatusQ/Core/Utils/ModelChangeGuard.qml</file>