aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicklistview2/data/qtbug98315.qml
blob: bf2ed857b17d9720963894f35eca403280f957b7 (plain)
1
2
3
4
5
6
7
8
9
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQml.Models

Item {
    width: 500
    height: 200

    property list<QtObject> myModel: [
        QtObject {
            objectName: "Item 0"
            property bool selected: true
        },
        QtObject {
            objectName: "Item 1"
            property bool selected: false
        },
        QtObject {
            objectName: "Item 2"
            property bool selected: false
        },
        QtObject {
            objectName: "Item 3"
            property bool selected: true
        },
        QtObject {
            objectName: "Item 4"
            property bool selected: true
        },
        QtObject {
            objectName: "Item 5"
            property bool selected: true
        },
        QtObject {
            objectName: "Item 6"
            property bool selected: false
        }
    ]

    ListView {
        objectName: "listView"
        id: listview
        width: 500
        height: 200

        focus: true
        clip: true
        spacing: 2
        orientation: ListView.Horizontal
        highlightMoveDuration: 300
        highlightMoveVelocity: -1
        preferredHighlightBegin: (500 - 100) / 2
        preferredHighlightEnd: (500 + 100) / 2
        highlightRangeMode: ListView.StrictlyEnforceRange
        cacheBuffer: 500
        currentIndex: 1

        model: DelegateModel {
            id: delegateModel
            filterOnGroup: "visible"
            model: myModel
            groups: [
                DelegateModelGroup {
                    name: "visible"
                    includeByDefault: true
                }
            ]
            delegate: Rectangle {
                id: tile
                objectName: model.modelData.objectName

                width: 100
                height: 100
                border.width: 0
                anchors.verticalCenter: parent.verticalCenter

                visible: model.modelData.selected
                Component.onCompleted: {
                    DelegateModel.inPersistedItems = true
                    DelegateModel.inVisible = Qt.binding(function () {
                        return model.modelData.selected
                    })
                }

                property bool isCurrent: ListView.isCurrentItem
                color: isCurrent ? "red" : "green"

                Text {
                    id: valueText
                    anchors.centerIn: parent
                    text: model.modelData.objectName
                }
            }
        }
    }
}