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

Proposed by Cris Dywan
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
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 :

FAILED: Continuous integration, rev:66
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://code.launchpad.net/~kalikiana/u1db-qt/trunk/+merge/156795/+edit-commit-message

http://91.189.93.125:8080/job/u1db-qt-ci/6/
Executed test runs:
    SUCCESS: http://91.189.93.125:8080/job/u1db-qt-quantal-amd64-ci/6
    SUCCESS: http://91.189.93.125:8080/job/u1db-qt-raring-amd64-ci/6

Click here to trigger a rebuild:
http://91.189.93.125:8080/job/u1db-qt-ci/6/rebuild

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
=== modified file 'database.cpp'
--- database.cpp 2013-03-20 17:10:45 +0000
+++ database.cpp 2013-04-03 10:16:22 +0000
@@ -31,6 +31,19 @@
3131
32QT_BEGIN_NAMESPACE_U1DB32QT_BEGIN_NAMESPACE_U1DB
3333
34/*!
35 \class Database
36
37 \brief The Database class implements the on-disk storage of an individual
38 U1DB database.
39
40 The functional API can be used from C++ and Javascript, and is the basis of
41 the declarative API.
42*/
43
44/*!
45 A unique identifier for the state of synchronization
46 */
34QString47QString
35Database::getReplicaUid()48Database::getReplicaUid()
36{49{
@@ -40,6 +53,10 @@
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();
41}54}
4255
56/*!
57 Checks if the underlying SQLite database is ready to be used
58 Only to be used as a utility function by initializeIfNeeded()
59 */
43bool60bool
44Database::isInitialized()61Database::isInitialized()
45{62{
@@ -49,6 +66,9 @@
49 return query.next();66 return query.next();
50}67}
5168
69/*!
70 Describes the error as a string if the last operation failed.
71 */
52bool72bool
53Database::setError(const QString& error)73Database::setError(const QString& error)
54{74{
@@ -58,12 +78,22 @@
58 return false;78 return false;
59}79}
6080
81/*!
82 Describes the error as a string if the last operation failed.
83 */
61QString84QString
62Database::lastError()85Database::lastError()
63{86{
64 return m_error;87 return m_error;
65}88}
6689
90/*!
91 Ensures that the underlying database works, or tries to set it up:
92
93 The SQlite backend is loaded - it's an optional Qt5 module and can fail
94 If @path is an existing database, it'll be opened
95 For a new database, the default schema will be applied
96 */
67bool97bool
68Database::initializeIfNeeded(const QString& path)98Database::initializeIfNeeded(const QString& path)
69{99{
@@ -115,6 +145,11 @@
115 initializeIfNeeded();145 initializeIfNeeded();
116}146}
117147
148/*!
149 Used to implement QAbstractListModel
150 Returns docId matching the given row index
151 assuming all documents are ordered consistently
152 */
118QString153QString
119Database::getDocIdByRow(int row) const154Database::getDocIdByRow(int row) const
120{155{
@@ -129,6 +164,13 @@
129 return QString();164 return QString();
130}165}
131166
167/*!
168 Used to implement QAbstractListModel
169 Implements the variables exposed to the Delegate in a model
170 QVariant contents
171 QString docId
172 int index (built-in)
173 */
132QVariant174QVariant
133Database::data(const QModelIndex & index, int role) const175Database::data(const QModelIndex & index, int role) const
134{176{
@@ -140,6 +182,11 @@
140 return QVariant();182 return QVariant();
141}183}
142184
185/*!
186 Used to implement QAbstractListModel
187 Defines \b{contents} and \b{docId} as variables exposed to the Delegate in a model
188 \b{index} is supported out of the box.
189 */
143QHash<int, QByteArray>190QHash<int, QByteArray>
144Database::roleNames() const191Database::roleNames() const
145{192{
@@ -149,6 +196,10 @@
149 return roles;196 return roles;
150}197}
151198
199/*!
200 Used to implement QAbstractListModel
201 The number of rows: the number of documents in the database.
202 */
152int203int
153Database::rowCount(const QModelIndex & parent) const204Database::rowCount(const QModelIndex & parent) const
154{205{
@@ -162,6 +213,11 @@
162 return query.value("count").toInt();213 return query.value("count").toInt();
163}214}
164215
216/*!
217 Same functionality as getDoc() except it won't set lastError() and it
218 doesn't implicitly try to initialize the underlying database.
219 Use cases: model implementations, Document::getContents()
220 */
165QVariant221QVariant
166Database::getDocUnchecked(const QString& docId) const222Database::getDocUnchecked(const QString& docId) const
167{223{
@@ -173,6 +229,7 @@
173 query.bindValue(":docId", docId);229 query.bindValue(":docId", docId);
174 if (query.exec() && query.next())230 if (query.exec() && query.next())
175 {231 {
232 // Convert JSON string to the Variant that QML expects
176 QJsonDocument json(QJsonDocument::fromJson(query.value("content").toByteArray()));233 QJsonDocument json(QJsonDocument::fromJson(query.value("content").toByteArray()));
177 Q_EMIT docLoaded(docId, json.object().toVariantMap());234 Q_EMIT docLoaded(docId, json.object().toVariantMap());
178 return json.object().toVariantMap();235 return json.object().toVariantMap();
@@ -180,6 +237,11 @@
180 return QVariant();237 return QVariant();
181}238}
182239
240/*!
241 Returns the contents of a document by docId in a form that QML recognizes
242 as a Variant object, it's identical to Document::getContents() with the
243 same docId.
244 */
183QVariant245QVariant
184Database::getDoc(const QString& docId)246Database::getDoc(const QString& docId)
185{247{
@@ -199,6 +261,7 @@
199 {261 {
200 if (query.value("conflicts").toInt() > 0)262 if (query.value("conflicts").toInt() > 0)
201 setError(QString("Conflicts in %1").arg(docId));263 setError(QString("Conflicts in %1").arg(docId));
264 // Convert JSON string to the Variant that QML expects
202 QJsonDocument json(QJsonDocument::fromJson(query.value("content").toByteArray()));265 QJsonDocument json(QJsonDocument::fromJson(query.value("content").toByteArray()));
203 Q_EMIT docLoaded(docId, json.object().toVariantMap());266 Q_EMIT docLoaded(docId, json.object().toVariantMap());
204 return json.object().toVariantMap();267 return json.object().toVariantMap();
@@ -214,6 +277,13 @@
214 return oldRev;277 return oldRev;
215}278}
216279
280/*!
281 Updates the existing contents of the document identified by docId if
282 there's no error.
283 If no docId is given or docId is an empty string the contents will be
284 stored under an autogenerated name.
285 Returns the new revision of the document, or -1 on failure.
286 */
217int287int
218Database::putDoc(QVariant newDoc, const QString& newOrEmptyDocId)288Database::putDoc(QVariant newDoc, const QString& newOrEmptyDocId)
219{289{
@@ -231,6 +301,7 @@
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");
232 query.bindValue(":docId", docId);302 query.bindValue(":docId", docId);
233 query.bindValue(":docRev", newRev);303 query.bindValue(":docRev", newRev);
304 // Parse Variant from QML as JsonDocument, fallback to string
234 QString json(QJsonDocument::fromVariant(newDoc).toJson());305 QString json(QJsonDocument::fromVariant(newDoc).toJson());
235 query.bindValue(":docJson", json.isEmpty() ? newDoc : json);306 query.bindValue(":docJson", json.isEmpty() ? newDoc : json);
236 if (!query.exec())307 if (!query.exec())
@@ -250,6 +321,7 @@
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)");
251 query.bindValue(":docId", docId);322 query.bindValue(":docId", docId);
252 query.bindValue(":docRev", newRev);323 query.bindValue(":docRev", newRev);
324 // Parse Variant from QML as JsonDocument, fallback to string
253 QJsonDocument json(QJsonDocument::fromVariant(newDoc));325 QJsonDocument json(QJsonDocument::fromVariant(newDoc));
254 query.bindValue(":docJson", json.isEmpty() ? newDoc : json.toJson());326 query.bindValue(":docJson", json.isEmpty() ? newDoc : json.toJson());
255 if (!query.exec())327 if (!query.exec())
@@ -290,6 +362,13 @@
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;
291}363}
292364
365/*!
366 A relative filename or absolute path advises the database to store documents
367 and indexes persistently on disk. Internally, an SQlite database is written.
368
369 If no path is set, as is the default, all database contents are written in
370 memory only. The same affect can be achieved by passing the string ":memory:".
371 */
293void372void
294Database::setPath(const QString& path)373Database::setPath(const QString& path)
295{374{
@@ -306,12 +385,20 @@
306 Q_EMIT pathChanged(path);385 Q_EMIT pathChanged(path);
307}386}
308387
388/*!
389 The persistent storage location if set. By default the database is only
390 storted in memory. See setPath().
391 */
309QString392QString
310Database::getPath()393Database::getPath()
311{394{
312 return m_path;395 return m_path;
313}396}
314397
398/*!
399 Stores a new index under the given name. An existing index won't be
400 replaced implicitly, an error will be set in that case.
401 */
315QString402QString
316Database::putIndex(const QString& indexName, QStringList expressions)403Database::putIndex(const QString& indexName, QStringList expressions)
317{404{
@@ -346,6 +433,9 @@
346 return QString();433 return QString();
347}434}
348435
436/*!
437 Gets the expressions saved with putIndex().
438 */
349QStringList439QStringList
350Database::getIndexExpressions(const QString& indexName)440Database::getIndexExpressions(const QString& indexName)
351{441{
@@ -365,6 +455,9 @@
365 return expressions;455 return expressions;
366}456}
367457
458/*!
459 Lists the index keys of an index created with putIndex().
460 */
368QStringList461QStringList
369Database::getIndexKeys(const QString& indexName)462Database::getIndexKeys(const QString& indexName)
370{463{
371464
=== modified file 'document.cpp'
--- document.cpp 2013-03-06 12:06:56 +0000
+++ document.cpp 2013-04-03 10:16:22 +0000
@@ -30,6 +30,15 @@
3030
31QT_BEGIN_NAMESPACE_U1DB31QT_BEGIN_NAMESPACE_U1DB
3232
33/*!
34 \class Document
35
36 \brief The Document class proxies a single document stored in the Database.
37
38 This is the declarative API equivalent of Database::putDoc() and
39 Database::getDoc().
40*/
41
33Document::Document(QObject *parent) :42Document::Document(QObject *parent) :
34 QObject(parent), m_database(0), m_create(false)43 QObject(parent), m_database(0), m_create(false)
35{44{
@@ -61,6 +70,10 @@
61 }70 }
62}71}
6372
73/*!
74 The database is used to lookup the contents of the document, reflecting
75 changes done to it and conversely changes are saved to the database.
76 */
64void77void
65Document::setDatabase(Database* database)78Document::setDatabase(Database* database)
66{79{
@@ -90,6 +103,11 @@
90 return m_docId;103 return m_docId;
91}104}
92105
106/*!
107 The docId can be that of an existing document in the database and
108 will determine what getContents() returns.
109 If no such documents exists, setDefaults() can be used to supply a preset.
110 */
93void111void
94Document::setDocId(const QString& docId)112Document::setDocId(const QString& docId)
95{113{
@@ -112,6 +130,10 @@
112 return m_create;130 return m_create;
113}131}
114132
133/*!
134 If create is true, docId is not empty and no document with the same docId
135 exists, defaults will be used to store the document.
136 */
115void137void
116Document::setCreate(bool create)138Document::setCreate(bool create)
117{139{
@@ -131,6 +153,12 @@
131 return m_defaults;153 return m_defaults;
132}154}
133155
156/*!
157 The default contents of the document, which are used only if
158 create is true, docId is not empty and no document with the same
159 docId exists in the database yet.
160 If the defaults change, it's up to the API user to handle it.
161 */
134void162void
135Document::setDefaults(QVariant defaults)163Document::setDefaults(QVariant defaults)
136{164{
@@ -144,12 +172,20 @@
144 m_database->putDoc(m_defaults, m_docId);172 m_database->putDoc(m_defaults, m_docId);
145}173}
146174
175/*!
176 The contents of the document, as set via setContents() or stored in
177 the database via Database::putDoc().
178 onContentsChanged() can be used to monitor changes.
179 */
147QVariant180QVariant
148Document::getContents()181Document::getContents()
149{182{
150 return m_contents;183 return m_contents;
151}184}
152185
186/*!
187 Updates the contents of the document. A valid docId must be set.
188 */
153void189void
154Document::setContents(QVariant contents)190Document::setContents(QVariant contents)
155{191{
156192
=== modified file 'index.cpp'
--- index.cpp 2013-02-28 17:59:51 +0000
+++ index.cpp 2013-04-03 10:16:22 +0000
@@ -30,6 +30,17 @@
3030
31QT_BEGIN_NAMESPACE_U1DB31QT_BEGIN_NAMESPACE_U1DB
3232
33/*!
34 \class Index
35
36 \brief The Index class defines an index to be stored in the database and
37 queried using Query. Changes in documents affected by the index also update
38 the index in the database.
39
40 This is the declarative API equivalent of Database::putIndex() and
41 Database::getIndexExpressions().
42*/
43
33Index::Index(QObject *parent) :44Index::Index(QObject *parent) :
34 QObject(parent), m_database(0)45 QObject(parent), m_database(0)
35{46{
@@ -53,6 +64,11 @@
53 Q_EMIT dataInvalidated();64 Q_EMIT dataInvalidated();
54}65}
5566
67/*!
68 Sets the Database to lookup documents from and store the index in. The
69 dataInvalidated() signal will be emitted on all changes that could affect
70 the index.
71 */
56void72void
57Index::setDatabase(Database* database)73Index::setDatabase(Database* database)
58{74{
@@ -80,6 +96,10 @@
80 return m_name;96 return m_name;
81}97}
8298
99/*!
100 Sets the name used. Both an expression and a name must be specified
101 for an index to be created.
102 */
83void103void
84Index::setName(const QString& name)104Index::setName(const QString& name)
85{105{
@@ -102,6 +122,10 @@
102 return m_expression;122 return m_expression;
103}123}
104124
125/*!
126 Sets the expression used. Both an expression and a name must be specified
127 for an index to be created.
128 */
105void129void
106Index::setExpression(QStringList expression)130Index::setExpression(QStringList expression)
107{131{
108132
=== modified file 'query.cpp'
--- query.cpp 2013-02-28 17:59:51 +0000
+++ query.cpp 2013-04-03 10:16:22 +0000
@@ -31,11 +31,27 @@
3131
32QT_BEGIN_NAMESPACE_U1DB32QT_BEGIN_NAMESPACE_U1DB
3333
34/*!
35 \class Query
36
37 \brief The Query class generates a filtered list of documents based on either
38 a query or a range, and using the given Index.
39
40 This is the declarative API equivalent of FIXME
41*/
42
34Query::Query(QObject *parent) :43Query::Query(QObject *parent) :
35 QAbstractListModel(parent), m_index(0)44 QAbstractListModel(parent), m_index(0)
36{45{
37}46}
3847
48/*!
49 Used to implement QAbstractListModel
50 Implements the variables exposed to the Delegate in a model
51 QVariant contents
52 QString docId
53 int index (built-in)
54 */
39QVariant55QVariant
40Query::data(const QModelIndex & index, int role) const56Query::data(const QModelIndex & index, int role) const
41{57{
@@ -44,13 +60,21 @@
44 {60 {
45 Database* db(m_index->getDatabase());61 Database* db(m_index->getDatabase());
46 if (db)62 if (db)
63 {
64 qDebug() << "Query::getData" << docId;
47 return db->getDocUnchecked(docId);65 return db->getDocUnchecked(docId);
66 }
48 }67 }
49 if (role == 1) // docId68 if (role == 1) // docId
50 return docId;69 return docId;
51 return QVariant();70 return QVariant();
52}71}
5372
73/*!
74 Used to implement QAbstractListModel
75 Defines \b{contents} and \b{docId} as variables exposed to the Delegate in a model
76 \b{index} is supported out of the box.
77 */
54QHash<int, QByteArray>78QHash<int, QByteArray>
55Query::roleNames() const79Query::roleNames() const
56{80{
@@ -60,6 +84,10 @@
60 return roles;84 return roles;
61}85}
6286
87/*!
88 Used to implement QAbstractListModel
89 The number of rows: the number of documents given by the query.
90 */
63int91int
64Query::rowCount(const QModelIndex & parent) const92Query::rowCount(const QModelIndex & parent) const
65{93{
@@ -82,6 +110,10 @@
82 // TODO110 // TODO
83}111}
84112
113/*!
114 Sets the Index to use. The index must have a valid name and index expressions,
115 then either a range or query can be set.
116 */
85void117void
86Query::setIndex(Index* index)118Query::setIndex(Index* index)
87{119{
@@ -103,6 +135,10 @@
103 return m_query;135 return m_query;
104}136}
105137
138/*!
139 Sets a range, such as ['match', false].
140 Only one of query and range is used - setting range unsets the query.
141 */
106void142void
107Query::setQuery(QVariant query)143Query::setQuery(QVariant query)
108{144{
@@ -123,6 +159,10 @@
123 return m_range;159 return m_range;
124}160}
125161
162/*!
163 Sets a range, such as [['a', 'b'], ['*']].
164 Only one of query and range is used - setting range unsets the query.
165 */
126void166void
127Query::setRange(QVariant range)167Query::setRange(QVariant range)
128{168{

Subscribers

People subscribed via source and target branches

to all changes: