-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdemo.qml
109 lines (94 loc) · 3.01 KB
/
demo.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
// TAKE CARE OF PATH IN qmldir FILE!
import Qt 4.7
import "QtMongo"
import "QtMongo/lib/json/json2.js" as Json
Row {
Column {
Text {
text: "<b>Object List:</b>"
}
ListView {
id: listview
focus: true
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
width: 250
height: 500
MongoDB {
id: db
name: "testdb"
host: "localhost"
collections: [
MongoCollection {
id: mythings
name: "things"
}
]
}
// this corresponds to
// model = mythings.find({x:4}):
model: MongoQuery {
collection: mythings
query: {}
// if you want to use objects here, you MUST use return stmts:
// sort: { return { j: -1 } }
}
delegate: mydelegate
Component {
id: mydelegate
Text {
text: "Object "+_id
}
}
onCurrentIndexChanged: jsonEdit.object = listview.model.get(listview.currentIndex)
}
}
Column {
width: 500
Row {
spacing: 2
Button {
text: "save this object"
onButtonClicked: { mythings.save(jsonEdit.object) }
}
Button {
text: "query this object"
onButtonClicked: {
listview.model = mythings.find(jsonEdit.object)
.toModel(listview.model) // we need a parent here!
}
}
}
JsonEdit {
id: jsonEdit
height: 300
width: parent.width
}
Rectangle {
id: hint
height: 100
width: parent.width
color: "red"
Text {
anchors.fill: parent
wrapMode: Text.WordWrap
text: "<b>Use up and down keys to navigate!</b><br/>"+
"You also might want to modify the <b>MongoDB.name property</b> to your database name "+
"and the <b>MongoCollection.name property</b> to your collection name to see any data"
}
}
Row {
spacing: 2
Button {
text: "Run MapReduce Demo"
onButtonClicked: {
var map = function() { emit(1,{}) }
var reduce = function( key , values ) { return 123; };
var result = mythings.mapReduce(map, reduce, "testname");
console.log( result.find({}).count() )
console.log( Json.JSON.stringify(result.find({}).toArray()) )
listview.model = result.find({}).toModel(listview)
}
}
}
}
}