aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicklistview/data/reusedelegateitems.qml
blob: c54d10f88ca149ad9621c853e373b6f482096a32 (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
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick 2.15

Rectangle {
    id: root
    width: 640
    height: 480

    property int rows: 500
    property int columns: 20
    property real delegateHeight: 30
    property real delegateWidth: 50

    ListView {
        id: list
        anchors.fill: parent
        anchors.margins: 10
        objectName: "list"

        model: reuseModel
        reuseItems: true

        cacheBuffer: 0
        contentWidth: columns * delegateWidth
        contentHeight: rows * delegateHeight
        clip: true

        property int delegatesCreatedCount: 0

        delegate: Item {
            objectName: "delegate"
            width: list.contentWidth
            height: delegateHeight

            property int modelIndex: index
            property int reusedCount: 0
            property int pooledCount: 0
            property string displayBinding: display

            ListView.onPooled: pooledCount++
            ListView.onReused: reusedCount++
            Component.onCompleted: list.delegatesCreatedCount++

            Text {
                id: text1
                text: display + " (Model index: " + modelIndex + ", Reused count: " + reusedCount + ")"
            }
        }
    }
}