Merge lp:~kevin-wright-1/u1db-qt/example-5-april-7-2013-i into lp:u1db-qt
- example-5-april-7-2013-i
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Cris Dywan |
Approved revision: | 68 |
Merged at revision: | 63 |
Proposed branch: | lp:~kevin-wright-1/u1db-qt/example-5-april-7-2013-i |
Merge into: | lp:u1db-qt |
Diff against target: |
345 lines (+233/-53) 1 file modified
examples/u1db-qt-example-5.qml (+233/-53) |
To merge this branch: | bzr merge lp:~kevin-wright-1/u1db-qt/example-5-april-7-2013-i |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Cris Dywan | Approve | ||
Review via email: mp+157841@code.launchpad.net |
This proposal supersedes a proposal from 2013-04-08.
Commit message
Modified examples/
Description of the change
Modified examples/
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:63
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:64
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:65
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:67
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:68
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:68
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Cris Dywan (kalikiana) : Posted in a previous version of this proposal | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:68
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Cris Dywan (kalikiana) : | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
Preview Diff
1 | === modified file 'examples/u1db-qt-example-5.qml' |
2 | --- examples/u1db-qt-example-5.qml 2013-04-06 00:25:13 +0000 |
3 | +++ examples/u1db-qt-example-5.qml 2013-04-09 10:45:28 +0000 |
4 | @@ -23,6 +23,14 @@ |
5 | |
6 | /*! |
7 | |
8 | +\page u1db-qt-index-tutorial.html |
9 | + |
10 | +\title U1Db-Qt Index Tutorial |
11 | + |
12 | +*/ |
13 | + |
14 | +/*! |
15 | + |
16 | This example and tutorial is designed to show a wide variety of U1Db-Qt functionality and usage. The example demonstrates: |
17 | |
18 | \list 1 |
19 | @@ -40,10 +48,12 @@ |
20 | |
21 | 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. |
22 | |
23 | + \code |
24 | U1db.Database { |
25 | id: aDatabase |
26 | path: "aDatabase4" |
27 | } |
28 | + \endcode |
29 | |
30 | */ |
31 | |
32 | @@ -54,43 +64,158 @@ |
33 | |
34 | /*! |
35 | |
36 | - A Document can be declared at runtime. It requires at the very least a unique 'docId', but that alone won't do anything special. The snipet below snippet demonstrates the basic requirements. |
37 | - |
38 | - In addition to this, this example displays text from the database for a specific docId and id key in a text area called 'documentContent. To update the text area at startup with either the default value or a value from the database the onCompleted function is utilized, which is also demonstrated below. |
39 | - |
40 | + A Document can be instantiated at runtime, or generated dynamically. The examples below demonstrate the former. |
41 | + |
42 | + A very basic Document could include its unique 'id' and 'docId' properties. While it is not mandatory to define these properties, in some cases they can be convenient references. More advanced applications would likely find these very useful, and in some cases may be an absolute necessity to achieve the objectives of the program. |
43 | + |
44 | + This example of a very simple Document will not initially do anything, until more properties are added and defined: |
45 | + |
46 | + \code |
47 | U1db.Document { |
48 | - id: aDocument |
49 | - database: aDatabase |
50 | - docId: 'helloworld' |
51 | - create: true |
52 | - defaults: { "helloworld":"Hello World" } |
53 | - |
54 | - Component.onCompleted: { |
55 | - documentContent.text = aDocument.contents.helloworld |
56 | - } |
57 | - |
58 | + id: aDocument1 |
59 | + docId: 'helloworld1' |
60 | } |
61 | + \endcode |
62 | |
63 | */ |
64 | |
65 | - |
66 | - U1db.Document { |
67 | - id: aDocument |
68 | - database: aDatabase |
69 | - docId: 'helloworld' |
70 | - create: true |
71 | - defaults:{"hello": { "world": [{ "message":"Hello World", "id": 1 }] } } |
72 | - |
73 | - } |
74 | - U1db.Document { |
75 | - id: aDocument2 |
76 | - database: aDatabase |
77 | - docId: 'helloworld2' |
78 | - create: true |
79 | - defaults:{"hello": { "world": [{ "message":"Hello World", "id": 2 }] } } |
80 | - |
81 | - } |
82 | - |
83 | + /*! |
84 | + |
85 | + A basic but still practical Document definition contains several essential properties. In addition to 'id' and 'docId' (discussed above), the 'database', 'create', and 'defaults' properties are also very important, and are introduced below. |
86 | + |
87 | + |
88 | + The 'database' property ensures that the Document is attached to am already defined (or possibly soon to be defined one) identified by its id (in this case 'aDatabase'). For example: |
89 | + |
90 | + \code |
91 | + U1db.Document { |
92 | + id: aDocument1 |
93 | + database: aDatabase |
94 | + docId: 'helloworld1' |
95 | + } |
96 | + \endcode |
97 | + |
98 | + Should the Database not already contain a Document with the same docId ('hellowworld1' in this example) when a 'create' property is present and set to true it will be generated. For example: |
99 | + |
100 | + \code |
101 | + U1db.Document { |
102 | + id: aDocument1 |
103 | + database: aDatabase |
104 | + docId: 'helloworld1' |
105 | + create: true |
106 | + } |
107 | + \endcode |
108 | + |
109 | + However, the Document still requires some data to be useful, which is what the 'defaults' property provides. The value of 'defaults' is a map of data that will be stored in the database (again when the create property is et to true). It contain key:value pairs, where the value can be a string, number, or nested object (e.g. additional fields, lists). For example: |
110 | + |
111 | + \code |
112 | + U1db.Document { |
113 | + id: aDocument1 |
114 | + database: aDatabase |
115 | + docId: 'helloworld1' |
116 | + create: true |
117 | + defaults:{"hello": { "world": { "message":"Hello World", "id": 1 } } } |
118 | + |
119 | + } |
120 | + \endcode |
121 | + |
122 | + */ |
123 | + |
124 | + U1db.Document { |
125 | + id: aDocument1 |
126 | + database: aDatabase |
127 | + docId: 'helloworld1' |
128 | + create: true |
129 | + defaults:{"hello": { "world": { "message":"Hello World", "id": 1 } } } |
130 | + |
131 | + } |
132 | + |
133 | + /*! |
134 | + |
135 | + As mentioned above, lists can also be nested in Document data. Lists provide a convenient method for producing multiple instances of the same key (AKA 'field' or 'sub-field'). The example code below shows valid use of the 'message' and 'id' sub-fields multiple times within the same object. |
136 | + |
137 | + \code |
138 | + U1db.Document { |
139 | + id: aDocument2 |
140 | + database: aDatabase |
141 | + docId: 'helloworld2' |
142 | + create: true |
143 | + defaults:{"hello": { "world": [{ "message":"Hello World", "id": 2 },{ "message":"Hello World", "id": 2.5 }] } } |
144 | + |
145 | + } |
146 | + \endcode |
147 | + |
148 | + When the default Javascript Object Notation itself is formatted with appropriate line breaks and indentation, it becomes easier to visualize an embedded list, containing sub-fields 'message' and 'id' (and their respective values): |
149 | + |
150 | + \code |
151 | + {"hello": |
152 | + { "world": |
153 | + [ |
154 | + { "message":"Hello World", "id": 2 }, |
155 | + { "message":"Hello World", "id": 2.5 } |
156 | + ] |
157 | + } |
158 | + } |
159 | + \endcode |
160 | + |
161 | + In dot notation these sub-fields are represented by 'hello.world.message' and 'hello.world.id' respectively. Later in this tutorial these will be utilized within the 'expression' property of U1Db-Qt's Index element, in close collaboration with a QML ListView's delegates. |
162 | + |
163 | + */ |
164 | + |
165 | + U1db.Document { |
166 | + id: aDocument2 |
167 | + database: aDatabase |
168 | + docId: 'helloworld2' |
169 | + create: true |
170 | + defaults:{"hello": { "world": [{ "message":"Hello World", "id": 2 },{ "message":"Hello World", "id": 2.5 }] } } |
171 | + } |
172 | + |
173 | + /*! |
174 | + |
175 | + Normally when a docId already exists in a database, and when the set flag is set to true, the value in 'defaults' will be ignored (and the existing data in the database will remain untouched). Sometimes a developer needs to easily overwrite the data in an existing document. The 'revise' property is a boolean for just that purpose. When 'revise' is set to true the value of 'defaults' will replace existing data for the document identified by the docId. |
176 | + |
177 | + Warning: This is an experimental property. It might not be supported in some installations of U1Db-Qt, and may be deprecated and/or the semantics changed. |
178 | + |
179 | + \code |
180 | + U1db.Document { |
181 | + id: aDocument3 |
182 | + database: aDatabase |
183 | + docId: 'helloworld3' |
184 | + create: true |
185 | + revise: true |
186 | + defaults:{"hello": { "world": [{ "message":"Hello World", "id": 3 },{ "message":"Hello World", "id": 3.33 },{ "message":"Hello World", "id": 3.66 }] } } |
187 | + } |
188 | + \endcode |
189 | + |
190 | + */ |
191 | + |
192 | + U1db.Document { |
193 | + id: aDocument3 |
194 | + database: aDatabase |
195 | + docId: 'helloworld3' |
196 | + create: true |
197 | + revise: true |
198 | + defaults:{"hello": { "world": [{ "message":"Hello World", "id": 3 },{ "message":"Hello World", "id": 3.33 },{ "message":"Hello World", "id": 3.66 }] } } |
199 | + } |
200 | + |
201 | + /*! |
202 | + |
203 | + This snippet simply represents the absence of the 'create' property, which is synonymous with 'create: false'. The Document can still be recognized within the application, but until applicable properties (such as those outlined above) are added and/or modified then nothing will be added or modified in the database, and this instance may have very little practical value. |
204 | + |
205 | + U1db.Document { |
206 | + id: aDocument4 |
207 | + database: aDatabase |
208 | + docId: 'helloworld4' |
209 | + defaults:{"hello": { "world": { "message":"Hello World", "id": 4 } } } |
210 | + } |
211 | + |
212 | + */ |
213 | + |
214 | + U1db.Document { |
215 | + id: aDocument4 |
216 | + database: aDatabase |
217 | + docId: 'helloworld4' |
218 | + defaults:{"hello": { "world": { "message":"Hello World", "id": 4 } } } |
219 | + } |
220 | U1db.Index{ |
221 | database: aDatabase |
222 | id: by_helloworld |
223 | @@ -121,47 +246,102 @@ |
224 | |
225 | page: Page { |
226 | id: helloPage |
227 | + |
228 | + /* |
229 | + |
230 | + This simple snippet represents how to attach a ListModel to a ListView. In this instance the model 'helloListModel' is representative of the Index defined earlier. It is a common QML concept, and not specific to U1Db-Qt. |
231 | + |
232 | + ListView { |
233 | + |
234 | + width: units.gu(45) |
235 | + height: units.gu(80) |
236 | + |
237 | + model: helloListModel |
238 | + |
239 | + } |
240 | + |
241 | + */ |
242 | + |
243 | ListView { |
244 | width: units.gu(45) |
245 | height: units.gu(80) |
246 | |
247 | + |
248 | + model: helloListModel |
249 | + |
250 | /* |
251 | - Here is the reference to the Database model mentioned earlier. |
252 | - */ |
253 | - model: helloListModel |
254 | - |
255 | - /* A delegate will be created for each Document retrieved from the Database */ |
256 | + When using QML ListView, delegates will be created based on particular properties such as the size of the application window, ListView, and delegate itself (amongst other factors). Each delegate can then represent a Document retrieved from the Database based on the record's index. This example demonstrates some of the property definitions that contribute to determining the number of delegates a ListView will contain: |
257 | + |
258 | + |
259 | + /code |
260 | + ListView { |
261 | + |
262 | + width: units.gu(45) |
263 | + height: units.gu(80) |
264 | + |
265 | + model: helloListModel |
266 | + |
267 | + delegate: Text { |
268 | + x: 66; y: 77 |
269 | + } |
270 | + |
271 | + } |
272 | + /endcode |
273 | + |
274 | + When the number of Documents is less than or equal to the number of delegates then there is a one to one mapping of index to delegate (e.g. the first delegate will represent the Document with an index = 0; the second, index = 1; and so on). |
275 | + |
276 | + When there are more Documents than delegates the ListView will request a new index depending on the situation (e.g. a user scrolls up or down). For example, if a ListView has 10 delegates, but 32 Documents to handle, when a user initially scrolls the first delegate will change from representing the Document with index = 0 to the Document that might have index = 8; the second, from index = 1 to index = 9; ...; the 10th delegate from index = 9 to index = 17. A second scrolling gesture the first index may change to 15, and the final index 24. And so on. Scrolling in the opposite direction will have a similar effect, but the Document index numbers for each delegate will obviously start to decline (towards their original values). |
277 | + |
278 | + The following snippet, which modifies the above delegate definition, could demonstrate this effect if there were enough Documents to do so (i.e. some number greater than the number of delegates): |
279 | + |
280 | + \code |
281 | + ListView { |
282 | + width: units.gu(45) |
283 | + height: units.gu(80) |
284 | + |
285 | + model: helloListModel |
286 | + |
287 | + delegate: Text { |
288 | + x: 66; y: 77 |
289 | + text: index |
290 | + } |
291 | + |
292 | + } |
293 | + \endcode |
294 | + |
295 | + */ |
296 | + |
297 | delegate: Text { |
298 | x: 66; y: 77 |
299 | text: { |
300 | + |
301 | /*! |
302 | - The object called 'contents' contains a string as demonstrated here. In this example 'hello' is our search string. |
303 | - |
304 | - text: contents.hello |
305 | + |
306 | + The object called 'contents' contains one or more properties. This example demonstrates the retrieval of data based on the U1db.Index defined earlier (id: by-helloworld). In this instance the Index contained two expressions simultaniously, "hello.world.id" and "hello.world.message" |
307 | + |
308 | + \code |
309 | + delegate: Text { |
310 | + x: 66; y: 77 |
311 | + text: { |
312 | + text: "(" + index + ") '" + contents.message + " " + contents.id + "'" |
313 | + } |
314 | + } |
315 | + \endcode |
316 | + |
317 | */ |
318 | |
319 | - text: contents.id + " " + contents.message |
320 | + text: "(" + index + ") '" + contents.message + " " + contents.id + "'" |
321 | } |
322 | } |
323 | } |
324 | } |
325 | |
326 | - |
327 | - } |
328 | - |
329 | } |
330 | |
331 | - |
332 | - |
333 | - |
334 | } |
335 | |
336 | - |
337 | - |
338 | - |
339 | - |
340 | - |
341 | - |
342 | } |
343 | |
344 | +} |
345 | + |
346 |
PASSED: Continuous integration, rev:62 91.189. 93.125: 8080/job/ u1db-qt- ci/22/ 91.189. 93.125: 8080/job/ u1db-qt- quantal- amd64-ci/ 22 91.189. 93.125: 8080/job/ u1db-qt- raring- amd64-ci/ 22
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.125: 8080/job/ u1db-qt- ci/22/rebuild
http://