Merge lp:~kevin-wright-1/u1db-qt/example-development-05-march-2013-ii into lp:u1db-qt
- example-development-05-march-2013-ii
- Merge into trunk
Proposed by
Kevin Wright
Status: | Merged |
---|---|
Merged at revision: | 34 |
Proposed branch: | lp:~kevin-wright-1/u1db-qt/example-development-05-march-2013-ii |
Merge into: | lp:u1db-qt |
Diff against target: |
404 lines (+350/-8) 3 files modified
examples/u1db-qt-example-1.qml (+15/-8) examples/u1db-qt-example-2.qml (+108/-0) examples/u1db-qt-example-3.qml (+227/-0) |
To merge this branch: | bzr merge lp:~kevin-wright-1/u1db-qt/example-development-05-march-2013-ii |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cris Dywan | Approve | ||
Review via email:
|
Commit message
Description of the change
Fixed some more formatting issues in example code, changed some code comments in the example code, reduced the interval value in example 2 to 5 from 500, and ensured every delegate in each example is using 'text: contents.hello'
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'examples/u1db-qt-example-1.qml' | |||
2 | --- examples/u1db-qt-example-1.qml 2013-03-04 13:58:58 +0000 | |||
3 | +++ examples/u1db-qt-example-1.qml 2013-03-06 10:48:20 +0000 | |||
4 | @@ -51,7 +51,7 @@ | |||
5 | 51 | database: aDatabase | 51 | database: aDatabase |
6 | 52 | docId: 'helloworld' | 52 | docId: 'helloworld' |
7 | 53 | create: true | 53 | create: true |
9 | 54 | defaults: { "hello": "world" } | 54 | defaults: { "hello": "Hello World!" } |
10 | 55 | } | 55 | } |
11 | 56 | 56 | ||
12 | 57 | Tabs { | 57 | Tabs { |
13 | @@ -60,12 +60,12 @@ | |||
14 | 60 | 60 | ||
15 | 61 | Tab { | 61 | Tab { |
16 | 62 | objectName: "Tab1" | 62 | objectName: "Tab1" |
18 | 63 | 63 | ||
19 | 64 | title: i18n.tr("Hello U1Db!") | 64 | title: i18n.tr("Hello U1Db!") |
20 | 65 | 65 | ||
21 | 66 | page: Page { | 66 | page: Page { |
22 | 67 | id: helloPage | 67 | id: helloPage |
24 | 68 | ListView { | 68 | ListView { |
25 | 69 | width: units.gu(45) | 69 | width: units.gu(45) |
26 | 70 | height: units.gu(80) | 70 | height: units.gu(80) |
27 | 71 | 71 | ||
28 | @@ -74,13 +74,20 @@ | |||
29 | 74 | */ | 74 | */ |
30 | 75 | model: aDatabase | 75 | model: aDatabase |
31 | 76 | 76 | ||
33 | 77 | /* A delegate will be created for each Document retrieved from the Database */ | 77 | /* A delegate will be created for each Document retrieved from the Database */ |
34 | 78 | delegate: Text { | 78 | delegate: Text { |
35 | 79 | x: 66; y: 77 | 79 | x: 66; y: 77 |
36 | 80 | text: { | 80 | text: { |
40 | 81 | /* | 81 | /*! |
41 | 82 | The contents of each Document are represented by a string that can be used in on the console or text as demonstrated here. | 82 | The object called 'contents' contains a string as demonstrated here. In this example 'hello' is our search string. |
42 | 83 | */ | 83 | |
43 | 84 | if(contents !== undefined){ | ||
44 | 85 | text: contents.hello | ||
45 | 86 | } | ||
46 | 87 | else { "" } | ||
47 | 88 | |||
48 | 89 | |||
49 | 90 | */ | ||
50 | 84 | text: contents.hello | 91 | text: contents.hello |
51 | 85 | } | 92 | } |
52 | 86 | } | 93 | } |
53 | @@ -93,4 +100,4 @@ | |||
54 | 93 | 100 | ||
55 | 94 | } | 101 | } |
56 | 95 | 102 | ||
57 | 96 | } | ||
58 | 97 | \ No newline at end of file | 103 | \ No newline at end of file |
59 | 104 | } | ||
60 | 98 | 105 | ||
61 | === added file 'examples/u1db-qt-example-2.qml' | |||
62 | --- examples/u1db-qt-example-2.qml 1970-01-01 00:00:00 +0000 | |||
63 | +++ examples/u1db-qt-example-2.qml 2013-03-06 10:48:20 +0000 | |||
64 | @@ -0,0 +1,108 @@ | |||
65 | 1 | /* | ||
66 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
67 | 3 | * | ||
68 | 4 | * Authors: | ||
69 | 5 | * Kevin Wright <kevin.wright@canonical.com> | ||
70 | 6 | * | ||
71 | 7 | * This program is free software; you can redistribute it and/or modify | ||
72 | 8 | * it under the terms of the GNU Lesser General Public License as published by | ||
73 | 9 | * the Free Software Foundation; version 3. | ||
74 | 10 | * | ||
75 | 11 | * This program is distributed in the hope that it will be useful, | ||
76 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
77 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
78 | 14 | * GNU Lesser General Public License for more details. | ||
79 | 15 | * | ||
80 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
81 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
82 | 18 | */ | ||
83 | 19 | |||
84 | 20 | import QtQuick 2.0 | ||
85 | 21 | import U1db 1.0 as U1db | ||
86 | 22 | import Ubuntu.Components 0.1 | ||
87 | 23 | |||
88 | 24 | |||
89 | 25 | MainView { | ||
90 | 26 | |||
91 | 27 | id: u1dbView | ||
92 | 28 | width: units.gu(45) | ||
93 | 29 | height: units.gu(80) | ||
94 | 30 | |||
95 | 31 | /*! | ||
96 | 32 | |||
97 | 33 | A Database is very simple to create. It only needs an id and a path where the file will be created. A Database is a model, which can be used by elements, such as the ListView further in this example. | ||
98 | 34 | |||
99 | 35 | */ | ||
100 | 36 | |||
101 | 37 | U1db.Database { | ||
102 | 38 | id: aDatabase | ||
103 | 39 | path: "aU1DbDSatabase2" | ||
104 | 40 | } | ||
105 | 41 | |||
106 | 42 | Timer { | ||
107 | 43 | |||
108 | 44 | property int i: 0; interval: 5; running: true; repeat: true | ||
109 | 45 | onTriggered: newDocumentObject() | ||
110 | 46 | |||
111 | 47 | function newDocumentObject() { | ||
112 | 48 | |||
113 | 49 | var qmlString = "import QtQuick 2.0; import U1db 1.0 as U1db; U1db.Document {id: aDcoument"+i+";database: aDatabase;docId: 'helloworld"+i+"';create: true; defaults: { 'hello': 'Hello New Document "+i+"!' }}" | ||
114 | 50 | |||
115 | 51 | Qt.createQmlObject(qmlString, u1dbView, "dynamicNewDocument"+i); | ||
116 | 52 | |||
117 | 53 | i = i+1 | ||
118 | 54 | } | ||
119 | 55 | |||
120 | 56 | } | ||
121 | 57 | |||
122 | 58 | Tabs { | ||
123 | 59 | id: tabs | ||
124 | 60 | anchors.fill: parent | ||
125 | 61 | |||
126 | 62 | Tab { | ||
127 | 63 | objectName: "Tab1" | ||
128 | 64 | |||
129 | 65 | title: i18n.tr("Hello U1Db!") | ||
130 | 66 | |||
131 | 67 | page: Page { | ||
132 | 68 | id: helloPage | ||
133 | 69 | ListView { | ||
134 | 70 | width: units.gu(45) | ||
135 | 71 | height: units.gu(80) | ||
136 | 72 | |||
137 | 73 | /* | ||
138 | 74 | Here is the reference to the Database model mentioned earlier. | ||
139 | 75 | */ | ||
140 | 76 | model: aDatabase | ||
141 | 77 | |||
142 | 78 | /* A delegate will be created for each Document retrieved from the Database */ | ||
143 | 79 | delegate: Text { | ||
144 | 80 | x: 66; y: 77 | ||
145 | 81 | text: { | ||
146 | 82 | /*! | ||
147 | 83 | The object called 'contents' contains a string as demonstrated here. In this example 'hello' is our search string. | ||
148 | 84 | |||
149 | 85 | if(contents !== undefined){ | ||
150 | 86 | text: contents.hello | ||
151 | 87 | } | ||
152 | 88 | else { "" } | ||
153 | 89 | |||
154 | 90 | |||
155 | 91 | */ | ||
156 | 92 | |||
157 | 93 | if(contents !== undefined){ | ||
158 | 94 | text: contents.hello | ||
159 | 95 | } | ||
160 | 96 | else { "" } | ||
161 | 97 | } | ||
162 | 98 | } | ||
163 | 99 | } | ||
164 | 100 | } | ||
165 | 101 | |||
166 | 102 | |||
167 | 103 | } | ||
168 | 104 | |||
169 | 105 | |||
170 | 106 | } | ||
171 | 107 | |||
172 | 108 | } | ||
173 | 0 | 109 | ||
174 | === added file 'examples/u1db-qt-example-3.qml' | |||
175 | --- examples/u1db-qt-example-3.qml 1970-01-01 00:00:00 +0000 | |||
176 | +++ examples/u1db-qt-example-3.qml 2013-03-06 10:48:20 +0000 | |||
177 | @@ -0,0 +1,227 @@ | |||
178 | 1 | /* | ||
179 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
180 | 3 | * | ||
181 | 4 | * Authors: | ||
182 | 5 | * Kevin Wright <kevin.wright@canonical.com> | ||
183 | 6 | * | ||
184 | 7 | * This program is free software; you can redistribute it and/or modify | ||
185 | 8 | * it under the terms of the GNU Lesser General Public License as published by | ||
186 | 9 | * the Free Software Foundation; version 3. | ||
187 | 10 | * | ||
188 | 11 | * This program is distributed in the hope that it will be useful, | ||
189 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
190 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
191 | 14 | * GNU Lesser General Public License for more details. | ||
192 | 15 | * | ||
193 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
194 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
195 | 18 | */ | ||
196 | 19 | |||
197 | 20 | import QtQuick 2.0 | ||
198 | 21 | import U1db 1.0 as U1db | ||
199 | 22 | import Ubuntu.Components 0.1 | ||
200 | 23 | |||
201 | 24 | Item { | ||
202 | 25 | |||
203 | 26 | width: units.gu(45) | ||
204 | 27 | height: units.gu(80) | ||
205 | 28 | |||
206 | 29 | MainView { | ||
207 | 30 | |||
208 | 31 | id: u1dbView | ||
209 | 32 | width: units.gu(45) | ||
210 | 33 | height: units.gu(80) | ||
211 | 34 | anchors.top: parent.top; | ||
212 | 35 | |||
213 | 36 | /*! | ||
214 | 37 | |||
215 | 38 | A Database is very simple to create. It only needs an id and a path where the file will be created. A Database is a model, which can be used by elements, such as the ListView further in this example. | ||
216 | 39 | |||
217 | 40 | U1db.Database { | ||
218 | 41 | id: aDatabase | ||
219 | 42 | path: "aU1DbDSatabase2" | ||
220 | 43 | } | ||
221 | 44 | |||
222 | 45 | */ | ||
223 | 46 | |||
224 | 47 | U1db.Database { | ||
225 | 48 | id: aDatabase | ||
226 | 49 | path: "aU1DbDSatabase2" | ||
227 | 50 | } | ||
228 | 51 | |||
229 | 52 | /*! | ||
230 | 53 | |||
231 | 54 | A Document can be declared at runtime. It requires at the very least a unique 'docId', but that alone won't do anything special. In order for a document to be entered into the database the below snippet demonstrates the basic requirements. The id might be optional. | ||
232 | 55 | |||
233 | 56 | U1db.Document { | ||
234 | 57 | id: aDocument | ||
235 | 58 | database: aDatabase | ||
236 | 59 | docId: 'helloworld' | ||
237 | 60 | create: true | ||
238 | 61 | defaults: { "hello":"Hello World" } | ||
239 | 62 | } | ||
240 | 63 | |||
241 | 64 | */ | ||
242 | 65 | |||
243 | 66 | U1db.Document { | ||
244 | 67 | id: aDocument | ||
245 | 68 | database: aDatabase | ||
246 | 69 | docId: 'helloworld' | ||
247 | 70 | create: true | ||
248 | 71 | defaults: { "hello":"Hello World" } | ||
249 | 72 | } | ||
250 | 73 | |||
251 | 74 | Tabs { | ||
252 | 75 | id: tabs | ||
253 | 76 | anchors.fill: parent | ||
254 | 77 | |||
255 | 78 | Tab { | ||
256 | 79 | objectName: "Tab1" | ||
257 | 80 | |||
258 | 81 | title: i18n.tr("Hello U1Db!") | ||
259 | 82 | |||
260 | 83 | page: Page { | ||
261 | 84 | |||
262 | 85 | id: helloPage | ||
263 | 86 | |||
264 | 87 | Rectangle { | ||
265 | 88 | |||
266 | 89 | width: units.gu(45) | ||
267 | 90 | height: units.gu(70) | ||
268 | 91 | anchors.bottom: parent.bottom | ||
269 | 92 | |||
270 | 93 | color: "#00FFFFFF" | ||
271 | 94 | |||
272 | 95 | ListView { | ||
273 | 96 | |||
274 | 97 | width: units.gu(45) | ||
275 | 98 | height: units.gu(60) | ||
276 | 99 | anchors.bottom: parent.bottom | ||
277 | 100 | |||
278 | 101 | TextArea{ | ||
279 | 102 | |||
280 | 103 | x: units.gu(1) | ||
281 | 104 | y: units.gu(1) | ||
282 | 105 | width: units.gu(43) | ||
283 | 106 | height: units.gu(58) | ||
284 | 107 | |||
285 | 108 | color: "#FFFFFF" | ||
286 | 109 | |||
287 | 110 | } | ||
288 | 111 | |||
289 | 112 | } | ||
290 | 113 | |||
291 | 114 | Rectangle { | ||
292 | 115 | |||
293 | 116 | width: units.gu(43) | ||
294 | 117 | height: units.gu(5) | ||
295 | 118 | anchors.top: addressBar.bottom | ||
296 | 119 | x: units.gu(1.5) | ||
297 | 120 | |||
298 | 121 | color: "#00FFFFFF" | ||
299 | 122 | |||
300 | 123 | Row{ | ||
301 | 124 | |||
302 | 125 | width: units.gu(43) | ||
303 | 126 | height: units.gu(5) | ||
304 | 127 | anchors.verticalCenter: parent.verticalCenter | ||
305 | 128 | spacing: units.gu(2) | ||
306 | 129 | |||
307 | 130 | |||
308 | 131 | Button { | ||
309 | 132 | text: "<" | ||
310 | 133 | onClicked: print("clicked Back Button") | ||
311 | 134 | } | ||
312 | 135 | Button { | ||
313 | 136 | text: "Home" | ||
314 | 137 | onClicked: print("clicked Home Button") | ||
315 | 138 | } | ||
316 | 139 | Button { | ||
317 | 140 | text: "+" | ||
318 | 141 | onClicked: print("clicked Save Button") | ||
319 | 142 | } | ||
320 | 143 | Button { | ||
321 | 144 | text: ">" | ||
322 | 145 | onClicked: print("clicked Forward Button") | ||
323 | 146 | } | ||
324 | 147 | } | ||
325 | 148 | |||
326 | 149 | } | ||
327 | 150 | |||
328 | 151 | ListView { | ||
329 | 152 | |||
330 | 153 | width: units.gu(45) | ||
331 | 154 | height: units.gu(5) | ||
332 | 155 | anchors.top: parent.top | ||
333 | 156 | |||
334 | 157 | id: addressBar | ||
335 | 158 | |||
336 | 159 | /*! Inside this example ListView is a reference to the Database model mentioned earlier: | ||
337 | 160 | |||
338 | 161 | ListView { | ||
339 | 162 | |||
340 | 163 | model: aDatabase | ||
341 | 164 | |||
342 | 165 | } | ||
343 | 166 | |||
344 | 167 | */ | ||
345 | 168 | |||
346 | 169 | model: aDatabase | ||
347 | 170 | |||
348 | 171 | /*! | ||
349 | 172 | |||
350 | 173 | Once a model is assigned to a ListView a delegate can represent each Document retrieved from the Database. | ||
351 | 174 | |||
352 | 175 | ListView { | ||
353 | 176 | |||
354 | 177 | model: aDatabase | ||
355 | 178 | |||
356 | 179 | delegate: Rectangle{ | ||
357 | 180 | anchors.right: parent.right | ||
358 | 181 | } | ||
359 | 182 | |||
360 | 183 | } | ||
361 | 184 | |||
362 | 185 | |||
363 | 186 | */ | ||
364 | 187 | |||
365 | 188 | delegate: TextField { | ||
366 | 189 | width: units.gu(43) | ||
367 | 190 | anchors.verticalCenter: parent.verticalCenter | ||
368 | 191 | x: units.gu(1) | ||
369 | 192 | |||
370 | 193 | text: { | ||
371 | 194 | /*! | ||
372 | 195 | The object called 'contents' contains a string as demonstrated here. In this example 'hello' is our search string. | ||
373 | 196 | |||
374 | 197 | if(contents !== undefined){ | ||
375 | 198 | text: contents.hello | ||
376 | 199 | } | ||
377 | 200 | else { "" } | ||
378 | 201 | |||
379 | 202 | |||
380 | 203 | */ | ||
381 | 204 | |||
382 | 205 | if(contents !== undefined){ | ||
383 | 206 | text: contents.hello | ||
384 | 207 | } | ||
385 | 208 | else { "" } | ||
386 | 209 | } | ||
387 | 210 | |||
388 | 211 | } | ||
389 | 212 | |||
390 | 213 | |||
391 | 214 | } | ||
392 | 215 | |||
393 | 216 | } | ||
394 | 217 | |||
395 | 218 | |||
396 | 219 | } | ||
397 | 220 | |||
398 | 221 | } | ||
399 | 222 | |||
400 | 223 | } | ||
401 | 224 | |||
402 | 225 | } | ||
403 | 226 | |||
404 | 227 | } |
As discussed, I simplified the delegates. Looking brilliant!