-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.qml
182 lines (152 loc) · 5.4 KB
/
Main.qml
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import QtQuick 2.0
import Ubuntu.Components 1.1
/*!
\brief MainView with a Label and Button elements.
*/
MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "jsonlistmodeltest.liu-xiao-guo"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true
// Removes the old toolbar and enables new features of the new header.
useDeprecatedToolbar: false
width: units.gu(100)
height: units.gu(75)
Page {
title: i18n.tr("jsonlistmodeltest")
Column {
spacing: 5
anchors.fill: parent
anchors.margins: 5
anchors.bottomMargin: 0
Text {
text: "JSON file data with subtree extraction: all books by title"
}
ListView {
id: list1
width: parent.width
height: 200
JSONListModel {
id: jsonModel1
source: "jsonData.txt"
query: "$.store.book[*]"
}
model: jsonModel1.model
section.delegate: sectionDelegate
section.property: "title"
section.criteria: ViewSection.FirstCharacter
delegate: Component {
Text {
width: parent.width
horizontalAlignment: Text.AlignLeft
font.pixelSize: 14
color: "black"
text: model.title
Text {
anchors.fill: parent
anchors.rightMargin: 5
horizontalAlignment: Text.AlignRight
font.pixelSize: 12
color: "gray"
text: model.author
}
}
}
}
Text {
text: "JSON file data with expression filter: books less than $10 by genre"
}
ListView {
id: list2
width: parent.width
height: 200
clip: true
JSONListModel {
id: jsonModel2
source: "jsonData.txt"
query: "$..book[?(@.price<10)]"
}
model: jsonModel2.model
section.delegate: sectionDelegate
section.property: "category"
section.criteria: ViewSection.FullString
delegate: Component {
Text {
width: parent.width
horizontalAlignment: Text.AlignLeft
font.pixelSize: 14
color: "black"
text: model.title
Text {
anchors.fill: parent
anchors.rightMargin: 5
horizontalAlignment: Text.AlignRight
font.pixelSize: 12
color: "gray"
text: model.price
}
}
}
}
Text {
text: "JSON string data with substring filter: labels starting with 'A'"
}
ListView {
id: list3
width: parent.width
height: 100
clip: true
JSONListModel {
id: jsonModel3
json: '[ \
{"label": "Answer", "value": "42"}, \
{"label": "Pastis", "value": "51"}, \
{"label": "Alsace", "value": "67"}, \
{"label": "Alsace", "value": "68"} \
]'
query: "$[?(@.label.charAt(0)==='A')]"
}
model: jsonModel3.model
delegate: Component {
Text {
width: parent.width
horizontalAlignment: Text.AlignLeft
font.pixelSize: 20
color: "black"
text: model.label
Text {
anchors.fill: parent
anchors.rightMargin: 5
horizontalAlignment: Text.AlignRight
font.pixelSize: 18
color: "gray"
text: model.value
}
}
}
}
}
Component {
id: sectionDelegate
Rectangle {
color: "gray"
width: parent.width
height: sectionLabel.height
Text {
id: sectionLabel
anchors.horizontalCenter: parent.horizontalCenter
font.bold: true
font.pixelSize: 20
color: "white"
style: Text.Raised
text: section
}
}
}
}
}