Merge lp:~renatofilho/history-service/most-called into lp:history-service

Proposed by Renato Araujo Oliveira Filho
Status: Work in progress
Proposed branch: lp:~renatofilho/history-service/most-called
Merge into: lp:history-service
Prerequisite: lp:~boiko/history-service/fix_flags
Diff against target: 274 lines (+94/-10)
10 files modified
Ubuntu/History/historyeventmodel.cpp (+3/-1)
Ubuntu/History/historymodel.cpp (+2/-1)
Ubuntu/History/historymodel.h (+2/-1)
Ubuntu/History/historyqmlfilter.h (+4/-2)
plugins/sqlite/sqlitehistoryplugin.cpp (+6/-1)
src/filter.cpp (+44/-0)
src/filter.h (+3/-0)
src/intersectionfilter.h (+1/-1)
src/types.h (+3/-1)
tests/plugins/sqlite/SqliteEventViewTest.cpp (+26/-2)
To merge this branch: bzr merge lp:~renatofilho/history-service/most-called
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+259280@code.launchpad.net

This proposal supersedes a proposal from 2015-05-14.

To post a comment you must log in.

Unmerged revisions

198. By Renato Araujo Oliveira Filho

Merged 'lp:~boiko/history-service/fix_flags'

197. By Renato Araujo Oliveira Filho

Export new enuns into QML.

196. By Renato Araujo Oliveira Filho

Removed "startDate" and "endDate" from history model.

195. By Renato Araujo Oliveira Filho

Implemented support for date filter on historymodel.

Added property 'startDate' and 'endDate' on QML component 'HistoryModel'.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Ubuntu/History/historyeventmodel.cpp'
2--- Ubuntu/History/historyeventmodel.cpp 2015-02-05 19:35:28 +0000
3+++ Ubuntu/History/historyeventmodel.cpp 2015-05-15 19:19:21 +0000
4@@ -323,7 +323,9 @@
5 querySort = mSort->sort();
6 }
7
8- mView = History::Manager::instance()->queryEvents((History::EventType)mType, querySort, queryFilter);
9+ mView = History::Manager::instance()->queryEvents((History::EventType)mType,
10+ querySort,
11+ queryFilter);
12 connect(mView.data(),
13 SIGNAL(eventsAdded(History::Events)),
14 SLOT(onEventsAdded(History::Events)));
15
16=== modified file 'Ubuntu/History/historymodel.cpp'
17--- Ubuntu/History/historymodel.cpp 2015-04-01 20:05:39 +0000
18+++ Ubuntu/History/historymodel.cpp 2015-05-15 19:19:21 +0000
19@@ -28,6 +28,7 @@
20 #include "textevent.h"
21 #include "manager.h"
22 #include "utils_p.h"
23+#include "intersectionfilter.h"
24 #include <QTimerEvent>
25 #include <QCryptographicHash>
26 #include <QDebug>
27@@ -209,7 +210,7 @@
28 History::TextEvent historyEvent = History::TextEvent(accountId,
29 threadId,
30 QString(QCryptographicHash::hash(QByteArray(
31- QDateTime::currentDateTime().toString().toLatin1()),
32+ QDateTime::currentDateTime().toString().toLatin1()),
33 QCryptographicHash::Md5).toHex()),
34 "self",
35 QDateTime::currentDateTime(),
36
37=== modified file 'Ubuntu/History/historymodel.h'
38--- Ubuntu/History/historymodel.h 2015-04-01 20:05:39 +0000
39+++ Ubuntu/History/historymodel.h 2015-05-15 19:19:21 +0000
40@@ -28,6 +28,7 @@
41 #include <QAbstractListModel>
42 #include <QStringList>
43 #include <QQmlParserStatus>
44+#include <QDateTime>
45
46 class HistoryModel : public QAbstractListModel, public QQmlParserStatus
47 {
48@@ -83,7 +84,7 @@
49 AttachmentPending = History::AttachmentPending,
50 AttachmentError = History::AttachmentError
51 };
52-
53+
54 enum Role {
55 AccountIdRole = Qt::UserRole,
56 ThreadIdRole,
57
58=== modified file 'Ubuntu/History/historyqmlfilter.h'
59--- Ubuntu/History/historyqmlfilter.h 2013-09-17 21:04:09 +0000
60+++ Ubuntu/History/historyqmlfilter.h 2015-05-15 19:19:21 +0000
61@@ -39,7 +39,9 @@
62 MatchCaseSensitive = History::MatchCaseSensitive,
63 MatchCaseInsensitive = History::MatchCaseInsensitive,
64 MatchContains = History::MatchContains,
65- MatchPhoneNumber = History::MatchPhoneNumber
66+ MatchPhoneNumber = History::MatchPhoneNumber,
67+ MatchLessOrEqual = History::MatchLessOrEqual,
68+ MatchGreaterOrEqual = History::MatchGreaterOrEqual
69 };
70
71 explicit HistoryQmlFilter(QObject *parent = 0);
72@@ -60,7 +62,7 @@
73 void filterValueChanged();
74 void matchFlagsChanged();
75 void filterChanged();
76-
77+
78 protected:
79 History::Filter mFilter;
80 };
81
82=== modified file 'plugins/sqlite/sqlitehistoryplugin.cpp'
83--- plugins/sqlite/sqlitehistoryplugin.cpp 2015-01-28 23:15:24 +0000
84+++ plugins/sqlite/sqlitehistoryplugin.cpp 2015-05-15 19:19:21 +0000
85@@ -671,7 +671,6 @@
86 QString result;
87 History::Filters filters;
88 QString linking;
89- QString value;
90 int count;
91 QString filterProperty = filter.filterProperty();
92 QVariant filterValue = filter.filterValue();
93@@ -713,6 +712,12 @@
94 if (filter.matchFlags() & History::MatchContains) {
95 // FIXME: maybe we should use QString("%1 LIKE '\%'||%2'\%'").arg(bindId) ?? needs more time for investigating
96 result = QString("%1 LIKE '\%%2\%' ESCAPE '\\'").arg(propertyName, escapeFilterValue(filterValue.toString()));
97+ } else if (filter.matchFlags() & History::MatchGreaterOrEqual) {
98+ result = QString("%1>=%2").arg(propertyName, bindId);
99+ bindValues[bindId] = filterValue;
100+ } else if (filter.matchFlags() & History::MatchLessOrEqual) {
101+ result = QString("%1<=%2").arg(propertyName, bindId);
102+ bindValues[bindId] = filterValue;
103 } else {
104 result = QString("%1=%2").arg(propertyName, bindId);
105 bindValues[bindId] = filterValue;
106
107=== modified file 'src/filter.cpp'
108--- src/filter.cpp 2015-01-07 21:59:30 +0000
109+++ src/filter.cpp 2015-05-15 19:19:21 +0000
110@@ -228,4 +228,48 @@
111 return filter;
112 }
113
114+const Filter operator&(const Filter &left, const Filter &right)
115+{
116+ if (left.isValid() && right.isValid()) {
117+ IntersectionFilter intersection;
118+ if (left.type() == History::FilterTypeIntersection) {
119+ intersection = static_cast<IntersectionFilter>(left);
120+ intersection.append(right);
121+ } else if (right.type() == History::FilterTypeIntersection) {
122+ intersection = static_cast<IntersectionFilter>(right);
123+ intersection.append(left);
124+ } else {
125+ intersection.append(left);
126+ intersection.append(right);
127+ }
128+ return intersection;
129+ } else if (left.isValid()) {
130+ return left;
131+ } else {
132+ return right;
133+ }
134+}
135+
136+const Filter operator|(const Filter &left, const Filter &right)
137+{
138+ if (left.isValid() && right.isValid()) {
139+ UnionFilter unionFilter;
140+ if (left.type() == History::FilterTypeUnion) {
141+ unionFilter = static_cast<UnionFilter>(left);
142+ unionFilter.append(right);
143+ } else if (right.type() == History::FilterTypeUnion) {
144+ unionFilter = static_cast<UnionFilter>(right);
145+ unionFilter.append(left);
146+ } else {
147+ unionFilter.append(left);
148+ unionFilter.append(right);
149+ }
150+ return unionFilter;
151+ } else if (left.isValid()) {
152+ return left;
153+ } else {
154+ return right;
155+ }
156+}
157+
158 }
159
160=== modified file 'src/filter.h'
161--- src/filter.h 2013-10-23 19:35:23 +0000
162+++ src/filter.h 2015-05-15 19:19:21 +0000
163@@ -73,6 +73,9 @@
164
165 typedef QList<Filter> Filters;
166
167+const Filter operator&(const Filter& left, const Filter& right);
168+const Filter operator|(const Filter& left, const Filter& right);
169+
170 }
171
172 #endif
173
174=== modified file 'src/intersectionfilter.h'
175--- src/intersectionfilter.h 2013-10-23 19:35:23 +0000
176+++ src/intersectionfilter.h 2015-05-15 19:19:21 +0000
177@@ -45,7 +45,7 @@
178 void setFilters(const Filters &filters);
179 void prepend(const Filter &filter);
180 void append(const Filter &filter);
181- void clear();
182+ void clear();
183 Filters filters() const;
184
185 static Filter fromProperties(const QVariantMap &properties);
186
187=== modified file 'src/types.h'
188--- src/types.h 2015-05-15 19:19:21 +0000
189+++ src/types.h 2015-05-15 19:19:21 +0000
190@@ -51,7 +51,9 @@
191 MatchCaseSensitive = 0x01,
192 MatchCaseInsensitive = 0x02,
193 MatchContains = 0x04,
194- MatchPhoneNumber = 0x08
195+ MatchPhoneNumber = 0x08,
196+ MatchLessOrEqual = 0x10,
197+ MatchGreaterOrEqual = 0x20
198 };
199
200 Q_DECLARE_FLAGS(MatchFlags, MatchFlag)
201
202=== modified file 'tests/plugins/sqlite/SqliteEventViewTest.cpp'
203--- tests/plugins/sqlite/SqliteEventViewTest.cpp 2013-12-09 21:18:14 +0000
204+++ tests/plugins/sqlite/SqliteEventViewTest.cpp 2015-05-15 19:19:21 +0000
205@@ -17,6 +17,7 @@
206 */
207
208 #include <QtCore/QObject>
209+#include <QtCore/QScopedPointer>
210 #include <QtTest/QtTest>
211 #include "sqlitehistoryplugin.h"
212 #include "sqlitedatabase.h"
213@@ -38,6 +39,7 @@
214 void initTestCase();
215 void testNextPage();
216 void testFilter();
217+ void testDateFilter();
218 void testSort();
219
220 private:
221@@ -99,6 +101,27 @@
222 delete view;
223 }
224
225+void SqliteEventViewTest::testDateFilter()
226+{
227+ const QDateTime currentDate = QDateTime::currentDateTime();
228+ History::IntersectionFilter iFilter =
229+ History::Filter(History::FieldAccountId, "account0") &
230+ History::Filter("timestamp", currentDate.addDays(-10).addSecs(-60), History::MatchGreaterOrEqual) &
231+ History::Filter("timestamp", currentDate.addSecs(60), History::MatchLessOrEqual);
232+
233+ QScopedPointer<History::PluginEventView> view(mPlugin->queryEvents(History::EventTypeText,
234+ History::Sort(History::FieldTimestamp),
235+ iFilter));
236+ QVERIFY(view->IsValid());
237+ QList<QVariantMap> events = view->NextPage();
238+ QCOMPARE(events.count(), 10);
239+ for(int i=0; i < 10; i++) {
240+ QVariantMap event = events.at(i);
241+ QCOMPARE(event[History::FieldTimestamp].toDateTime().date().day(),
242+ currentDate.addDays(i-10).date().day());
243+ }
244+}
245+
246 void SqliteEventViewTest::testSort()
247 {
248 History::Sort ascendingSort(History::FieldEventId, Qt::AscendingOrder);
249@@ -133,6 +156,7 @@
250
251 void SqliteEventViewTest::populateDatabase()
252 {
253+ const QDateTime currentDate = QDateTime::currentDateTime();
254 mPlugin->beginBatchOperation();
255
256 // create two threads of each type
257@@ -147,7 +171,7 @@
258 voiceThread[History::FieldThreadId].toString(),
259 QString("event%1").arg(j, 2, 10, QChar('0')),
260 j % 2 ? "self" : QString("participant%1").arg(i),
261- QDateTime::currentDateTime(),
262+ currentDate.addDays(j - EVENT_COUNT + 1),
263 j % 2,
264 j % 2,
265 j % 2 ? QTime(i, j, 0) : QTime());
266@@ -164,7 +188,7 @@
267 textThread[History::FieldThreadId].toString(),
268 QString("event%1").arg(j, 2, 10, QChar('0')),
269 j % 2 ? "self" : QString("participant%1").arg(i),
270- QDateTime::currentDateTime(),
271+ currentDate.addDays(j - EVENT_COUNT + 1),
272 j % 2,
273 QString("Hello %1").arg(j),
274 History::MessageTypeText,

Subscribers

People subscribed via source and target branches