aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmldelegatemodel/data/viewUpdatedOnDelegateChoiceAffectingRoleChange.qml
blob: b2367b3a6e56eb5c1c56c34e0d42a5679a836fa3 (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
import QtQuick
import Qt.labs.qmlmodels
import QtQml.Models

Item {
    id: root
    property bool triggered: false
    onTriggeredChanged: {
        rootLM.setProperty(1, "currentRole", "first");
    }
    width: 800
    height: 680

    function verify(): bool {
        rootLV.currentIndex = 1; // needed for itemAtIndex to work
        if (root.triggered)
            return rootLV.itemAtIndex(0).isFirst && rootLV.itemAtIndex(1).isFirst;
        else
            return rootLV.itemAtIndex(0).isFirst && !rootLV.itemAtIndex(1).isFirst;
    }

    ListModel {
        id: rootLM
        ListElement {
            currentRole: "first"
            firstText: "TEXT_FIRST_1"
            secondText: "TEXT_SECOND_1"
        }
        ListElement {
            currentRole: "second"
            firstText: "TEXT_FIRST_2"
            secondText: "TEXT_SECOND_2"
        }
    }

    DelegateModel {
        id: delModel
        model: rootLM
        delegate: DelegateChooser {
            id: delegateChooser
            role: "currentRole"
            DelegateChoice {
                roleValue: "first"
                Rectangle {
                    property bool isFirst: true
                    height: 30
                    width: rootLV.width
                    color: "yellow"
                    Text {
                        anchors.centerIn: parent
                        text: firstText + "    " + currentRole
                    }
                }
            }
            DelegateChoice {
                roleValue: "second"
                Rectangle {
                    property bool isFirst: false
                    height: 30
                    width: rootLV.width
                    color: "red"
                    Text {
                        anchors.centerIn: parent
                        text: secondText + "    " + currentRole
                    }
                }
            }
        }
    }

    TapHandler {
        // for manual testing
        onTapped: root.triggered = true
    }

    Rectangle {
        width: 200
        height: 300
        anchors.centerIn: parent
        border.color: "black"
        border.width: 1
        color: "blue"

        ListView {
            id: rootLV
            objectName: "listview"
            anchors.margins: 30
            anchors.fill: parent
            cacheBuffer: 0
            model: delModel
        }
    }
}