Merge lp:~kevin-wright-1/u1db-qt/examples-19-march-2013-i into lp:u1db-qt

Proposed by Kevin Wright
Status: Merged
Merged at revision: 55
Proposed branch: lp:~kevin-wright-1/u1db-qt/examples-19-march-2013-i
Merge into: lp:u1db-qt
Diff against target: 114 lines (+110/-0)
1 file modified
examples/u1db-qt-example-2b.qml (+110/-0)
To merge this branch: bzr merge lp:~kevin-wright-1/u1db-qt/examples-19-march-2013-i
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Review via email: mp+153994@code.launchpad.net

Description of the change

Added examples/u1db-qt-example-2b.qml to demonstrate the creation and querying of sub-fields in a Document. Discovered a bug where the database, document contents do not appear to update properly if a change has been made and the contents contain sub-fields.

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote :

As discussed, I'm wary if this is "best practise" but let's keep it on the radar while missing features are being implemented.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'examples/u1db-qt-example-2b.qml'
--- examples/u1db-qt-example-2b.qml 1970-01-01 00:00:00 +0000
+++ examples/u1db-qt-example-2b.qml 2013-03-19 05:44:21 +0000
@@ -0,0 +1,110 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Kevin Wright <kevin.wright@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20import QtQuick 2.0
21import U1db 1.0 as U1db
22import Ubuntu.Components 0.1
23
24/*!
25
26This example demonstrates how to create and query one level of sub-fields in a document.
27
28*/
29
30MainView {
31
32 id: u1dbView
33 width: units.gu(45)
34 height: units.gu(80)
35
36 U1db.Database {
37 id: aDatabase
38 path: "aU1DbDSatabase2b"
39 }
40
41 /*!
42
43 This snippet demonstrates how to create content that includes nested fields. The main field is 'hello', while the sub-field for each entry is 'value'. Later in the example it will be shown how to access each of these in the delegate of a ListView.
44
45 U1db.Document {
46 id: aDocument
47 database: aDatabase
48 docId: 'hello'
49 create: true
50 defaults: { "hello": [{"value":"99 Hello Worlds on the wall...!"},{"value":"98 Hello Worlds on the wall...!"},{"value":"97 Hello Worlds on the wall...!"},{"value":"...and so on..."}] }
51 }
52
53 */
54
55 U1db.Document {
56 id: aDocument
57 database: aDatabase
58 docId: 'hello'
59 create: true
60 defaults: { "hello": [{"value":"99 Hello Worlds on the wall...!"},{"value":"98 Hello Worlds on the wall...!"},{"value":"97 Hello Worlds on the wall...!"},{"value":"...and so on..."}] }
61 }
62
63 Tabs {
64 id: tabs
65 anchors.fill: parent
66
67 Tab {
68 objectName: "Tab1"
69
70 title: i18n.tr("Hello U1Db!")
71
72 page: Page {
73
74 id: helloPage
75
76 ListView {
77 width: units.gu(45)
78 height: units.gu(80)
79 anchors.fill: parent
80 model: aDocument.contents.hello
81
82 /*!
83
84 Determining the current record is easy. All that is required is to access it using the delegate's own 'index' value, as shown here:
85
86 delegate: Text {
87 height: 30
88 text: aDocument.contents.hello[index].value
89 }
90
91
92 Remember that when the entries were created the sub-field was 'value'. So where index = 0, 'aDocument.contents.hello[0].value' will produce '99 Hello Worlds on the wall...!'. Each entry in the document will in turn create its own delegate with a new index number, which can then be used to extract the 'value' (or whatever other sub-field has been created).
93
94 */
95
96 delegate: Text {
97 height: 30
98 text: aDocument.contents.hello[index].value
99 }
100
101 }
102
103 }
104
105 }
106
107
108 }
109}
110

Subscribers

People subscribed via source and target branches

to all changes: