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