aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicklistview2/data/delegateModelRefresh.qml
blob: 7a2a01751552737f976c32eb25ad884976218314 (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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

import QtQuick
import QtQuick.Controls
import QtQml.Models

ApplicationWindow {
    id: window
    visible: true
    width: 400
    height: 800
    property bool done: false

    ListView {
        model: delegateModel
        anchors.fill: parent
    }

    DelegateModel {
        id: delegateModel
        model: ListModel {
            ListElement {
                available: true
            }
            ListElement {
                available: true
            }
            ListElement {
                available: true
            }
        }

        Component.onCompleted: {
            delegateModel.refresh()
            done = true;
        }
        function refresh() {
            var rowCount = delegateModel.model.count;
            const flatItemsList = []
            for (var i = 0; i < rowCount; i++) {
                var entry = delegateModel.model.get(i);
                flatItemsList.push(entry)
            }

            for (i = 0; i < flatItemsList.length; ++i) {
                var item = flatItemsList[i]
                if (item !== null)
                    items.insert(item)
            }
        }
    }
}