blob: 4c513df905c3f7a2bde7a6acac05b031f894a56b (
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
|
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Window
Item {
id: win
height: 640
width: 480
property string currentModel: 'foo'
function toggle() : Item {
var ret = listView.itemAtIndex(0);
win.currentModel = win.currentModel === 'foo' ? 'bar' : 'foo'
switch (win.currentModel) {
case 'foo':
if (listView.model) {
listView.model.destroy()
}
listView.model = fooModelComponent.createObject(win)
break
case 'bar':
if (listView.model) {
listView.model.destroy()
}
listView.model = barModelComponent.createObject(win)
break
}
return ret;
}
Component {
id: fooModelComponent
ListModel {
ListElement { textValue: "foo1" }
}
}
Component {
id: barModelComponent
ListModel {
ListElement { textValue: "bar1" }
}
}
ListView {
states: [
State {
when: win.currentModel === 'bar'
PropertyChanges {
listView.section.property: 'sectionProp'
}
}
]
id: listView
model: fooModelComponent.createObject(win)
anchors.fill: parent
section.delegate: Text {
required property string section
text: section
}
delegate: Text {
id: delg
text: delg.textValue
required property string textValue
}
}
}
|