Merge lp:~kevin-wright-1/u1db-qt/example-5-april-7-2013-i into lp:u1db-qt

Proposed by Kevin Wright
Status: Superseded
Proposed branch: lp:~kevin-wright-1/u1db-qt/example-5-april-7-2013-i
Merge into: lp:u1db-qt
Diff against target: 351 lines (+347/-0)
1 file modified
examples/u1db-qt-example-5.qml (+347/-0)
To merge this branch: bzr merge lp:~kevin-wright-1/u1db-qt/example-5-april-7-2013-i
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Cris Dywan Pending
Review via email: mp+157531@code.launchpad.net

This proposal has been superseded by a proposal from 2013-04-08.

Commit message

Modified examples/u1db-qt-example-5.qml so that it is representative of a tutorial demonstrating Index and other U1Db-Qt functionality. Additionally added appropriate qdoc markup for the tutorial to the file.

Description of the change

Modified examples/u1db-qt-example-5.qml so that it is representative of a tutorial demonstrating Index and other U1Db-Qt functionality. Additionally added appropriate qdoc markup for the tutorial to the file.

To post a comment you must log in.
63. By Kevin Wright

Modified examples/u1db-qt-example-5.qml to include code markup in the qdoc sections, surrounding appropriate example snippets.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
64. By Kevin Wright

Modified examples/u1db-qt-example-5.qml to include additional tutorial qdoc markup, focussed on describing support for embedded lists within the Document element's 'default' property definition.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
65. By Kevin Wright

Modified examples/u1db-qt-example-5.qml. Made mostly minor modifications to the tutorial qdoc markup.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
66. By Kevin Wright

Modified examples/u1db-qt-example-5.qml to add more tutorial qdoc markup, up to the end of describing the variations of the Document instances used in the example.

67. By Kevin Wright

Modified examples/u1db-qt-example-5.qml to edit a small portion of the tutorial qdoc markup (regarding ListView and delegates).

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
68. By Kevin Wright

Modified examples/u1db-qt-example-5.qml, with additional edits to the section of the tutorial qdoc markup regarding ListView and delegates.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'examples/u1db-qt-example-5.qml'
2--- examples/u1db-qt-example-5.qml 1970-01-01 00:00:00 +0000
3+++ examples/u1db-qt-example-5.qml 2013-04-07 14:07:21 +0000
4@@ -0,0 +1,347 @@
5+/*
6+ * Copyright (C) 2013 Canonical, Ltd.
7+ *
8+ * Authors:
9+ * Kevin Wright <kevin.wright@canonical.com>
10+ *
11+ * This program is free software; you can redistribute it and/or modify
12+ * it under the terms of the GNU Lesser General Public License as published by
13+ * the Free Software Foundation; version 3.
14+ *
15+ * This program is distributed in the hope that it will be useful,
16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+ * GNU Lesser General Public License for more details.
19+ *
20+ * You should have received a copy of the GNU Lesser General Public License
21+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
22+ */
23+
24+import QtQuick 2.0
25+import U1db 1.0 as U1db
26+import Ubuntu.Components 0.1
27+
28+/*!
29+
30+\page u1db-qt-index-tutorial.html
31+
32+\title U1Db-Qt Index Tutorial
33+
34+*/
35+
36+/*!
37+
38+This example and tutorial is designed to show a wide variety of U1Db-Qt functionality and usage. The example demonstrates:
39+
40+\list 1
41+ \li Using Index and Query elements
42+\endlist
43+
44+ */
45+
46+Item {
47+
48+ width: units.gu(45)
49+ height: units.gu(80)
50+
51+ /*!
52+
53+ 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.
54+
55+ \code
56+ U1db.Database {
57+ id: aDatabase
58+ path: "aDatabase4"
59+ }
60+ \endcode
61+
62+ */
63+
64+ U1db.Database {
65+ id: aDatabase
66+ path: "aDatabase5"
67+ }
68+
69+ /*!
70+
71+ A Document can be instantiated at runtime, or generated dynamically. The examples below demonstrate the former.
72+
73+ 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.
74+
75+ This example of a very simple Document will not initially do anything, until more properties are added and defined:
76+
77+ \code
78+ U1db.Document {
79+ id: aDocument1
80+ docId: 'helloworld1'
81+ }
82+ \endcode
83+
84+ */
85+
86+ /*!
87+
88+ 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.
89+
90+
91+ 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:
92+
93+ \code
94+ U1db.Document {
95+ id: aDocument1
96+ database: aDatabase
97+ docId: 'helloworld1'
98+ }
99+ \endcode
100+
101+ 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:
102+
103+ \code
104+ U1db.Document {
105+ id: aDocument1
106+ database: aDatabase
107+ docId: 'helloworld1'
108+ create: true
109+ }
110+ \endcode
111+
112+ 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:
113+
114+ \code
115+ U1db.Document {
116+ id: aDocument1
117+ database: aDatabase
118+ docId: 'helloworld1'
119+ create: true
120+ defaults:{"hello": { "world": { "message":"Hello World", "id": 1 } } }
121+
122+ }
123+ \endcode
124+
125+ */
126+
127+ U1db.Document {
128+ id: aDocument1
129+ database: aDatabase
130+ docId: 'helloworld1'
131+ create: true
132+ defaults:{"hello": { "world": { "message":"Hello World", "id": 1 } } }
133+
134+ }
135+
136+ /*!
137+
138+ 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.
139+
140+ \code
141+ U1db.Document {
142+ id: aDocument2
143+ database: aDatabase
144+ docId: 'helloworld2'
145+ create: true
146+ defaults:{"hello": { "world": [{ "message":"Hello World", "id": 2 },{ "message":"Hello World", "id": 2.5 }] } }
147+
148+ }
149+ \endcode
150+
151+ 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):
152+
153+ \code
154+ {"hello":
155+ { "world":
156+ [
157+ { "message":"Hello World", "id": 2 },
158+ { "message":"Hello World", "id": 2.5 }
159+ ]
160+ }
161+ }
162+ \endcode
163+
164+ 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.
165+
166+ */
167+
168+ U1db.Document {
169+ id: aDocument2
170+ database: aDatabase
171+ docId: 'helloworld2'
172+ create: true
173+ defaults:{"hello": { "world": [{ "message":"Hello World", "id": 2 },{ "message":"Hello World", "id": 2.5 }] } }
174+ }
175+
176+ /*!
177+
178+ 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.
179+
180+ 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.
181+
182+ \code
183+ U1db.Document {
184+ id: aDocument3
185+ database: aDatabase
186+ docId: 'helloworld3'
187+ create: true
188+ revise: true
189+ defaults:{"hello": { "world": [{ "message":"Hello World", "id": 3 },{ "message":"Hello World", "id": 3.33 },{ "message":"Hello World", "id": 3.66 }] } }
190+ }
191+ \endcode
192+
193+ */
194+
195+ U1db.Document {
196+ id: aDocument3
197+ database: aDatabase
198+ docId: 'helloworld3'
199+ create: true
200+ revise: true
201+ defaults:{"hello": { "world": [{ "message":"Hello World", "id": 3 },{ "message":"Hello World", "id": 3.33 },{ "message":"Hello World", "id": 3.66 }] } }
202+ }
203+
204+ /*!
205+
206+ 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.
207+
208+ U1db.Document {
209+ id: aDocument4
210+ database: aDatabase
211+ docId: 'helloworld4'
212+ defaults:{"hello": { "world": { "message":"Hello World", "id": 4 } } }
213+ }
214+
215+ */
216+
217+ U1db.Document {
218+ id: aDocument4
219+ database: aDatabase
220+ docId: 'helloworld4'
221+ defaults:{"hello": { "world": { "message":"Hello World", "id": 4 } } }
222+ }
223+ U1db.Index{
224+ database: aDatabase
225+ id: by_helloworld
226+ name: "by-helloworld"
227+ expression: ["hello.world.id","hello.world.message"]
228+ }
229+ U1db.Query{
230+ id: helloListModel
231+ index: by_helloworld
232+ //query: "*"
233+ }
234+
235+ MainView {
236+
237+ id: u1dbView
238+ width: units.gu(45)
239+ height: units.gu(80)
240+ anchors.top: parent.top;
241+
242+ Tabs {
243+ id: tabs
244+ anchors.fill: parent
245+
246+ Tab {
247+ objectName: "Tab1"
248+
249+ title: i18n.tr("Hello U1Db!")
250+
251+ page: Page {
252+ id: helloPage
253+
254+ /*
255+
256+ 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.
257+
258+ ListView {
259+
260+ width: units.gu(45)
261+ height: units.gu(80)
262+
263+ model: helloListModel
264+
265+ }
266+
267+ */
268+
269+ ListView {
270+ width: units.gu(45)
271+ height: units.gu(80)
272+
273+
274+ model: helloListModel
275+
276+ /*
277+ 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:
278+
279+
280+ /code
281+ ListView {
282+
283+ width: units.gu(45)
284+ height: units.gu(80)
285+
286+ model: helloListModel
287+
288+ delegate: Text {
289+ x: 66; y: 77
290+ }
291+
292+ }
293+ /endcode
294+
295+ 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).
296+
297+ 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).
298+
299+ 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):
300+
301+ \code
302+ ListView {
303+ width: units.gu(45)
304+ height: units.gu(80)
305+
306+ model: helloListModel
307+
308+ delegate: Text {
309+ x: 66; y: 77
310+ text: index
311+ }
312+
313+ }
314+ \endcode
315+
316+ */
317+
318+ delegate: Text {
319+ x: 66; y: 77
320+ text: {
321+
322+ /*!
323+
324+ 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"
325+
326+ \code
327+ delegate: Text {
328+ x: 66; y: 77
329+ text: {
330+ text: "(" + index + ") '" + contents.message + " " + contents.id + "'"
331+ }
332+ }
333+ \endcode
334+
335+ */
336+
337+ text: "(" + index + ") '" + contents.message + " " + contents.id + "'"
338+ }
339+ }
340+ }
341+ }
342+
343+ }
344+
345+ }
346+
347+ }
348+
349+}
350+
351+

Subscribers

People subscribed via source and target branches

to all changes: