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
1=== added file 'examples/u1db-qt-example-2b.qml'
2--- examples/u1db-qt-example-2b.qml 1970-01-01 00:00:00 +0000
3+++ examples/u1db-qt-example-2b.qml 2013-03-19 05:44:21 +0000
4@@ -0,0 +1,110 @@
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+This example demonstrates how to create and query one level of sub-fields in a document.
31+
32+*/
33+
34+MainView {
35+
36+ id: u1dbView
37+ width: units.gu(45)
38+ height: units.gu(80)
39+
40+ U1db.Database {
41+ id: aDatabase
42+ path: "aU1DbDSatabase2b"
43+ }
44+
45+ /*!
46+
47+ 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.
48+
49+ U1db.Document {
50+ id: aDocument
51+ database: aDatabase
52+ docId: 'hello'
53+ create: true
54+ 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..."}] }
55+ }
56+
57+ */
58+
59+ U1db.Document {
60+ id: aDocument
61+ database: aDatabase
62+ docId: 'hello'
63+ create: true
64+ 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..."}] }
65+ }
66+
67+ Tabs {
68+ id: tabs
69+ anchors.fill: parent
70+
71+ Tab {
72+ objectName: "Tab1"
73+
74+ title: i18n.tr("Hello U1Db!")
75+
76+ page: Page {
77+
78+ id: helloPage
79+
80+ ListView {
81+ width: units.gu(45)
82+ height: units.gu(80)
83+ anchors.fill: parent
84+ model: aDocument.contents.hello
85+
86+ /*!
87+
88+ Determining the current record is easy. All that is required is to access it using the delegate's own 'index' value, as shown here:
89+
90+ delegate: Text {
91+ height: 30
92+ text: aDocument.contents.hello[index].value
93+ }
94+
95+
96+ 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).
97+
98+ */
99+
100+ delegate: Text {
101+ height: 30
102+ text: aDocument.contents.hello[index].value
103+ }
104+
105+ }
106+
107+ }
108+
109+ }
110+
111+
112+ }
113+}
114+

Subscribers

People subscribed via source and target branches

to all changes: