Merge lp:~3v1n0/u1db-qt/doc-path-change-fixes into lp:u1db-qt

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Cris Dywan
Approved revision: 128
Merged at revision: 129
Proposed branch: lp:~3v1n0/u1db-qt/doc-path-change-fixes
Merge into: lp:u1db-qt
Prerequisite: lp:~3v1n0/u1db-qt/uri-path-parsing
Diff against target: 155 lines (+26/-13)
9 files modified
examples/u1db-qt-example-1/u1db-qt-example-1.qml (+1/-1)
examples/u1db-qt-example-2/u1db-qt-example-2.qml (+1/-1)
examples/u1db-qt-example-2b/u1db-qt-example-2b.qml (+1/-1)
examples/u1db-qt-example-3/u1db-qt-example-3.qml (+1/-1)
examples/u1db-qt-example-5/u1db-qt-example-5.qml (+1/-1)
examples/u1db-qt-example-6/u1db-qt-example-6.qml (+2/-5)
src/document.cpp (+16/-0)
src/index.cpp (+1/-0)
tests/tst_database.qml (+2/-3)
To merge this branch: bzr merge lp:~3v1n0/u1db-qt/doc-path-change-fixes
Reviewer Review Type Date Requested Status
Cris Dywan Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+251439@code.launchpad.net

Commit message

Document: ensure defaults and contents are set when database path changes

Description of the change

When database path changes (as it happens when you use a JS call to set it), document does not initialize defaults and contents correctly on it.

To post a comment you must log in.
126. By Marco Trevisan (Treviño)

Document: put current contents on database when path changes and new one is empty

127. By Marco Trevisan (Treviño)

Examples: use Qt.resolvedUrl to open databases

In this way we won't put settings inside user config

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
128. By Marco Trevisan (Treviño)

Fix tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

That's a nice fix. I didn't even realize before that the unit tests hint at this very bug.

review: Approve
129. By Marco Trevisan (Treviño)

Index: ensure we've the index set on db when path changes

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/u1db-qt-example-1.qml'
2--- examples/u1db-qt-example-1/u1db-qt-example-1.qml 2015-03-06 02:38:22 +0000
3+++ examples/u1db-qt-example-1/u1db-qt-example-1.qml 2015-03-06 02:38:22 +0000
4@@ -36,7 +36,7 @@
5
6 U1db.Database {
7 id: aDatabase
8- path: "file:///tmp/aDatabase1.db";
9+ path: Qt.resolvedUrl("aDatabase1");
10 }
11
12 /*!
13
14=== modified file 'examples/u1db-qt-example-2/u1db-qt-example-2.qml'
15--- examples/u1db-qt-example-2/u1db-qt-example-2.qml 2013-05-02 18:20:33 +0000
16+++ examples/u1db-qt-example-2/u1db-qt-example-2.qml 2015-03-06 02:38:22 +0000
17@@ -35,7 +35,7 @@
18
19 U1db.Database {
20 id: aDatabase
21- path: "aDatabase2"
22+ path: Qt.resolvedUrl("aDatabase2")
23 }
24
25 Timer {
26
27=== modified file 'examples/u1db-qt-example-2b/u1db-qt-example-2b.qml'
28--- examples/u1db-qt-example-2b/u1db-qt-example-2b.qml 2013-05-02 18:20:33 +0000
29+++ examples/u1db-qt-example-2b/u1db-qt-example-2b.qml 2015-03-06 02:38:22 +0000
30@@ -36,7 +36,7 @@
31
32 U1db.Database {
33 id: aDatabase
34- path: "aDatabase2b"
35+ path: Qt.resolvedUrl("aDatabase2b")
36 }
37
38 /*!
39
40=== modified file 'examples/u1db-qt-example-3/u1db-qt-example-3.qml'
41--- examples/u1db-qt-example-3/u1db-qt-example-3.qml 2013-05-02 18:19:33 +0000
42+++ examples/u1db-qt-example-3/u1db-qt-example-3.qml 2015-03-06 02:38:22 +0000
43@@ -49,7 +49,7 @@
44
45 U1db.Database {
46 id: aDatabase
47- path: "aDatabase3"
48+ path: Qt.resolvedUrl("aDatabase3")
49 }
50
51 /*!
52
53=== modified file 'examples/u1db-qt-example-5/u1db-qt-example-5.qml'
54--- examples/u1db-qt-example-5/u1db-qt-example-5.qml 2013-05-02 18:20:33 +0000
55+++ examples/u1db-qt-example-5/u1db-qt-example-5.qml 2015-03-06 02:38:22 +0000
56@@ -27,7 +27,7 @@
57
58 U1db.Database {
59 id: aDatabase
60- path: "aDatabase5"
61+ path: Qt.resolvedUrl("aDatabase5")
62 }
63
64 U1db.Document {
65
66=== modified file 'examples/u1db-qt-example-6/u1db-qt-example-6.qml'
67--- examples/u1db-qt-example-6/u1db-qt-example-6.qml 2013-08-09 10:42:18 +0000
68+++ examples/u1db-qt-example-6/u1db-qt-example-6.qml 2015-03-06 02:38:22 +0000
69@@ -21,7 +21,6 @@
70 import U1db 1.0 as U1db
71 import Ubuntu.Components 0.1
72
73-
74 Item {
75
76 width: units.gu(45)
77@@ -29,7 +28,7 @@
78
79 U1db.Database {
80 id: aDatabase
81- path: "aDatabase6"
82+ path: Qt.resolvedUrl("aDatabase6");
83 }
84
85 U1db.Document {
86@@ -143,9 +142,7 @@
87 anchors.left: parent.left
88 anchors.right: parent.right
89 wrapMode: Text.WordWrap
90- text: {
91- text: sync_output
92- }
93+ text: sync_output.message_value
94 }
95 }
96
97
98=== modified file 'src/document.cpp'
99--- src/document.cpp 2015-02-19 10:37:54 +0000
100+++ src/document.cpp 2015-03-06 02:38:22 +0000
101@@ -71,6 +71,22 @@
102 {
103 if (!m_docId.isEmpty())
104 {
105+ if (m_create && m_defaults.isValid())
106+ {
107+ // Make sure we create defaults on new path
108+ m_create = false;
109+ setCreate(true);
110+ }
111+
112+ if (m_contents.isValid() && m_database && !m_docId.isEmpty())
113+ {
114+ if (!m_database->getDocUnchecked(m_docId).isValid())
115+ {
116+ // Put current contents on new database
117+ m_database->putDoc(m_contents, m_docId);
118+ }
119+ }
120+
121 m_contents = m_database->getDocUnchecked(m_docId);
122 Q_EMIT contentsChanged(m_contents);
123 }
124
125=== modified file 'src/index.cpp'
126--- src/index.cpp 2014-01-31 19:20:07 +0000
127+++ src/index.cpp 2015-03-06 02:38:22 +0000
128@@ -61,6 +61,7 @@
129 void
130 Index::onPathChanged(const QString& path)
131 {
132+ m_database->putIndex(m_name, m_expression);
133 Q_EMIT dataInvalidated();
134 }
135
136
137=== modified file 'tests/tst_database.qml'
138--- tests/tst_database.qml 2013-08-12 15:28:13 +0000
139+++ tests/tst_database.qml 2015-03-06 02:38:22 +0000
140@@ -127,13 +127,12 @@
141 myDatabase.putDoc({'foo': 'bar'} ,'dl' + Number(i).toLocaleString())
142 myDatabase.path = ":memory:"
143 spyPathChanged.wait()
144- compare(myDatabase.listDocs(), [])
145- compare(myList.count, 0)
146+ compare(myList.count, 2)
147 myDatabase.first_row_loaded = false
148 myDatabase.last_row_loaded = false
149 myDatabase.path = path
150 spyPathChanged.wait()
151- compare(myList.count, 100)
152+ compare(myList.count, 102)
153 spyDocLoaded.wait()
154 // FIXME compare(myDatabase.first_row_loaded, true)
155 // FIXME compare(myDatabase.last_row_loaded, false)

Subscribers

People subscribed via source and target branches

to all changes: