Status: | Merged |
---|---|
Approved by: | Cris Dywan |
Approved revision: | 66 |
Merged at revision: | 58 |
Proposed branch: | lp:~kalikiana/u1db-qt/trunk |
Merge into: | lp:u1db-qt |
Diff against target: |
483 lines (+193/-0) 4 files modified
database.cpp (+93/-0) document.cpp (+36/-0) index.cpp (+24/-0) query.cpp (+40/-0) |
To merge this branch: | bzr merge lp:~kalikiana/u1db-qt/trunk |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Cris Dywan | Approve | ||
Review via email: mp+156795@code.launchpad.net |
Commit message
qdoc for Database, Document, Index and Query
Description of the change
qdoc for Database, Document, Index and Query
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:
Needs Fixing
(continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) : | # |
review:
Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'database.cpp' | |||
2 | --- database.cpp 2013-03-20 17:10:45 +0000 | |||
3 | +++ database.cpp 2013-04-03 10:16:22 +0000 | |||
4 | @@ -31,6 +31,19 @@ | |||
5 | 31 | 31 | ||
6 | 32 | QT_BEGIN_NAMESPACE_U1DB | 32 | QT_BEGIN_NAMESPACE_U1DB |
7 | 33 | 33 | ||
8 | 34 | /*! | ||
9 | 35 | \class Database | ||
10 | 36 | |||
11 | 37 | \brief The Database class implements the on-disk storage of an individual | ||
12 | 38 | U1DB database. | ||
13 | 39 | |||
14 | 40 | The functional API can be used from C++ and Javascript, and is the basis of | ||
15 | 41 | the declarative API. | ||
16 | 42 | */ | ||
17 | 43 | |||
18 | 44 | /*! | ||
19 | 45 | A unique identifier for the state of synchronization | ||
20 | 46 | */ | ||
21 | 34 | QString | 47 | QString |
22 | 35 | Database::getReplicaUid() | 48 | Database::getReplicaUid() |
23 | 36 | { | 49 | { |
24 | @@ -40,6 +53,10 @@ | |||
25 | 40 | return setError(QString("Failed to get replica UID: %1\n%2").arg(query.lastError().text()).arg(query.lastQuery())) ? QString() : QString(); | 53 | return setError(QString("Failed to get replica UID: %1\n%2").arg(query.lastError().text()).arg(query.lastQuery())) ? QString() : QString(); |
26 | 41 | } | 54 | } |
27 | 42 | 55 | ||
28 | 56 | /*! | ||
29 | 57 | Checks if the underlying SQLite database is ready to be used | ||
30 | 58 | Only to be used as a utility function by initializeIfNeeded() | ||
31 | 59 | */ | ||
32 | 43 | bool | 60 | bool |
33 | 44 | Database::isInitialized() | 61 | Database::isInitialized() |
34 | 45 | { | 62 | { |
35 | @@ -49,6 +66,9 @@ | |||
36 | 49 | return query.next(); | 66 | return query.next(); |
37 | 50 | } | 67 | } |
38 | 51 | 68 | ||
39 | 69 | /*! | ||
40 | 70 | Describes the error as a string if the last operation failed. | ||
41 | 71 | */ | ||
42 | 52 | bool | 72 | bool |
43 | 53 | Database::setError(const QString& error) | 73 | Database::setError(const QString& error) |
44 | 54 | { | 74 | { |
45 | @@ -58,12 +78,22 @@ | |||
46 | 58 | return false; | 78 | return false; |
47 | 59 | } | 79 | } |
48 | 60 | 80 | ||
49 | 81 | /*! | ||
50 | 82 | Describes the error as a string if the last operation failed. | ||
51 | 83 | */ | ||
52 | 61 | QString | 84 | QString |
53 | 62 | Database::lastError() | 85 | Database::lastError() |
54 | 63 | { | 86 | { |
55 | 64 | return m_error; | 87 | return m_error; |
56 | 65 | } | 88 | } |
57 | 66 | 89 | ||
58 | 90 | /*! | ||
59 | 91 | Ensures that the underlying database works, or tries to set it up: | ||
60 | 92 | |||
61 | 93 | The SQlite backend is loaded - it's an optional Qt5 module and can fail | ||
62 | 94 | If @path is an existing database, it'll be opened | ||
63 | 95 | For a new database, the default schema will be applied | ||
64 | 96 | */ | ||
65 | 67 | bool | 97 | bool |
66 | 68 | Database::initializeIfNeeded(const QString& path) | 98 | Database::initializeIfNeeded(const QString& path) |
67 | 69 | { | 99 | { |
68 | @@ -115,6 +145,11 @@ | |||
69 | 115 | initializeIfNeeded(); | 145 | initializeIfNeeded(); |
70 | 116 | } | 146 | } |
71 | 117 | 147 | ||
72 | 148 | /*! | ||
73 | 149 | Used to implement QAbstractListModel | ||
74 | 150 | Returns docId matching the given row index | ||
75 | 151 | assuming all documents are ordered consistently | ||
76 | 152 | */ | ||
77 | 118 | QString | 153 | QString |
78 | 119 | Database::getDocIdByRow(int row) const | 154 | Database::getDocIdByRow(int row) const |
79 | 120 | { | 155 | { |
80 | @@ -129,6 +164,13 @@ | |||
81 | 129 | return QString(); | 164 | return QString(); |
82 | 130 | } | 165 | } |
83 | 131 | 166 | ||
84 | 167 | /*! | ||
85 | 168 | Used to implement QAbstractListModel | ||
86 | 169 | Implements the variables exposed to the Delegate in a model | ||
87 | 170 | QVariant contents | ||
88 | 171 | QString docId | ||
89 | 172 | int index (built-in) | ||
90 | 173 | */ | ||
91 | 132 | QVariant | 174 | QVariant |
92 | 133 | Database::data(const QModelIndex & index, int role) const | 175 | Database::data(const QModelIndex & index, int role) const |
93 | 134 | { | 176 | { |
94 | @@ -140,6 +182,11 @@ | |||
95 | 140 | return QVariant(); | 182 | return QVariant(); |
96 | 141 | } | 183 | } |
97 | 142 | 184 | ||
98 | 185 | /*! | ||
99 | 186 | Used to implement QAbstractListModel | ||
100 | 187 | Defines \b{contents} and \b{docId} as variables exposed to the Delegate in a model | ||
101 | 188 | \b{index} is supported out of the box. | ||
102 | 189 | */ | ||
103 | 143 | QHash<int, QByteArray> | 190 | QHash<int, QByteArray> |
104 | 144 | Database::roleNames() const | 191 | Database::roleNames() const |
105 | 145 | { | 192 | { |
106 | @@ -149,6 +196,10 @@ | |||
107 | 149 | return roles; | 196 | return roles; |
108 | 150 | } | 197 | } |
109 | 151 | 198 | ||
110 | 199 | /*! | ||
111 | 200 | Used to implement QAbstractListModel | ||
112 | 201 | The number of rows: the number of documents in the database. | ||
113 | 202 | */ | ||
114 | 152 | int | 203 | int |
115 | 153 | Database::rowCount(const QModelIndex & parent) const | 204 | Database::rowCount(const QModelIndex & parent) const |
116 | 154 | { | 205 | { |
117 | @@ -162,6 +213,11 @@ | |||
118 | 162 | return query.value("count").toInt(); | 213 | return query.value("count").toInt(); |
119 | 163 | } | 214 | } |
120 | 164 | 215 | ||
121 | 216 | /*! | ||
122 | 217 | Same functionality as getDoc() except it won't set lastError() and it | ||
123 | 218 | doesn't implicitly try to initialize the underlying database. | ||
124 | 219 | Use cases: model implementations, Document::getContents() | ||
125 | 220 | */ | ||
126 | 165 | QVariant | 221 | QVariant |
127 | 166 | Database::getDocUnchecked(const QString& docId) const | 222 | Database::getDocUnchecked(const QString& docId) const |
128 | 167 | { | 223 | { |
129 | @@ -173,6 +229,7 @@ | |||
130 | 173 | query.bindValue(":docId", docId); | 229 | query.bindValue(":docId", docId); |
131 | 174 | if (query.exec() && query.next()) | 230 | if (query.exec() && query.next()) |
132 | 175 | { | 231 | { |
133 | 232 | // Convert JSON string to the Variant that QML expects | ||
134 | 176 | QJsonDocument json(QJsonDocument::fromJson(query.value("content").toByteArray())); | 233 | QJsonDocument json(QJsonDocument::fromJson(query.value("content").toByteArray())); |
135 | 177 | Q_EMIT docLoaded(docId, json.object().toVariantMap()); | 234 | Q_EMIT docLoaded(docId, json.object().toVariantMap()); |
136 | 178 | return json.object().toVariantMap(); | 235 | return json.object().toVariantMap(); |
137 | @@ -180,6 +237,11 @@ | |||
138 | 180 | return QVariant(); | 237 | return QVariant(); |
139 | 181 | } | 238 | } |
140 | 182 | 239 | ||
141 | 240 | /*! | ||
142 | 241 | Returns the contents of a document by docId in a form that QML recognizes | ||
143 | 242 | as a Variant object, it's identical to Document::getContents() with the | ||
144 | 243 | same docId. | ||
145 | 244 | */ | ||
146 | 183 | QVariant | 245 | QVariant |
147 | 184 | Database::getDoc(const QString& docId) | 246 | Database::getDoc(const QString& docId) |
148 | 185 | { | 247 | { |
149 | @@ -199,6 +261,7 @@ | |||
150 | 199 | { | 261 | { |
151 | 200 | if (query.value("conflicts").toInt() > 0) | 262 | if (query.value("conflicts").toInt() > 0) |
152 | 201 | setError(QString("Conflicts in %1").arg(docId)); | 263 | setError(QString("Conflicts in %1").arg(docId)); |
153 | 264 | // Convert JSON string to the Variant that QML expects | ||
154 | 202 | QJsonDocument json(QJsonDocument::fromJson(query.value("content").toByteArray())); | 265 | QJsonDocument json(QJsonDocument::fromJson(query.value("content").toByteArray())); |
155 | 203 | Q_EMIT docLoaded(docId, json.object().toVariantMap()); | 266 | Q_EMIT docLoaded(docId, json.object().toVariantMap()); |
156 | 204 | return json.object().toVariantMap(); | 267 | return json.object().toVariantMap(); |
157 | @@ -214,6 +277,13 @@ | |||
158 | 214 | return oldRev; | 277 | return oldRev; |
159 | 215 | } | 278 | } |
160 | 216 | 279 | ||
161 | 280 | /*! | ||
162 | 281 | Updates the existing contents of the document identified by docId if | ||
163 | 282 | there's no error. | ||
164 | 283 | If no docId is given or docId is an empty string the contents will be | ||
165 | 284 | stored under an autogenerated name. | ||
166 | 285 | Returns the new revision of the document, or -1 on failure. | ||
167 | 286 | */ | ||
168 | 217 | int | 287 | int |
169 | 218 | Database::putDoc(QVariant newDoc, const QString& newOrEmptyDocId) | 288 | Database::putDoc(QVariant newDoc, const QString& newOrEmptyDocId) |
170 | 219 | { | 289 | { |
171 | @@ -231,6 +301,7 @@ | |||
172 | 231 | query.prepare("UPDATE document SET doc_rev=:docRev, content=:docJson WHERE doc_id = :docId"); | 301 | query.prepare("UPDATE document SET doc_rev=:docRev, content=:docJson WHERE doc_id = :docId"); |
173 | 232 | query.bindValue(":docId", docId); | 302 | query.bindValue(":docId", docId); |
174 | 233 | query.bindValue(":docRev", newRev); | 303 | query.bindValue(":docRev", newRev); |
175 | 304 | // Parse Variant from QML as JsonDocument, fallback to string | ||
176 | 234 | QString json(QJsonDocument::fromVariant(newDoc).toJson()); | 305 | QString json(QJsonDocument::fromVariant(newDoc).toJson()); |
177 | 235 | query.bindValue(":docJson", json.isEmpty() ? newDoc : json); | 306 | query.bindValue(":docJson", json.isEmpty() ? newDoc : json); |
178 | 236 | if (!query.exec()) | 307 | if (!query.exec()) |
179 | @@ -250,6 +321,7 @@ | |||
180 | 250 | query.prepare("INSERT INTO document (doc_id, doc_rev, content) VALUES (:docId, :docRev, :docJson)"); | 321 | query.prepare("INSERT INTO document (doc_id, doc_rev, content) VALUES (:docId, :docRev, :docJson)"); |
181 | 251 | query.bindValue(":docId", docId); | 322 | query.bindValue(":docId", docId); |
182 | 252 | query.bindValue(":docRev", newRev); | 323 | query.bindValue(":docRev", newRev); |
183 | 324 | // Parse Variant from QML as JsonDocument, fallback to string | ||
184 | 253 | QJsonDocument json(QJsonDocument::fromVariant(newDoc)); | 325 | QJsonDocument json(QJsonDocument::fromVariant(newDoc)); |
185 | 254 | query.bindValue(":docJson", json.isEmpty() ? newDoc : json.toJson()); | 326 | query.bindValue(":docJson", json.isEmpty() ? newDoc : json.toJson()); |
186 | 255 | if (!query.exec()) | 327 | if (!query.exec()) |
187 | @@ -290,6 +362,13 @@ | |||
188 | 290 | return setError(QString("Failed to list documents: %1\n%2").arg(query.lastError().text()).arg(query.lastQuery())) ? list : list; | 362 | return setError(QString("Failed to list documents: %1\n%2").arg(query.lastError().text()).arg(query.lastQuery())) ? list : list; |
189 | 291 | } | 363 | } |
190 | 292 | 364 | ||
191 | 365 | /*! | ||
192 | 366 | A relative filename or absolute path advises the database to store documents | ||
193 | 367 | and indexes persistently on disk. Internally, an SQlite database is written. | ||
194 | 368 | |||
195 | 369 | If no path is set, as is the default, all database contents are written in | ||
196 | 370 | memory only. The same affect can be achieved by passing the string ":memory:". | ||
197 | 371 | */ | ||
198 | 293 | void | 372 | void |
199 | 294 | Database::setPath(const QString& path) | 373 | Database::setPath(const QString& path) |
200 | 295 | { | 374 | { |
201 | @@ -306,12 +385,20 @@ | |||
202 | 306 | Q_EMIT pathChanged(path); | 385 | Q_EMIT pathChanged(path); |
203 | 307 | } | 386 | } |
204 | 308 | 387 | ||
205 | 388 | /*! | ||
206 | 389 | The persistent storage location if set. By default the database is only | ||
207 | 390 | storted in memory. See setPath(). | ||
208 | 391 | */ | ||
209 | 309 | QString | 392 | QString |
210 | 310 | Database::getPath() | 393 | Database::getPath() |
211 | 311 | { | 394 | { |
212 | 312 | return m_path; | 395 | return m_path; |
213 | 313 | } | 396 | } |
214 | 314 | 397 | ||
215 | 398 | /*! | ||
216 | 399 | Stores a new index under the given name. An existing index won't be | ||
217 | 400 | replaced implicitly, an error will be set in that case. | ||
218 | 401 | */ | ||
219 | 315 | QString | 402 | QString |
220 | 316 | Database::putIndex(const QString& indexName, QStringList expressions) | 403 | Database::putIndex(const QString& indexName, QStringList expressions) |
221 | 317 | { | 404 | { |
222 | @@ -346,6 +433,9 @@ | |||
223 | 346 | return QString(); | 433 | return QString(); |
224 | 347 | } | 434 | } |
225 | 348 | 435 | ||
226 | 436 | /*! | ||
227 | 437 | Gets the expressions saved with putIndex(). | ||
228 | 438 | */ | ||
229 | 349 | QStringList | 439 | QStringList |
230 | 350 | Database::getIndexExpressions(const QString& indexName) | 440 | Database::getIndexExpressions(const QString& indexName) |
231 | 351 | { | 441 | { |
232 | @@ -365,6 +455,9 @@ | |||
233 | 365 | return expressions; | 455 | return expressions; |
234 | 366 | } | 456 | } |
235 | 367 | 457 | ||
236 | 458 | /*! | ||
237 | 459 | Lists the index keys of an index created with putIndex(). | ||
238 | 460 | */ | ||
239 | 368 | QStringList | 461 | QStringList |
240 | 369 | Database::getIndexKeys(const QString& indexName) | 462 | Database::getIndexKeys(const QString& indexName) |
241 | 370 | { | 463 | { |
242 | 371 | 464 | ||
243 | === modified file 'document.cpp' | |||
244 | --- document.cpp 2013-03-06 12:06:56 +0000 | |||
245 | +++ document.cpp 2013-04-03 10:16:22 +0000 | |||
246 | @@ -30,6 +30,15 @@ | |||
247 | 30 | 30 | ||
248 | 31 | QT_BEGIN_NAMESPACE_U1DB | 31 | QT_BEGIN_NAMESPACE_U1DB |
249 | 32 | 32 | ||
250 | 33 | /*! | ||
251 | 34 | \class Document | ||
252 | 35 | |||
253 | 36 | \brief The Document class proxies a single document stored in the Database. | ||
254 | 37 | |||
255 | 38 | This is the declarative API equivalent of Database::putDoc() and | ||
256 | 39 | Database::getDoc(). | ||
257 | 40 | */ | ||
258 | 41 | |||
259 | 33 | Document::Document(QObject *parent) : | 42 | Document::Document(QObject *parent) : |
260 | 34 | QObject(parent), m_database(0), m_create(false) | 43 | QObject(parent), m_database(0), m_create(false) |
261 | 35 | { | 44 | { |
262 | @@ -61,6 +70,10 @@ | |||
263 | 61 | } | 70 | } |
264 | 62 | } | 71 | } |
265 | 63 | 72 | ||
266 | 73 | /*! | ||
267 | 74 | The database is used to lookup the contents of the document, reflecting | ||
268 | 75 | changes done to it and conversely changes are saved to the database. | ||
269 | 76 | */ | ||
270 | 64 | void | 77 | void |
271 | 65 | Document::setDatabase(Database* database) | 78 | Document::setDatabase(Database* database) |
272 | 66 | { | 79 | { |
273 | @@ -90,6 +103,11 @@ | |||
274 | 90 | return m_docId; | 103 | return m_docId; |
275 | 91 | } | 104 | } |
276 | 92 | 105 | ||
277 | 106 | /*! | ||
278 | 107 | The docId can be that of an existing document in the database and | ||
279 | 108 | will determine what getContents() returns. | ||
280 | 109 | If no such documents exists, setDefaults() can be used to supply a preset. | ||
281 | 110 | */ | ||
282 | 93 | void | 111 | void |
283 | 94 | Document::setDocId(const QString& docId) | 112 | Document::setDocId(const QString& docId) |
284 | 95 | { | 113 | { |
285 | @@ -112,6 +130,10 @@ | |||
286 | 112 | return m_create; | 130 | return m_create; |
287 | 113 | } | 131 | } |
288 | 114 | 132 | ||
289 | 133 | /*! | ||
290 | 134 | If create is true, docId is not empty and no document with the same docId | ||
291 | 135 | exists, defaults will be used to store the document. | ||
292 | 136 | */ | ||
293 | 115 | void | 137 | void |
294 | 116 | Document::setCreate(bool create) | 138 | Document::setCreate(bool create) |
295 | 117 | { | 139 | { |
296 | @@ -131,6 +153,12 @@ | |||
297 | 131 | return m_defaults; | 153 | return m_defaults; |
298 | 132 | } | 154 | } |
299 | 133 | 155 | ||
300 | 156 | /*! | ||
301 | 157 | The default contents of the document, which are used only if | ||
302 | 158 | create is true, docId is not empty and no document with the same | ||
303 | 159 | docId exists in the database yet. | ||
304 | 160 | If the defaults change, it's up to the API user to handle it. | ||
305 | 161 | */ | ||
306 | 134 | void | 162 | void |
307 | 135 | Document::setDefaults(QVariant defaults) | 163 | Document::setDefaults(QVariant defaults) |
308 | 136 | { | 164 | { |
309 | @@ -144,12 +172,20 @@ | |||
310 | 144 | m_database->putDoc(m_defaults, m_docId); | 172 | m_database->putDoc(m_defaults, m_docId); |
311 | 145 | } | 173 | } |
312 | 146 | 174 | ||
313 | 175 | /*! | ||
314 | 176 | The contents of the document, as set via setContents() or stored in | ||
315 | 177 | the database via Database::putDoc(). | ||
316 | 178 | onContentsChanged() can be used to monitor changes. | ||
317 | 179 | */ | ||
318 | 147 | QVariant | 180 | QVariant |
319 | 148 | Document::getContents() | 181 | Document::getContents() |
320 | 149 | { | 182 | { |
321 | 150 | return m_contents; | 183 | return m_contents; |
322 | 151 | } | 184 | } |
323 | 152 | 185 | ||
324 | 186 | /*! | ||
325 | 187 | Updates the contents of the document. A valid docId must be set. | ||
326 | 188 | */ | ||
327 | 153 | void | 189 | void |
328 | 154 | Document::setContents(QVariant contents) | 190 | Document::setContents(QVariant contents) |
329 | 155 | { | 191 | { |
330 | 156 | 192 | ||
331 | === modified file 'index.cpp' | |||
332 | --- index.cpp 2013-02-28 17:59:51 +0000 | |||
333 | +++ index.cpp 2013-04-03 10:16:22 +0000 | |||
334 | @@ -30,6 +30,17 @@ | |||
335 | 30 | 30 | ||
336 | 31 | QT_BEGIN_NAMESPACE_U1DB | 31 | QT_BEGIN_NAMESPACE_U1DB |
337 | 32 | 32 | ||
338 | 33 | /*! | ||
339 | 34 | \class Index | ||
340 | 35 | |||
341 | 36 | \brief The Index class defines an index to be stored in the database and | ||
342 | 37 | queried using Query. Changes in documents affected by the index also update | ||
343 | 38 | the index in the database. | ||
344 | 39 | |||
345 | 40 | This is the declarative API equivalent of Database::putIndex() and | ||
346 | 41 | Database::getIndexExpressions(). | ||
347 | 42 | */ | ||
348 | 43 | |||
349 | 33 | Index::Index(QObject *parent) : | 44 | Index::Index(QObject *parent) : |
350 | 34 | QObject(parent), m_database(0) | 45 | QObject(parent), m_database(0) |
351 | 35 | { | 46 | { |
352 | @@ -53,6 +64,11 @@ | |||
353 | 53 | Q_EMIT dataInvalidated(); | 64 | Q_EMIT dataInvalidated(); |
354 | 54 | } | 65 | } |
355 | 55 | 66 | ||
356 | 67 | /*! | ||
357 | 68 | Sets the Database to lookup documents from and store the index in. The | ||
358 | 69 | dataInvalidated() signal will be emitted on all changes that could affect | ||
359 | 70 | the index. | ||
360 | 71 | */ | ||
361 | 56 | void | 72 | void |
362 | 57 | Index::setDatabase(Database* database) | 73 | Index::setDatabase(Database* database) |
363 | 58 | { | 74 | { |
364 | @@ -80,6 +96,10 @@ | |||
365 | 80 | return m_name; | 96 | return m_name; |
366 | 81 | } | 97 | } |
367 | 82 | 98 | ||
368 | 99 | /*! | ||
369 | 100 | Sets the name used. Both an expression and a name must be specified | ||
370 | 101 | for an index to be created. | ||
371 | 102 | */ | ||
372 | 83 | void | 103 | void |
373 | 84 | Index::setName(const QString& name) | 104 | Index::setName(const QString& name) |
374 | 85 | { | 105 | { |
375 | @@ -102,6 +122,10 @@ | |||
376 | 102 | return m_expression; | 122 | return m_expression; |
377 | 103 | } | 123 | } |
378 | 104 | 124 | ||
379 | 125 | /*! | ||
380 | 126 | Sets the expression used. Both an expression and a name must be specified | ||
381 | 127 | for an index to be created. | ||
382 | 128 | */ | ||
383 | 105 | void | 129 | void |
384 | 106 | Index::setExpression(QStringList expression) | 130 | Index::setExpression(QStringList expression) |
385 | 107 | { | 131 | { |
386 | 108 | 132 | ||
387 | === modified file 'query.cpp' | |||
388 | --- query.cpp 2013-02-28 17:59:51 +0000 | |||
389 | +++ query.cpp 2013-04-03 10:16:22 +0000 | |||
390 | @@ -31,11 +31,27 @@ | |||
391 | 31 | 31 | ||
392 | 32 | QT_BEGIN_NAMESPACE_U1DB | 32 | QT_BEGIN_NAMESPACE_U1DB |
393 | 33 | 33 | ||
394 | 34 | /*! | ||
395 | 35 | \class Query | ||
396 | 36 | |||
397 | 37 | \brief The Query class generates a filtered list of documents based on either | ||
398 | 38 | a query or a range, and using the given Index. | ||
399 | 39 | |||
400 | 40 | This is the declarative API equivalent of FIXME | ||
401 | 41 | */ | ||
402 | 42 | |||
403 | 34 | Query::Query(QObject *parent) : | 43 | Query::Query(QObject *parent) : |
404 | 35 | QAbstractListModel(parent), m_index(0) | 44 | QAbstractListModel(parent), m_index(0) |
405 | 36 | { | 45 | { |
406 | 37 | } | 46 | } |
407 | 38 | 47 | ||
408 | 48 | /*! | ||
409 | 49 | Used to implement QAbstractListModel | ||
410 | 50 | Implements the variables exposed to the Delegate in a model | ||
411 | 51 | QVariant contents | ||
412 | 52 | QString docId | ||
413 | 53 | int index (built-in) | ||
414 | 54 | */ | ||
415 | 39 | QVariant | 55 | QVariant |
416 | 40 | Query::data(const QModelIndex & index, int role) const | 56 | Query::data(const QModelIndex & index, int role) const |
417 | 41 | { | 57 | { |
418 | @@ -44,13 +60,21 @@ | |||
419 | 44 | { | 60 | { |
420 | 45 | Database* db(m_index->getDatabase()); | 61 | Database* db(m_index->getDatabase()); |
421 | 46 | if (db) | 62 | if (db) |
422 | 63 | { | ||
423 | 64 | qDebug() << "Query::getData" << docId; | ||
424 | 47 | return db->getDocUnchecked(docId); | 65 | return db->getDocUnchecked(docId); |
425 | 66 | } | ||
426 | 48 | } | 67 | } |
427 | 49 | if (role == 1) // docId | 68 | if (role == 1) // docId |
428 | 50 | return docId; | 69 | return docId; |
429 | 51 | return QVariant(); | 70 | return QVariant(); |
430 | 52 | } | 71 | } |
431 | 53 | 72 | ||
432 | 73 | /*! | ||
433 | 74 | Used to implement QAbstractListModel | ||
434 | 75 | Defines \b{contents} and \b{docId} as variables exposed to the Delegate in a model | ||
435 | 76 | \b{index} is supported out of the box. | ||
436 | 77 | */ | ||
437 | 54 | QHash<int, QByteArray> | 78 | QHash<int, QByteArray> |
438 | 55 | Query::roleNames() const | 79 | Query::roleNames() const |
439 | 56 | { | 80 | { |
440 | @@ -60,6 +84,10 @@ | |||
441 | 60 | return roles; | 84 | return roles; |
442 | 61 | } | 85 | } |
443 | 62 | 86 | ||
444 | 87 | /*! | ||
445 | 88 | Used to implement QAbstractListModel | ||
446 | 89 | The number of rows: the number of documents given by the query. | ||
447 | 90 | */ | ||
448 | 63 | int | 91 | int |
449 | 64 | Query::rowCount(const QModelIndex & parent) const | 92 | Query::rowCount(const QModelIndex & parent) const |
450 | 65 | { | 93 | { |
451 | @@ -82,6 +110,10 @@ | |||
452 | 82 | // TODO | 110 | // TODO |
453 | 83 | } | 111 | } |
454 | 84 | 112 | ||
455 | 113 | /*! | ||
456 | 114 | Sets the Index to use. The index must have a valid name and index expressions, | ||
457 | 115 | then either a range or query can be set. | ||
458 | 116 | */ | ||
459 | 85 | void | 117 | void |
460 | 86 | Query::setIndex(Index* index) | 118 | Query::setIndex(Index* index) |
461 | 87 | { | 119 | { |
462 | @@ -103,6 +135,10 @@ | |||
463 | 103 | return m_query; | 135 | return m_query; |
464 | 104 | } | 136 | } |
465 | 105 | 137 | ||
466 | 138 | /*! | ||
467 | 139 | Sets a range, such as ['match', false]. | ||
468 | 140 | Only one of query and range is used - setting range unsets the query. | ||
469 | 141 | */ | ||
470 | 106 | void | 142 | void |
471 | 107 | Query::setQuery(QVariant query) | 143 | Query::setQuery(QVariant query) |
472 | 108 | { | 144 | { |
473 | @@ -123,6 +159,10 @@ | |||
474 | 123 | return m_range; | 159 | return m_range; |
475 | 124 | } | 160 | } |
476 | 125 | 161 | ||
477 | 162 | /*! | ||
478 | 163 | Sets a range, such as [['a', 'b'], ['*']]. | ||
479 | 164 | Only one of query and range is used - setting range unsets the query. | ||
480 | 165 | */ | ||
481 | 126 | void | 166 | void |
482 | 127 | Query::setRange(QVariant range) | 167 | Query::setRange(QVariant range) |
483 | 128 | { | 168 | { |
FAILED: Continuous integration, rev:66 /code.launchpad .net/~kalikiana /u1db-qt/ trunk/+ merge/156795/ +edit-commit- message
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http:// 91.189. 93.125: 8080/job/ u1db-qt- ci/6/ 91.189. 93.125: 8080/job/ u1db-qt- quantal- amd64-ci/ 6 91.189. 93.125: 8080/job/ u1db-qt- raring- amd64-ci/ 6
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.125: 8080/job/ u1db-qt- ci/6/rebuild
http://