Merge lp:~kalikiana/u1db-qt/docf into lp:u1db-qt

Proposed by Cris Dywan
Status: Merged
Approved by: Cris Dywan
Approved revision: 83
Merged at revision: 76
Proposed branch: lp:~kalikiana/u1db-qt/docf
Merge into: lp:u1db-qt
Diff against target: 323 lines (+57/-49)
4 files modified
documentation/u1db.qdocconf (+1/-0)
src/database.cpp (+33/-27)
src/index.cpp (+8/-17)
src/query.cpp (+15/-5)
To merge this branch: bzr merge lp:~kalikiana/u1db-qt/docf
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+160097@code.launchpad.net

Commit message

Mark internal methods, mention model feature and document parameters

Description of the change

Mark internal methods, mention model feature and document parameters

To post a comment you must log in.
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
Cris Dywan (kalikiana) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'documentation/u1db.qdocconf'
2--- documentation/u1db.qdocconf 2013-04-22 10:35:32 +0000
3+++ documentation/u1db.qdocconf 2013-04-22 12:57:29 +0000
4@@ -11,6 +11,7 @@
5 Cpp.ignoretokens = Q_DECL_EXPORT \
6 Q_PROPERTY \
7 QT_BEGIN_NAMESPACE_U1DB \
8+ Q_INVOKABLE \
9
10 defines = Q_QDOC
11 Cpp.ignoredirectives = Q_ENUMS \
12
13=== modified file 'src/database.cpp'
14--- src/database.cpp 2013-04-22 10:35:32 +0000
15+++ src/database.cpp 2013-04-22 12:57:29 +0000
16@@ -39,8 +39,8 @@
17 \brief The Database class implements the on-disk storage of an individual
18 U1DB database.
19
20- The functional API can be used from C++ and Javascript, and is the basis of
21- the declarative API.
22+ Database can be used as a QAbstractListModel, delegates will then have access to \a docId and \a contents
23+ analogous to the properties of Document.
24 */
25
26 /*!
27@@ -167,6 +167,7 @@
28 }
29
30 /*!
31+ \internal
32 Used to implement QAbstractListModel
33 Implements the variables exposed to the Delegate in a model
34 QVariant contents
35@@ -185,6 +186,7 @@
36 }
37
38 /*!
39+ \internal
40 Used to implement QAbstractListModel
41 Defines \b{contents} and \b{docId} as variables exposed to the Delegate in a model
42 \b{index} is supported out of the box.
43@@ -199,6 +201,7 @@
44 }
45
46 /*!
47+ \internal
48 Used to implement QAbstractListModel
49 The number of rows: the number of documents in the database.
50 */
51@@ -216,8 +219,9 @@
52 }
53
54 /*!
55- Same functionality as getDoc() except it won't set lastError() and it
56+ Same functionality as Database::getDoc() except it won't set Database::lastError() and it
57 doesn't implicitly try to initialize the underlying database.
58+ \a docId must be a valid unique ID string
59 Use cases: model implementations, Document::getContents()
60 */
61 QVariant
62@@ -240,9 +244,9 @@
63 }
64
65 /*!
66- Returns the contents of a document by docId in a form that QML recognizes
67+ Returns the contents of a document by \a docId in a form that QML recognizes
68 as a Variant object, it's identical to Document::getContents() with the
69- same docId.
70+ same \a docId.
71 */
72 QVariant
73 Database::getDoc(const QString& docId)
74@@ -280,52 +284,52 @@
75 }
76
77 /*!
78- Updates the existing contents of the document identified by docId if
79+ Updates the existing \a contents of the document identified by \a docId if
80 there's no error.
81- If no docId is given or docId is an empty string the contents will be
82+ If no \a docId is given or \a docId is an empty string the \a contents will be
83 stored under an autogenerated name.
84 Returns the new revision of the document, or -1 on failure.
85 */
86 int
87-Database::putDoc(QVariant newDoc, const QString& newOrEmptyDocId)
88+Database::putDoc(QVariant contents, const QString& docId)
89 {
90 if (!initializeIfNeeded())
91 return -1;
92
93- QString docId(newOrEmptyDocId);
94- QVariant oldDoc = docId.isEmpty() ? QVariant() : getDocUnchecked(docId);
95+ QString newOrEmptyDocId(docId);
96+ QVariant oldDoc = newOrEmptyDocId.isEmpty() ? QVariant() : getDocUnchecked(newOrEmptyDocId);
97 /* FIXME: Conflicts */
98
99- int newRev = increaseVectorClockRev(7/*newDoc.rev*/);
100+ int newRev = increaseVectorClockRev(7/*contents.rev*/);
101 QSqlQuery query(m_db.exec());
102 if (oldDoc.isValid())
103 {
104 query.prepare("UPDATE document SET doc_rev=:docRev, content=:docJson WHERE doc_id = :docId");
105- query.bindValue(":docId", docId);
106+ query.bindValue(":docId", newOrEmptyDocId);
107 query.bindValue(":docRev", newRev);
108 // Parse Variant from QML as JsonDocument, fallback to string
109- QString json(QJsonDocument::fromVariant(newDoc).toJson());
110- query.bindValue(":docJson", json.isEmpty() ? newDoc : json);
111+ QString json(QJsonDocument::fromVariant(contents).toJson());
112+ query.bindValue(":docJson", json.isEmpty() ? contents : json);
113 if (!query.exec())
114- return setError(QString("Failed to put/ update document %1: %2\n%3").arg(docId).arg(query.lastError().text()).arg(query.lastQuery())) ? -1 : -1;
115+ return setError(QString("Failed to put/ update document %1: %2\n%3").arg(newOrEmptyDocId).arg(query.lastError().text()).arg(query.lastQuery())) ? -1 : -1;
116 query.prepare("DELETE FROM document_fields WHERE doc_id = :docId");
117- query.bindValue(":docId", docId);
118+ query.bindValue(":docId", newOrEmptyDocId);
119 if (!query.exec())
120- return setError(QString("Failed to delete document field %1: %2\n%3").arg(docId).arg(query.lastError().text()).arg(query.lastQuery())) ? -1 : -1;
121+ return setError(QString("Failed to delete document field %1: %2\n%3").arg(newOrEmptyDocId).arg(query.lastError().text()).arg(query.lastQuery())) ? -1 : -1;
122 }
123 else
124 {
125- if (docId.isEmpty())
126- docId = QString("D-%1").arg(QUuid::createUuid().toString().mid(1).replace("}",""));
127- if (!QRegExp("^[a-zA-Z0-9.%_-]+$").exactMatch(docId))
128- return setError(QString("Invalid docID %1").arg(docId)) ? -1 : -1;
129+ if (newOrEmptyDocId.isEmpty())
130+ newOrEmptyDocId = QString("D-%1").arg(QUuid::createUuid().toString().mid(1).replace("}",""));
131+ if (!QRegExp("^[a-zA-Z0-9.%_-]+$").exactMatch(newOrEmptyDocId))
132+ return setError(QString("Invalid docID %1").arg(newOrEmptyDocId)) ? -1 : -1;
133
134 query.prepare("INSERT INTO document (doc_id, doc_rev, content) VALUES (:docId, :docRev, :docJson)");
135- query.bindValue(":docId", docId);
136+ query.bindValue(":docId", newOrEmptyDocId);
137 query.bindValue(":docRev", newRev);
138 // Parse Variant from QML as JsonDocument, fallback to string
139- QJsonDocument json(QJsonDocument::fromVariant(newDoc));
140- query.bindValue(":docJson", json.isEmpty() ? newDoc : json.toJson());
141+ QJsonDocument json(QJsonDocument::fromVariant(contents));
142+ query.bindValue(":docJson", json.isEmpty() ? contents : json.toJson());
143 if (!query.exec())
144 return setError(QString("Failed to put document %1: %2\n%3").arg(docId).arg(query.lastError().text()).arg(query.lastQuery())) ? -1 : -1;
145 }
146@@ -341,7 +345,7 @@
147
148 documentCount = documents.count();
149
150- Q_EMIT docChanged(docId, newDoc);
151+ Q_EMIT docChanged(newOrEmptyDocId, contents);
152
153 return newRev;
154 }
155@@ -403,8 +407,8 @@
156 }
157
158 /*!
159- Stores a new index under the given name. An existing index won't be
160- replaced implicitly, an error will be set in that case.
161+ Stores a new index under the given \a indexName, with \a expressions.
162+ An existing index won't be replaced implicitly, an error will be set in that case.
163 */
164 QString
165 Database::putIndex(const QString& indexName, QStringList expressions)
166@@ -442,6 +446,7 @@
167
168 /*!
169 Gets the expressions saved with putIndex().
170+ \a indexName: the unique name of an existing index
171 */
172 QStringList
173 Database::getIndexExpressions(const QString& indexName)
174@@ -464,6 +469,7 @@
175
176 /*!
177 Lists the index keys of an index created with putIndex().
178+ \a indexName: the unique name of an existing index
179 */
180 QStringList
181 Database::getIndexKeys(const QString& indexName)
182
183=== modified file 'src/index.cpp'
184--- src/index.cpp 2013-04-22 10:35:32 +0000
185+++ src/index.cpp 2013-04-22 12:57:29 +0000
186@@ -152,8 +152,7 @@
187 }
188
189 /*!
190- * \brief Index::generateIndexResults
191- *
192+ \internal
193 * Iterates through the documents stored in the database and creates the list of results based on the Index expressions.
194 */
195
196@@ -180,6 +179,9 @@
197
198 }
199
200+/*!
201+ \internal
202+ */
203 void Index::clearResults()
204 {
205 m_results.clear();
206@@ -187,8 +189,7 @@
207
208
209 /*!
210- * \brief Index::getAllResults
211- * \return
212+ \internal
213 */
214
215 QList<QVariantMap> Index::getAllResults(){
216@@ -196,20 +197,14 @@
217 }
218
219 /*!
220- * \brief Index::getResult
221- * \param index
222- * \return
223+ \internal
224 */
225 QVariantMap Index::getResult(int index){
226 return m_results[index];
227 }
228
229 /*!
230- * \brief Index::appendResultsFromMap
231- * \param fieldsList
232- * \param current_section
233- * \param current_field
234- * \return
235+ \internal
236 *
237 *This method is desinged to recursively iterate through a document, or section of a document, which represents a QVariantMap. As it iterates through the entire document, the method keeps track of the current index expression, and populates a local QVariantMap should the current expression be found in the Index's list of expressions.
238 *
239@@ -264,11 +259,7 @@
240 return fieldsList;
241 }
242 /*!
243- * \brief Index::getFieldsFromList
244- * \param fieldsList
245- * \param current_section
246- * \param current_field
247- * \return
248+ \internal
249 *
250 *This recursive method is used in conjuntion with Index::appendResultsFromMap, to aid in iterating through a document when an embedded list is found.
251 *
252
253=== modified file 'src/query.cpp'
254--- src/query.cpp 2013-04-22 11:19:36 +0000
255+++ src/query.cpp 2013-04-22 12:57:29 +0000
256@@ -39,7 +39,8 @@
257 \brief The Query class generates a filtered list of documents based on either
258 a query or a range, and using the given Index.
259
260- This is the declarative API equivalent of FIXME
261+ Query can be used as a QAbstractListModel, delegates will then have access to \a docId and \a contents
262+ analogous to the properties of Document.
263 */
264
265 Query::Query(QObject *parent) :
266@@ -48,10 +49,7 @@
267 }
268
269 /*!
270- * \brief Query::data
271- * \param index
272- * \param role
273- * \return
274+ \internal
275 *Used to implement QAbstractListModel
276 *Implements the variables exposed to the Delegate in a model
277 */
278@@ -74,6 +72,7 @@
279 }
280
281 /*!
282+ \internal
283 Used to implement QAbstractListModel
284 Defines \b{contents} and \b{docId} as variables exposed to the Delegate in a model
285 \b{index} is supported out of the box.
286@@ -88,6 +87,7 @@
287 }
288
289 /*!
290+ \internal
291 Used to implement QAbstractListModel
292 The number of rows: the number of documents given by the query.
293 */
294@@ -97,12 +97,19 @@
295 return m_hash.count();
296 }
297
298+/*!
299+ Returns the Index used to query the database.
300+ */
301 Index*
302 Query::getIndex()
303 {
304 return m_index;
305 }
306
307+/*!
308+ Emitted whenever the index or documents change, and the results
309+ need to be updated.
310+ */
311 void
312 Query::onDataInvalidated()
313 {
314@@ -303,6 +310,9 @@
315
316 }
317
318+/*!
319+ Returns the query used, in the form of a string, list or variant.
320+ */
321 QVariant
322 Query::getQuery()
323 {

Subscribers

People subscribed via source and target branches

to all changes: