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

Proposed by Cris Dywan
Status: Merged
Approved by: Cris Dywan
Approved revision: 118
Merged at revision: 124
Proposed branch: lp:~kalikiana/u1db-qt/qmlDocs
Merge into: lp:u1db-qt
Diff against target: 1204 lines (+367/-149)
11 files modified
documentation/u1db.qdocconf (+1/-6)
src/database.cpp (+66/-15)
src/database.h (+10/-0)
src/document.cpp (+68/-21)
src/document.h (+20/-1)
src/index.cpp (+49/-18)
src/index.h (+12/-1)
src/query.cpp (+54/-14)
src/query.h (+16/-0)
src/synchronizer.cpp (+66/-70)
src/synchronizer.h (+5/-3)
To merge this branch: bzr merge lp:~kalikiana/u1db-qt/qmlDocs
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Marco Trevisan (Treviño) Approve
Review via email: mp+208818@code.launchpad.net

Commit message

Port qdoc syntax to QML annotations

Description of the change

This gets us QML docs, including a few tweaks to ensure each has one example at the top, using highlighting and identifier linking. Behind each component a link is available to reveal the C++ version.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Looks good... Added two small comments, just to stay in sync with the recent approved changes...

review: Approve
lp:~kalikiana/u1db-qt/qmlDocs updated
118. By Cris Dywan

Clarify path behavior documentation

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'documentation/u1db.qdocconf'
--- documentation/u1db.qdocconf 2013-09-06 10:00:36 +0000
+++ documentation/u1db.qdocconf 2015-03-24 19:42:30 +0000
@@ -5,12 +5,7 @@
55
6sourcedirs = ../src \6sourcedirs = ../src \
7 ../documentation7 ../documentation
8headers = ../src/database.h \8headerdirs = ../src/
9 ../src/document.h \
10 ../src/index.h \
11 ../src/query.h \
12 ../src/synchronizer.h \
13 ../src/global.h
14Cpp.ignoretokens = Q_DECL_EXPORT \9Cpp.ignoretokens = Q_DECL_EXPORT \
15 Q_PROPERTY \10 Q_PROPERTY \
16 QT_BEGIN_NAMESPACE_U1DB \11 QT_BEGIN_NAMESPACE_U1DB \
1712
=== modified file 'src/database.cpp'
--- src/database.cpp 2015-02-19 10:37:54 +0000
+++ src/database.cpp 2015-03-24 19:42:30 +0000
@@ -17,7 +17,6 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */18 */
1919
20#include <QDebug>
21#include <QSqlQuery>20#include <QSqlQuery>
22#include <QFile>21#include <QFile>
23#include <QFileInfo>22#include <QFileInfo>
@@ -63,16 +62,41 @@
63/*!62/*!
64 \class Database63 \class Database
65 \inmodule U1Db64 \inmodule U1Db
66 \ingroup modules65 \ingroup cpp
6766
68 \brief The Database class implements the on-disk storage of an individual67 \brief The Database class implements on-disk storage for documents and indexes.
69 U1DB database.
7068
71 Database can be used as a QAbstractListModel, delegates will then have access to \a docId and \a contents69 Database can be used as a QAbstractListModel, delegates will then have access to \a docId and \a contents
72 analogous to the properties of Document.70 analogous to the properties of Document.
73*/71*/
7472
75/*!73/*!
74 \qmltype Database
75 \instantiates Database
76 \inqmlmodule U1Db 1.0
77 \ingroup modules
78
79 \brief Database implements on-disk storage for documents and indexes.
80
81 In a ListView the Database can be used as a model which includes all documents
82 in the database. For listing only a subset of documents Query can be used.
83
84 \qml
85 ListView {
86 model: Database {
87 id: myDatabase
88 }
89 delegate: ListItem.Subtitled {
90 text: docId
91 subText: contents.color
92 }
93 }
94 \endqml
95
96 \sa Query
97*/
98
99/*!
76 A unique identifier for the state of synchronization100 A unique identifier for the state of synchronization
77 */101 */
78QString102QString
@@ -110,7 +134,10 @@
110}134}
111135
112/*!136/*!
113 \property Database::error137 \qmlproperty string Database::error
138 The last error as a string if the last operation failed.
139 */
140/*!
114 The last error as a string if the last operation failed.141 The last error as a string if the last operation failed.
115 */142 */
116QString143QString
@@ -335,10 +362,16 @@
335362
336363
337/*!364/*!
365 \qmlmethod Variant Database::getDoc(string)
338 Returns the contents of a document by \a docId in a form that QML recognizes366 Returns the contents of a document by \a docId in a form that QML recognizes
339 as a Variant object, it's identical to Document::getContents() with the367 as a Variant object, it's identical to Document::getContents() with the
340 same \a docId.368 same \a docId.
341 */369 */
370/*!
371 * Returns the contents of a document by \a docId in a form that QML recognizes
372 * as a Variant object, it's identical to Document::getContents() with the
373 * same \a docId.
374 */
342QVariant375QVariant
343Database::getDoc(const QString& docId)376Database::getDoc(const QString& docId)
344{377{
@@ -513,7 +546,6 @@
513546
514/*!547/*!
515 * \internal548 * \internal
516 * \brief Database::updateDocRevisionNumber
517 *549 *
518 * Whenever a document as added or modified it needs a new revision number.550 * Whenever a document as added or modified it needs a new revision number.
519 *551 *
@@ -614,6 +646,14 @@
614}646}
615647
616/*!648/*!
649 \qmlmethod string Database::putDoc(var, string)
650 Updates the existing \a contents of the document identified by \a docId if
651 there's no error.
652 If no \a docId is given or \a docId is an empty string the \a contents will be
653 stored under an autogenerated name.
654 Returns the new revision of the document, or -1 on failure.
655 */
656/*!
617 Updates the existing \a contents of the document identified by \a docId if657 Updates the existing \a contents of the document identified by \a docId if
618 there's no error.658 there's no error.
619 If no \a docId is given or \a docId is an empty string the \a contents will be659 If no \a docId is given or \a docId is an empty string the \a contents will be
@@ -687,6 +727,10 @@
687}727}
688728
689/*!729/*!
730 \qmlmethod void Database::deleteDoc(string)
731 Deletes the document identified by \a docId.
732 */
733/*!
690 Deletes the document identified by \a docId.734 Deletes the document identified by \a docId.
691 */735 */
692void736void
@@ -710,6 +754,10 @@
710754
711755
712/*!756/*!
757 \qmlmethod list<string> Database::listDocs()
758 Returns a list of all stored documents by their docId.
759 */
760/*!
713 Returns a list of all stored documents by their docId.761 Returns a list of all stored documents by their docId.
714 */762 */
715QList<QString>763QList<QString>
@@ -737,11 +785,17 @@
737}785}
738786
739/*!787/*!
740 \property Database::path788 \qmlproperty string Database::path
741 A relative filename can be given to store the database in an app-specific789 A relative \a path can be given to store the database in an app-specific
742 writable folder. This is recommended as it ensures to work with confinement.790 writable folder. This is recommended as it ensures to work with confinement.
743 If more control is needed absolute paths can be used.791 If more control is needed absolute paths or local file URIs can be used.
744 By default everything is stored in memory.792 By default or if the path is empty everything is stored in memory.
793 */
794/*!
795 A relative \a path can be given to store the database in an app-specific
796 writable folder. This is recommended as it ensures to work with confinement.
797 If more control is needed absolute paths or local file URIs can be used.
798 By default or if the path is empty everything is stored in memory.
745 */799 */
746void800void
747Database::setPath(const QString& path)801Database::setPath(const QString& path)
@@ -759,10 +813,7 @@
759}813}
760814
761/*!815/*!
762 * \brief Database::getPath816 * Returns the path of the database.
763 *
764 * Simply returns the path of the database.
765 *
766 */817 */
767QString818QString
768Database::getPath()819Database::getPath()
769820
=== modified file 'src/database.h'
--- src/database.h 2014-01-24 11:13:35 +0000
+++ src/database.h 2015-03-24 19:42:30 +0000
@@ -31,7 +31,9 @@
3131
32class Q_DECL_EXPORT Database : public QAbstractListModel {32class Q_DECL_EXPORT Database : public QAbstractListModel {
33 Q_OBJECT33 Q_OBJECT
34 /*! path */
34 Q_PROPERTY(QString path READ getPath WRITE setPath NOTIFY pathChanged)35 Q_PROPERTY(QString path READ getPath WRITE setPath NOTIFY pathChanged)
36 /*! error */
35 Q_PROPERTY(QString error READ lastError NOTIFY errorChanged)37 Q_PROPERTY(QString error READ lastError NOTIFY errorChanged)
36public:38public:
37 Database(QObject* parent = 0);39 Database(QObject* parent = 0);
@@ -65,7 +67,15 @@
65 QMap<QString,QVariant> getSyncLogInfo(QMap<QString,QVariant> lastSyncInformation, QString uid, QString prefix);67 QMap<QString,QVariant> getSyncLogInfo(QMap<QString,QVariant> lastSyncInformation, QString uid, QString prefix);
6668
67Q_SIGNALS:69Q_SIGNALS:
70 /*!
71 \signal Database::pathChanged
72 The database path changed - the empty string means it's in-memory only.
73 */
68 void pathChanged(const QString& path);74 void pathChanged(const QString& path);
75 /*!
76 \signal Database::errorChanged
77 An error occurred. Use lastError() to check it.
78 */
69 void errorChanged(const QString& error);79 void errorChanged(const QString& error);
70 /*!80 /*!
71 A document's contents were modified.81 A document's contents were modified.
7282
=== modified file 'src/document.cpp'
--- src/document.cpp 2015-02-19 10:37:54 +0000
+++ src/document.cpp 2015-03-24 19:42:30 +0000
@@ -17,14 +17,6 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */18 */
1919
20#include <QDebug>
21#include <QSqlQuery>
22#include <QFile>
23#include <QSqlError>
24#include <QUuid>
25#include <QStringList>
26#include <QJsonDocument>
27
28#include "document.h"20#include "document.h"
29#include "private.h"21#include "private.h"
3022
@@ -33,12 +25,34 @@
33/*!25/*!
34 \class Document26 \class Document
35 \inmodule U1db27 \inmodule U1db
28 \ingroup cpp
29
30 \brief The Document class proxies a single document stored in the Database.
31*/
32
33
34/*!
35 \qmltype Document
36 \instantiates Document
37 \inqmlmodule U1db 1.0
36 \ingroup modules38 \ingroup modules
3739
38 \brief The Document class proxies a single document stored in the Database.40 \brief Document proxies a single document stored in the Database.
3941
40 This is the declarative API equivalent of Database::putDoc() and42 This is the declarative API equivalent of Database::putDoc() and
41 Database::getDoc().43 Database::getDoc().
44
45 \qml
46 Document {
47 docId: 'myId'
48 defaults: {
49 color: 'blue'
50 }
51 create: true
52 }
53 \endqml
54
55 \sa Database
42*/56*/
4357
44/*!58/*!
@@ -50,6 +64,9 @@
50{64{
51}65}
5266
67/*!
68 Returns the \l Database.
69 */
53Database*70Database*
54Document::getDatabase()71Document::getDatabase()
55{72{
@@ -77,8 +94,7 @@
77}94}
7895
79/*!96/*!
80 \property Document::database97 The \a database is used to lookup the contents of the document, reflecting
81 The database is used to lookup the contents of the document, reflecting
82 changes done to it and conversely changes are saved to the database.98 changes done to it and conversely changes are saved to the database.
83 */99 */
84void100void
@@ -104,6 +120,9 @@
104 Q_EMIT databaseChanged(database);120 Q_EMIT databaseChanged(database);
105}121}
106122
123/*!
124 Returns the docId.
125 */
107QString126QString
108Document::getDocId()127Document::getDocId()
109{128{
@@ -111,11 +130,16 @@
111}130}
112131
113/*!132/*!
114 \property Document::docId133 \qmlproperty string Document::docId
115 The docId can be that of an existing document in the database and134 The docId can be that of an existing document in the database and
116 will determine what getContents() returns.135 will determine what getContents() returns.
117 If no such documents exists, setDefaults() can be used to supply a preset.136 If no such documents exists, setDefaults() can be used to supply a preset.
118 */137 */
138/*!
139 The \a docId can be that of an existing document in the database and
140 will determine what getContents() returns.
141 If no such documents exists, setDefaults() can be used to supply a preset.
142 */
119void143void
120Document::setDocId(const QString& docId)144Document::setDocId(const QString& docId)
121{145{
@@ -132,6 +156,9 @@
132 }156 }
133}157}
134158
159/*!
160 Returns whether the document will be newly created if it doesn't exist.
161 */
135bool162bool
136Document::getCreate()163Document::getCreate()
137{164{
@@ -139,8 +166,12 @@
139}166}
140167
141/*!168/*!
142 \property Document::create169 \qmlproperty bool Document::create
143 If create is true, docId is not empty and no document with the same docId170 If \a create is true, docId is not empty and no document with the same docId
171 exists, defaults will be used to store the document.
172 */
173/*!
174 If \a create is true, docId is not empty and no document with the same docId
144 exists, defaults will be used to store the document.175 exists, defaults will be used to store the document.
145 */176 */
146void177void
@@ -156,6 +187,10 @@
156 m_database->putDoc(m_defaults, m_docId);187 m_database->putDoc(m_defaults, m_docId);
157}188}
158189
190/*!
191 Returns the defaults to be used when the document is newly created
192 because it doesn't exist, if create is true.
193 */
159QVariant194QVariant
160Document::getDefaults()195Document::getDefaults()
161{196{
@@ -163,11 +198,17 @@
163}198}
164199
165/*!200/*!
166 \property Document::defaults201 \qmlproperty Variant Document::content
167 The default contents of the document, which are used only if202 The default contents of the document, which are used only if
168 create is true, docId is not empty and no document with the same203 create is true, docId is not empty and no document with the same
169 docId exists in the database yet.204 docId exists in the database yet.
170 If the defaults change, it's up to the API user to handle it.205 If the \a defaults change, it's up to the API user to handle it.
206 */
207/*!
208 The default contents of the document, which are used only if
209 create is true, docId is not empty and no document with the same
210 docId exists in the database yet.
211 If the \a defaults change, it's up to the API user to handle it.
171 */212 */
172void213void
173Document::setDefaults(QVariant defaults)214Document::setDefaults(QVariant defaults)
@@ -185,6 +226,9 @@
185 m_database->putDoc(m_defaults, m_docId);226 m_database->putDoc(m_defaults, m_docId);
186}227}
187228
229/*!
230 Returns the current contents of the document.
231 */
188QVariant232QVariant
189Document::getContents()233Document::getContents()
190{234{
@@ -192,8 +236,11 @@
192}236}
193237
194/*!238/*!
195 \property Document::contents239 \qmlproperty Variant Document::contents
196 Updates the contents of the document. A valid docId must be set.240 Updates the \a contents of the document. A valid docId must be set.
241 */
242/*!
243 Updates the \a contents of the document. A valid docId must be set.
197 */244 */
198void245void
199Document::setContents(QVariant contents)246Document::setContents(QVariant contents)
200247
=== modified file 'src/document.h'
--- src/document.h 2013-04-23 15:17:24 +0000
+++ src/document.h 2015-03-24 19:42:30 +0000
@@ -21,7 +21,6 @@
21#define U1DB_DOCUMENT_H21#define U1DB_DOCUMENT_H
2222
23#include <QtCore/QObject>23#include <QtCore/QObject>
24#include <QSqlDatabase>
25#include <QVariant>24#include <QVariant>
2625
27#include "database.h"26#include "database.h"
@@ -31,13 +30,18 @@
31class Q_DECL_EXPORT Document : public QObject {30class Q_DECL_EXPORT Document : public QObject {
32 Q_OBJECT31 Q_OBJECT
33#ifdef Q_QDOC32#ifdef Q_QDOC
33 /*! database */
34 Q_PROPERTY(Database* database READ getDatabase WRITE setDatabase NOTIFY databaseChanged)34 Q_PROPERTY(Database* database READ getDatabase WRITE setDatabase NOTIFY databaseChanged)
35#else35#else
36 Q_PROPERTY(QT_PREPEND_NAMESPACE_U1DB(Database*) database READ getDatabase WRITE setDatabase NOTIFY databaseChanged)36 Q_PROPERTY(QT_PREPEND_NAMESPACE_U1DB(Database*) database READ getDatabase WRITE setDatabase NOTIFY databaseChanged)
37#endif37#endif
38 /*! docId */
38 Q_PROPERTY(QString docId READ getDocId WRITE setDocId NOTIFY docIdChanged)39 Q_PROPERTY(QString docId READ getDocId WRITE setDocId NOTIFY docIdChanged)
40 /*! create */
39 Q_PROPERTY(bool create READ getCreate WRITE setCreate NOTIFY createChanged)41 Q_PROPERTY(bool create READ getCreate WRITE setCreate NOTIFY createChanged)
42 /*! defaults */
40 Q_PROPERTY(QVariant defaults READ getDefaults WRITE setDefaults NOTIFY defaultsChanged)43 Q_PROPERTY(QVariant defaults READ getDefaults WRITE setDefaults NOTIFY defaultsChanged)
44 /*! contents */
41 Q_PROPERTY(QVariant contents READ getContents WRITE setContents NOTIFY contentsChanged)45 Q_PROPERTY(QVariant contents READ getContents WRITE setContents NOTIFY contentsChanged)
42public:46public:
43 Document(QObject* parent = 0);47 Document(QObject* parent = 0);
@@ -53,10 +57,25 @@
53 QVariant getContents();57 QVariant getContents();
54 void setContents(QVariant contents);58 void setContents(QVariant contents);
55Q_SIGNALS:59Q_SIGNALS:
60 /*!
61 The database changed.
62 */
56 void databaseChanged(Database* database);63 void databaseChanged(Database* database);
64 /*!
65 The docId changed.
66 */
57 void docIdChanged(const QString& docId);67 void docIdChanged(const QString& docId);
68 /*!
69 The create flag changed.
70 */
58 void createChanged(bool create);71 void createChanged(bool create);
72 /*!
73 The default contents changed.
74 */
59 void defaultsChanged(QVariant defaults);75 void defaultsChanged(QVariant defaults);
76 /*!
77 The current contents of the document changed.
78 */
60 void contentsChanged(QVariant contents);79 void contentsChanged(QVariant contents);
61private:80private:
62 Q_DISABLE_COPY(Document)81 Q_DISABLE_COPY(Document)
6382
=== modified file 'src/index.cpp'
--- src/index.cpp 2014-01-31 19:20:07 +0000
+++ src/index.cpp 2015-03-24 19:42:30 +0000
@@ -17,13 +17,7 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */18 */
1919
20#include <QDebug>
21#include <QSqlQuery>
22#include <QFile>
23#include <QSqlError>
24#include <QUuid>
25#include <QStringList>20#include <QStringList>
26#include <QJsonDocument>
2721
28#include "index.h"22#include "index.h"
29#include "private.h"23#include "private.h"
@@ -32,15 +26,33 @@
3226
33/*!27/*!
34 \class Index28 \class Index
35 \inmodule U1Db29 \inmodule U1db
36 \ingroup modules30 \ingroup cpp
3731
38 \brief The Index class defines an index to be stored in the database and32 \brief The Index class defines an index to be stored in the database and
39 queried using Query. Changes in documents affected by the index also update33 queried using Query. Changes in documents affected by the index also update
40 the index in the database.34 the index in the database.
4135*/
42 This is the declarative API equivalent of Database::putIndex() and36
43 Database::getIndexExpressions().37/*!
38 \qmltype Index
39 \instantiates Index
40 \inqmlmodule U1db 1.0
41 \ingroup modules
42
43 \brief An Index defines what fields can be filtered using Query.
44
45 Documents in the database will be included if they contain all fields in the expression.
46
47 \qml
48 Index {
49 database: myDatabase
50 name: 'colorIndex'
51 expression: [ 'color' ]
52 }
53 \endqml
54
55 \sa Query
44*/56*/
4557
46/*!58/*!
@@ -52,6 +64,9 @@
52{64{
53}65}
5466
67/*!
68 Returns the \l Database to lookup documents from and store the index in.
69 */
55Database*70Database*
56Index::getDatabase()71Index::getDatabase()
57{72{
@@ -71,11 +86,16 @@
71}86}
7287
73/*!88/*!
74 \property Index::database89 \qmlproperty Database Index::database
75 Sets the Database to lookup documents from and store the index in. The90 Sets the Database to lookup documents from and store the index in. The
76 dataInvalidated() signal will be emitted on all changes that could affect91 dataInvalidated() signal will be emitted on all changes that could affect
77 the index.92 the index.
78 */93 */
94/*!
95 Sets the \a database to lookup documents from and store the index in. The
96 dataInvalidated() signal will be emitted on all changes that could affect
97 the index.
98 */
79void99void
80Index::setDatabase(Database* database)100Index::setDatabase(Database* database)
81{101{
@@ -98,6 +118,9 @@
98118
99}119}
100120
121/*!
122 Returns the name of the index. Both name and expression must be specified.
123 */
101QString124QString
102Index::getName()125Index::getName()
103{126{
@@ -105,10 +128,14 @@
105}128}
106129
107/*!130/*!
108 \property Index::name131 \qmlproperty string Index::name
109 Sets the name used. Both an expression and a name must be specified132 Sets the name used. Both an expression and a name must be specified
110 for an index to be created.133 for an index to be created.
111 */134 */
135/*!
136 Sets the \a name used. Both an expression and a name must be specified
137 for an index to be created.
138 */
112void139void
113Index::setName(const QString& name)140Index::setName(const QString& name)
114{141{
@@ -125,6 +152,9 @@
125 Q_EMIT nameChanged(name);152 Q_EMIT nameChanged(name);
126}153}
127154
155/*!
156 Returns the expression of the index. Both name and expression must be specified.
157 */
128QStringList158QStringList
129Index::getExpression()159Index::getExpression()
130{160{
@@ -132,12 +162,17 @@
132}162}
133163
134/*!164/*!
135 \property Index::expression165 \qmlproperty list<string> Index::expression
136 Sets the expression used. Both an expression and a name must be specified166 Sets the expression used. Both an expression and a name must be specified
137 for an index to be created.167 for an index to be created.
138168
139 Also starts the process of creating the Index result list, which can then be queried or populate the Query model as is.169 Also starts the process of creating the Index result list, which can then be queried or populate the Query model as is.
170 */
171/*!
172 Sets the \a expression used. Both an expression and a name must be specified
173 for an index to be created.
140174
175 Also starts the process of creating the Index result list, which can then be queried or populate the Query model as is.
141 */176 */
142void177void
143Index::setExpression(QStringList expression)178Index::setExpression(QStringList expression)
@@ -189,7 +224,6 @@
189/*!224/*!
190 \internal225 \internal
191 */226 */
192
193QList<QVariantMap> Index::getAllResults(){227QList<QVariantMap> Index::getAllResults(){
194 generateIndexResults();228 generateIndexResults();
195 return m_results;229 return m_results;
@@ -205,7 +239,6 @@
205 */239 */
206QStringList Index::appendResultsFromMap(QString docId, QStringList fieldsList, QVariantMap current_section, QString current_field)240QStringList Index::appendResultsFromMap(QString docId, QStringList fieldsList, QVariantMap current_section, QString current_field)
207{241{
208
209 QMapIterator<QString, QVariant> i(current_section);242 QMapIterator<QString, QVariant> i(current_section);
210243
211 QString original_field = current_field;244 QString original_field = current_field;
@@ -259,8 +292,6 @@
259 *This recursive method is used in conjuntion with Index::appendResultsFromMap, to aid in iterating through a document when an embedded list is found.292 *This recursive method is used in conjuntion with Index::appendResultsFromMap, to aid in iterating through a document when an embedded list is found.
260 *293 *
261 */294 */
262
263
264QStringList Index::getFieldsFromList(QString docId, QStringList fieldsList, QVariantList current_section, QString current_field)295QStringList Index::getFieldsFromList(QString docId, QStringList fieldsList, QVariantList current_section, QString current_field)
265{296{
266297
267298
=== modified file 'src/index.h'
--- src/index.h 2013-04-25 13:38:33 +0000
+++ src/index.h 2015-03-24 19:42:30 +0000
@@ -21,7 +21,6 @@
21#define U1DB_INDEX_H21#define U1DB_INDEX_H
2222
23#include <QtCore/QObject>23#include <QtCore/QObject>
24#include <QSqlDatabase>
25#include <QStringList>24#include <QStringList>
2625
27#include "database.h"26#include "database.h"
@@ -31,11 +30,14 @@
31class Q_DECL_EXPORT Index : public QObject {30class Q_DECL_EXPORT Index : public QObject {
32 Q_OBJECT31 Q_OBJECT
33#ifdef Q_QDOC32#ifdef Q_QDOC
33 /*! database */
34 Q_PROPERTY(Database* database READ getDatabase WRITE setDatabase NOTIFY databaseChanged)34 Q_PROPERTY(Database* database READ getDatabase WRITE setDatabase NOTIFY databaseChanged)
35#else35#else
36 Q_PROPERTY(QT_PREPEND_NAMESPACE_U1DB(Database*) database READ getDatabase WRITE setDatabase NOTIFY databaseChanged)36 Q_PROPERTY(QT_PREPEND_NAMESPACE_U1DB(Database*) database READ getDatabase WRITE setDatabase NOTIFY databaseChanged)
37#endif37#endif
38 /*! name */
38 Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)39 Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
40 /*! expression */
39 Q_PROPERTY(QStringList expression READ getExpression WRITE setExpression NOTIFY expressionChanged)41 Q_PROPERTY(QStringList expression READ getExpression WRITE setExpression NOTIFY expressionChanged)
40public:42public:
41 Index(QObject* parent = 0);43 Index(QObject* parent = 0);
@@ -49,8 +51,17 @@
49 QList<QVariantMap> getAllResults();51 QList<QVariantMap> getAllResults();
5052
51Q_SIGNALS:53Q_SIGNALS:
54 /*!
55 The database changed.
56 */
52 void databaseChanged(Database* database);57 void databaseChanged(Database* database);
58 /*!
59 The index name changed.
60 */
53 void nameChanged(const QString& name);61 void nameChanged(const QString& name);
62 /*!
63 The index expression changed.
64 */
54 void expressionChanged(QVariant expression);65 void expressionChanged(QVariant expression);
55 /*!66 /*!
56 The database, an indexed document or the expressions changed.67 The database, an indexed document or the expressions changed.
5768
=== modified file 'src/query.cpp'
--- src/query.cpp 2014-03-13 19:31:58 +0000
+++ src/query.cpp 2015-03-24 19:42:30 +0000
@@ -17,13 +17,7 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */18 */
1919
20#include <QDebug>
21#include <QSqlQuery>
22#include <QFile>
23#include <QSqlError>
24#include <QUuid>
25#include <QStringList>20#include <QStringList>
26#include <QJsonDocument>
2721
28#include "query.h"22#include "query.h"
29#include "database.h"23#include "database.h"
@@ -34,12 +28,42 @@
34/*!28/*!
35 \class Query29 \class Query
36 \inmodule U1db30 \inmodule U1db
37 \ingroup modules31 \ingroup cpp
3832
39 \brief The Query class generates a filtered list of documents based on a query using the given Index.33 \brief The Query class generates a filtered list of documents based on a query using the given Index.
4034
41 Query can be used as a QAbstractListModel, delegates will then have access to \a docId and \a contents35 Query can be used as a QAbstractListModel, delegates will then have access to \a docId and \a contents
42 analogous to the properties of Document.36 analogous to the properties of Document.
37 */
38
39/*!
40 \qmltype Query
41 \instantiates Query
42 \inqmlmodule U1db 1.0
43 \ingroup modules
44
45 \brief Query filters documents based on the query and index.
46
47 In a ListView the Query can be used as a model.
48
49 \qml
50 ListView {
51 model: Query {
52 index: Index {
53 name: 'colorIndex'
54 expression: [ 'color' ]
55 database: myDatabase
56 }
57 query: [ 'blue' ]
58 }
59 delegate: ListItem.Subtitled {
60 text: docId
61 subText: contents.color
62 }
63 }
64 \endqml
65
66 \sa Index
43*/67*/
4468
45/*!69/*!
@@ -93,6 +117,9 @@
93 return m_results.count();117 return m_results.count();
94}118}
95119
120/*!
121 FIXME
122 */
96Index*123Index*
97Query::getIndex()124Query::getIndex()
98{125{
@@ -287,10 +314,13 @@
287}314}
288315
289/*!316/*!
290 \property Query::index317 \qmlproperty Index Query::index
291 Sets the Index to use. The index must have a valid name and index expressions.318 Sets the Index to use. \a index must have a valid name and index expressions.
292 If no query is set, the default is all results of the index.319 If no query is set, the default is all results of the index.
293 */320 */
321/*!
322 FIXME \a index
323 */
294void324void
295Query::setIndex(Index* index)325Query::setIndex(Index* index)
296{326{
@@ -305,11 +335,12 @@
305 }335 }
306 Q_EMIT indexChanged(index);336 Q_EMIT indexChanged(index);
307337
308
309 onDataInvalidated();338 onDataInvalidated();
310
311}339}
312340
341/*!
342 FIXME
343 */
313QVariant344QVariant
314Query::getQuery()345Query::getQuery()
315{346{
@@ -317,11 +348,14 @@
317}348}
318349
319/*!350/*!
320 \property Query::query351 \qmlproperty Variant Query::query
321 A query in one of the allowed forms:352 A query in one of the allowed forms:
322 'value', ['value'] or [{'sub-field': 'value'}].353 'value', ['value'] or [{'sub-field': 'value'}].
323 The default is equivalent to '*'.354 The default is equivalent to '*'.
324 */355 */
356/*!
357 FIXME \a query
358 */
325void359void
326Query::setQuery(QVariant query)360Query::setQuery(QVariant query)
327{361{
@@ -334,9 +368,12 @@
334}368}
335369
336/*!370/*!
337 \property Query::documents371 \qmlproperty list<string> Query::documents
338 The docId's of all matched documents.372 The docId's of all matched documents.
339 */373 */
374/*!
375 FIXME
376 */
340QStringList377QStringList
341Query::getDocuments()378Query::getDocuments()
342{379{
@@ -344,9 +381,12 @@
344}381}
345382
346/*!383/*!
347 \property Query::results384 \qmlproperty list<Variant> Query::results
348 The results of the query as a list.385 The results of the query as a list.
349 */386 */
387/*!
388 FIXME
389 */
350QList<QVariant>390QList<QVariant>
351Query::getResults()391Query::getResults()
352{392{
353393
=== modified file 'src/query.h'
--- src/query.h 2014-03-07 17:54:07 +0000
+++ src/query.h 2015-03-24 19:42:30 +0000
@@ -30,12 +30,16 @@
30class Q_DECL_EXPORT Query : public QAbstractListModel {30class Q_DECL_EXPORT Query : public QAbstractListModel {
31 Q_OBJECT31 Q_OBJECT
32#ifdef Q_QDOC32#ifdef Q_QDOC
33 /*! index */
33 Q_PROPERTY(Index* index READ getIndex WRITE setIndex NOTIFY indexChanged)34 Q_PROPERTY(Index* index READ getIndex WRITE setIndex NOTIFY indexChanged)
34#else35#else
35 Q_PROPERTY(QT_PREPEND_NAMESPACE_U1DB(Index*) index READ getIndex WRITE setIndex NOTIFY indexChanged)36 Q_PROPERTY(QT_PREPEND_NAMESPACE_U1DB(Index*) index READ getIndex WRITE setIndex NOTIFY indexChanged)
36#endif37#endif
38 /*! query */
37 Q_PROPERTY(QVariant query READ getQuery WRITE setQuery NOTIFY queryChanged)39 Q_PROPERTY(QVariant query READ getQuery WRITE setQuery NOTIFY queryChanged)
40 /*! documents */
38 Q_PROPERTY(QStringList documents READ getDocuments NOTIFY documentsChanged)41 Q_PROPERTY(QStringList documents READ getDocuments NOTIFY documentsChanged)
42 /*! results */
39 Q_PROPERTY(QList<QVariant> results READ getResults NOTIFY resultsChanged)43 Q_PROPERTY(QList<QVariant> results READ getResults NOTIFY resultsChanged)
40public:44public:
41 Query(QObject* parent = 0);45 Query(QObject* parent = 0);
@@ -55,9 +59,21 @@
55 void resetModel();59 void resetModel();
5660
57Q_SIGNALS:61Q_SIGNALS:
62 /*!
63 The associated index changed.
64 */
58 void indexChanged(Index* index);65 void indexChanged(Index* index);
66 /*!
67 The query changed.
68 */
59 void queryChanged(QVariant query);69 void queryChanged(QVariant query);
70 /*!
71 The documents matching the query changed.
72 */
60 void documentsChanged(QStringList documents);73 void documentsChanged(QStringList documents);
74 /*!
75 The results matching the query changed.
76 */
61 void resultsChanged(QList<QVariant> results);77 void resultsChanged(QList<QVariant> results);
62private:78private:
63 Q_DISABLE_COPY(Query)79 Q_DISABLE_COPY(Query)
6480
=== modified file 'src/synchronizer.cpp'
--- src/synchronizer.cpp 2013-11-25 13:22:07 +0000
+++ src/synchronizer.cpp 2015-03-24 19:42:30 +0000
@@ -17,7 +17,6 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */18 */
1919
20#include <QDebug>
21#include <QSqlQuery>20#include <QSqlQuery>
22#include <QFile>21#include <QFile>
23#include <QSqlError>22#include <QSqlError>
@@ -33,10 +32,34 @@
33/*!32/*!
34 \class Synchronizer33 \class Synchronizer
35 \inmodule U1Db34 \inmodule U1Db
35 \ingroup cpp
36
37 \brief The Synchronizer class handles synchronizing between two databases.
38 */
39
40/*!
41 \qmltype Synchronizer
42 \instantiates Synchronizer
43 \inqmlmodule U1db 1.0
36 \ingroup modules44 \ingroup modules
3745
38 \brief The Synchronizer class handles synchronizing between two databases.46 \brief Synchronizer handles synchronizing between two databases.
3947
48 \qml
49 Synchronizer {
50 id: mySync
51 synchronize: false
52 source: myDatabase
53 targets: [ {
54 remote: true,
55 ip: "127.0.0.1",
56 port: 7777,
57 name: "example1.u1db",
58 resolve_to_source: true
59 } ]
60
61 }
62 \endqml
40*/63*/
4164
42/*65/*
@@ -50,20 +73,6 @@
5073
51 Synchronizer elements sync two databases together, a 'source' database and a remote or local 'target' database.74 Synchronizer elements sync two databases together, a 'source' database and a remote or local 'target' database.
5275
53 Example use in a QML application:
54
55 U1db.Synchronizer{
56 id: aSynchronizer
57 synchronize: false
58 source: aDatabase
59 targets: [{remote:true,
60 ip:"127.0.0.1",
61 port: 7777,
62 name:"example1.u1db",
63 resolve_to_source:true}]
64
65 }
66
67 Short description of properties:76 Short description of properties:
6877
69 id: The element's identification.78 id: The element's identification.
@@ -152,12 +161,8 @@
152 return roles;161 return roles;
153}162}
154163
155
156/*!164/*!
157165 Sets the \a source database.
158
159 Sets the source database.
160
161 */166 */
162void Synchronizer::setSource(Database* source)167void Synchronizer::setSource(Database* source)
163{168{
@@ -173,15 +178,16 @@
173 Q_EMIT sourceChanged(source);178 Q_EMIT sourceChanged(source);
174}179}
175180
176
177/*!181/*!
178 * \property Synchronizer::targets182 * \qmlproperty Variant Synchronizer::targets
183 * \preliminary
179 *184 *
180 * Sets meta-data for databases to be used during a synchronization session.185 * Sets meta-data for databases to be used during a synchronization session.
181 *186 *
182 * The QVariant is a list that can contain definitions for more than one database187 * The QVariant is a list that can contain definitions for more than one database
183 * to be used as a target. For example:188 * to be used as a target. For example:
184 *189 *
190 * \code
185 * targets: [{remote:true},191 * targets: [{remote:true},
186 * {remote:true,192 * {remote:true,
187 * ip:"127.0.0.1",193 * ip:"127.0.0.1",
@@ -189,6 +195,7 @@
189 * name:"example1.u1db",195 * name:"example1.u1db",
190 * resolve_to_source:true},196 * resolve_to_source:true},
191 * {remote:"OK"}]197 * {remote:"OK"}]
198 * \endcode
192 *199 *
193 * The above example defines three databases. Two of the three definitions in the200 * The above example defines three databases. Two of the three definitions in the
194 * example are invalid, the first ({remote:true}) and the third ({remote:"OK"}),201 * example are invalid, the first ({remote:true}) and the third ({remote:"OK"}),
@@ -197,11 +204,13 @@
197 * The second definition is a fully defined and valid definition for a local to204 * The second definition is a fully defined and valid definition for a local to
198 * remote synchronization of two databases:205 * remote synchronization of two databases:
199 *206 *
207 * \code
200 * {remote:true,208 * {remote:true,
201 * ip:"127.0.0.1",209 * ip:"127.0.0.1",
202 * port: 7777,210 * port: 7777,
203 * name:"example1.u1db",211 * name:"example1.u1db",
204 * resolve_to_source:true}212 * resolve_to_source:true}
213 * \endcode
205 *214 *
206 * 'remote' determines whether the database is on disk or located on a server.215 * 'remote' determines whether the database is on disk or located on a server.
207 * 'ip' and 'port' for a server are used only when 'remote' is set to true216 * 'ip' and 'port' for a server are used only when 'remote' is set to true
@@ -209,9 +218,10 @@
209 * Note: If 'remote' is false this is the relative/absolute file location.218 * Note: If 'remote' is false this is the relative/absolute file location.
210 * 'resolve_to_source' determines whether to resolve conflicts automatically219 * 'resolve_to_source' determines whether to resolve conflicts automatically
211 * in favor of the source (aka local) database's values or the target's.220 * in favor of the source (aka local) database's values or the target's.
212 *221 */
213 */222/*!
214223 * FIXME \a targets
224 */
215void Synchronizer::setTargets(QVariant targets)225void Synchronizer::setTargets(QVariant targets)
216{226{
217227
@@ -226,9 +236,12 @@
226}236}
227237
228/*!238/*!
229 * \property Synchronizer::synchronize239 * \qmlproperty bool Synchronizer::synchronize
230 */240 * FIXME
231241 */
242/*!
243 * FIXME \a synchronize
244 */
232void Synchronizer::setSync(bool synchronize)245void Synchronizer::setSync(bool synchronize)
233{246{
234247
@@ -241,9 +254,15 @@
241254
242255
243/*!256/*!
244 * \property Synchronizer::resolve_to_source257 * \qmlproperty bool Synchronizer::resolve_to_source
245 */258 *
246259 * If true, conflicts during sync will be resolved in favor of the content
260 * from the source database.
261 */
262/*!
263 * If \a resolve_to_source is true, conflicts during sync will be resolved in favor
264 * of the content from the source database.
265 */
247void Synchronizer::setResolveToSource(bool resolve_to_source)266void Synchronizer::setResolveToSource(bool resolve_to_source)
248{267{
249 if (m_resolve_to_source == resolve_to_source)268 if (m_resolve_to_source == resolve_to_source)
@@ -255,8 +274,6 @@
255274
256275
257/*!276/*!
258 * \fn void Synchronizer::setSyncOutput(QList<QVariant> sync_output)
259 *
260 * Sets the current value for the active session's \a sync_output.277 * Sets the current value for the active session's \a sync_output.
261 *278 *
262 */279 */
@@ -271,11 +288,12 @@
271}288}
272289
273/*!290/*!
274 * \property Synchronizer::source291 * \qmlproperty Database Synchronizer::source
275 *292 *
276 *293 * Returns the source \l Database.
277 * Returns a source Database.294 */
278 *295/*!
296 Returns the source \l Database.
279 */297 */
280Database* Synchronizer::getSource()298Database* Synchronizer::getSource()
281{299{
@@ -283,54 +301,36 @@
283}301}
284302
285/*!303/*!
286 * \brief Synchronizer::getTargets
287 *
288 *
289 * Returns meta-data for all target databases.304 * Returns meta-data for all target databases.
290 *
291 */305 */
292
293QVariant Synchronizer::getTargets()306QVariant Synchronizer::getTargets()
294{307{
295 return m_targets;308 return m_targets;
296}309}
297310
298/*!311/*!
299 * \brief Synchronizer::getSync
300 *
301 *
302 * Returns the current value of synchronize. If true then the synchronize312 * Returns the current value of synchronize. If true then the synchronize
303 * session is initiated.313 * session is initiated.
304 *314 *
305 * This should probaby always be set to false on application start up.315 * This should probaby always be set to false on application start up.
306 * The application developer should use some trigger to switch it to true316 * The application developer should use some trigger to switch it to true
307 * when needed (e.g. button click).317 * when needed (e.g. button click).
308 *
309 */318 */
310
311bool Synchronizer::getSync()319bool Synchronizer::getSync()
312{320{
313 return m_synchronize;321 return m_synchronize;
314}322}
315323
316/*!324/*!
317 * \brief Synchronizer::getResolveToSource325 * Returns \b true if conflicts during sync will be resolved in favor of the content
318 *326 * from the source database.
319 *
320 * If set to true, any document conflicts created during a sync session
321 * will be resolved in favor of the content from the source database. If false
322 * the content from the target database will replace the document content in
323 * the source database.
324 *
325 */327 */
326
327bool Synchronizer::getResolveToSource(){328bool Synchronizer::getResolveToSource(){
328 return m_resolve_to_source;329 return m_resolve_to_source;
329}330}
330331
331/*!332/*!
332 * \property Synchronizer::sync_output333 * \qmlproperty list<Variant> Synchronizer::sync_output
333 * \brief Synchronizer::getSyncOutput
334 *334 *
335 * Returns the output from a sync session. The list should contain numerous335 * Returns the output from a sync session. The list should contain numerous
336 * QVariantMaps, each of which will have various meta-data with informative336 * QVariantMaps, each of which will have various meta-data with informative
@@ -343,19 +343,18 @@
343 * The information can be used in any number of ways, such as on screen within an app,343 * The information can be used in any number of ways, such as on screen within an app,
344 * testing, console output, logs and more. This is designed to be flexible enough that344 * testing, console output, logs and more. This is designed to be flexible enough that
345 * the app developer can decide themselves how to best use the data.345 * the app developer can decide themselves how to best use the data.
346 *346 */
347 */347/*!
348348 * FIXME
349 */
349QList<QVariant> Synchronizer::getSyncOutput(){350QList<QVariant> Synchronizer::getSyncOutput(){
350 return m_sync_output;351 return m_sync_output;
351}352}
352353
353/*354/*
354
355 Below this line represents the class' more unique functionality.355 Below this line represents the class' more unique functionality.
356 In other words, methods that do more than simply modify/retrieve356 In other words, methods that do more than simply modify/retrieve
357 an element's property values.357 an element's property values.
358
359*/358*/
360359
361360
@@ -363,7 +362,6 @@
363 * \brief Synchronizer::onSyncChanged362 * \brief Synchronizer::onSyncChanged
364 *363 *
365 * The synchroization process begins here.364 * The synchroization process begins here.
366 *
367 */365 */
368366
369void Synchronizer::onSyncChanged(bool synchronize){367void Synchronizer::onSyncChanged(bool synchronize){
@@ -446,12 +444,10 @@
446 * \internal444 * \internal
447 * \brief Synchronizer::getValidTargets445 * \brief Synchronizer::getValidTargets
448 *446 *
449 *
450 * This method confirms that each sync target definition is valid, based447 * This method confirms that each sync target definition is valid, based
451 * on predefined criteria contained in the validator and mandatory lists.448 * on predefined criteria contained in the validator and mandatory lists.
452 *449 *
453 */450 */
454
455QList<QVariant> Synchronizer::getValidTargets(QMap<QString,QString>validator, QList<QString>mandatory){451QList<QVariant> Synchronizer::getValidTargets(QMap<QString,QString>validator, QList<QString>mandatory){
456452
457 QList<QVariant> sync_targets;453 QList<QVariant> sync_targets;
@@ -1018,7 +1014,7 @@
1018 return dbUid;1014 return dbUid;
1019 }1015 }
1020 else{1016 else{
1021 qDebug() << query.lastError().text();1017 qWarning("u1db: %s", qPrintable(query.lastError().text()));
1022 db.close();1018 db.close();
1023 return dbUid;1019 return dbUid;
1024 }1020 }
10251021
=== modified file 'src/synchronizer.h'
--- src/synchronizer.h 2013-11-22 15:21:37 +0000
+++ src/synchronizer.h 2015-03-24 19:42:30 +0000
@@ -21,11 +21,8 @@
21#define U1DB_SYNCHRONIZER_H21#define U1DB_SYNCHRONIZER_H
2222
23#include <QtCore/QObject>23#include <QtCore/QObject>
24#include <QSqlDatabase>
25#include <QVariant>24#include <QVariant>
26#include <QMetaType>
27#include <QtNetwork>25#include <QtNetwork>
28#include <QNetworkAccessManager>
2926
3027
31#include "database.h"28#include "database.h"
@@ -37,13 +34,18 @@
37class Q_DECL_EXPORT Synchronizer : public QAbstractListModel {34class Q_DECL_EXPORT Synchronizer : public QAbstractListModel {
38 Q_OBJECT35 Q_OBJECT
39#ifdef Q_QDOC36#ifdef Q_QDOC
37 /*! source */
40 Q_PROPERTY(Database* source READ getSource WRITE setSource NOTIFY sourceChanged) 38 Q_PROPERTY(Database* source READ getSource WRITE setSource NOTIFY sourceChanged)
41#else39#else
42 Q_PROPERTY(QT_PREPEND_NAMESPACE_U1DB(Database*) source READ getSource WRITE setSource NOTIFY sourceChanged) 40 Q_PROPERTY(QT_PREPEND_NAMESPACE_U1DB(Database*) source READ getSource WRITE setSource NOTIFY sourceChanged)
43#endif41#endif
42 /*! synchronize */
44 Q_PROPERTY(bool synchronize READ getSync WRITE setSync NOTIFY syncChanged)43 Q_PROPERTY(bool synchronize READ getSync WRITE setSync NOTIFY syncChanged)
44 /*! resolve_to_source */
45 Q_PROPERTY(bool resolve_to_source READ getResolveToSource WRITE setResolveToSource NOTIFY resolveToSourceChanged)45 Q_PROPERTY(bool resolve_to_source READ getResolveToSource WRITE setResolveToSource NOTIFY resolveToSourceChanged)
46 /*! targets */
46 Q_PROPERTY(QVariant targets READ getTargets WRITE setTargets NOTIFY targetsChanged)47 Q_PROPERTY(QVariant targets READ getTargets WRITE setTargets NOTIFY targetsChanged)
48 /*! sync_output */
47 Q_PROPERTY(QList<QVariant> sync_output READ getSyncOutput NOTIFY syncOutputChanged)49 Q_PROPERTY(QList<QVariant> sync_output READ getSyncOutput NOTIFY syncOutputChanged)
4850
49public:51public:

Subscribers

People subscribed via source and target branches

to all changes: