Merge lp:~phablet-team/history-service/sort_by_multiple_fields into lp:history-service/staging

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Tiago Salem Herrmann
Approved revision: 263
Merged at revision: 260
Proposed branch: lp:~phablet-team/history-service/sort_by_multiple_fields
Merge into: lp:history-service/staging
Prerequisite: lp:~phablet-team/history-service/mark_threads_as_read
Diff against target: 115 lines (+50/-8)
4 files modified
Ubuntu/History/historymodel.cpp (+12/-4)
plugins/sqlite/sqlitehistoryeventview.cpp (+8/-1)
plugins/sqlite/sqlitehistorythreadview.cpp (+8/-1)
tests/plugins/sqlite/SqliteEventViewTest.cpp (+22/-2)
To merge this branch: bzr merge lp:~phablet-team/history-service/sort_by_multiple_fields
Reviewer Review Type Date Requested Status
Tiago Salem Herrmann (community) Approve
Gustavo Pichorim Boiko (community) Needs Fixing
Review via email: mp+320661@code.launchpad.net

This proposal supersedes a proposal from 2017-02-07.

Commit message

Allow pass multiple fields on sort clause.

Description of the change

Allow pass multiple fields on sort clause.

To post a comment you must log in.
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Just one request, looks good otherwise.

review: Needs Fixing
263. By Renato Araujo Oliveira Filho

Code optimize.

Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

> Just one request, looks good otherwise.
fixed.

Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote :

looks good. thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Ubuntu/History/historymodel.cpp'
2--- Ubuntu/History/historymodel.cpp 2017-03-22 17:15:32 +0000
3+++ Ubuntu/History/historymodel.cpp 2017-03-22 17:15:32 +0000
4@@ -415,10 +415,18 @@
5
6 bool HistoryModel::lessThan(const QVariantMap &left, const QVariantMap &right) const
7 {
8- QVariant leftValue = left[sort()->sortField()];
9- QVariant rightValue = right[sort()->sortField()];
10-
11- return leftValue < rightValue;
12+ QStringList sortFields = sort()->sortField().split(",");
13+
14+ while(!sortFields.isEmpty()) {
15+ QString sortField = sortFields.takeFirst().trimmed();
16+ QVariant leftValue = left.value(sortField, QVariant());
17+ QVariant rightValue = right.value(sortField, QVariant());
18+
19+ if (leftValue != rightValue) {
20+ return leftValue < rightValue;
21+ }
22+ }
23+ return false;
24 }
25
26 int HistoryModel::positionForItem(const QVariantMap &item) const
27
28=== modified file 'plugins/sqlite/sqlitehistoryeventview.cpp'
29--- plugins/sqlite/sqlitehistoryeventview.cpp 2015-01-28 23:08:01 +0000
30+++ plugins/sqlite/sqlitehistoryeventview.cpp 2017-03-22 17:15:32 +0000
31@@ -42,7 +42,14 @@
32 QString condition = mPlugin->filterToString(filter, filterValues);
33 QString order;
34 if (!sort.sortField().isNull()) {
35- order = QString("ORDER BY %1 %2").arg(sort.sortField(), sort.sortOrder() == Qt::AscendingOrder ? "ASC" : "DESC");
36+ // WORKAROUND: Supports multiple fields by split it using ','
37+ Q_FOREACH(const QString& field, sort.sortField().split(",")) {
38+ order += QString("%1 %2, ")
39+ .arg(field.trimmed())
40+ .arg(sort.sortOrder() == Qt::AscendingOrder ? "ASC" : "DESC");
41+ }
42+
43+ order = QString("ORDER BY %1").arg(order.mid(0, order.lastIndexOf(",")));
44 // FIXME: check case sensitiviy
45 }
46
47
48=== modified file 'plugins/sqlite/sqlitehistorythreadview.cpp'
49--- plugins/sqlite/sqlitehistorythreadview.cpp 2016-11-24 01:56:01 +0000
50+++ plugins/sqlite/sqlitehistorythreadview.cpp 2017-03-22 17:15:32 +0000
51@@ -43,7 +43,14 @@
52 QString condition = mPlugin->filterToString(filter, filterValues);
53 QString order;
54 if (!sort.sortField().isNull()) {
55- order = QString("ORDER BY %1 %2").arg(sort.sortField(), sort.sortOrder() == Qt::AscendingOrder ? "ASC" : "DESC");
56+ // WORKAROUND: Supports multiple fields by split it using ','
57+ Q_FOREACH(const QString& field, sort.sortField().split(",")) {
58+ order += QString("%1 %2, ")
59+ .arg(field.trimmed())
60+ .arg(sort.sortOrder() == Qt::AscendingOrder ? "ASC" : "DESC");
61+ }
62+
63+ order = QString("ORDER BY %1").arg(order.mid(0, order.lastIndexOf(",")));
64 // FIXME: check case sensitiviy
65 }
66
67
68=== modified file 'tests/plugins/sqlite/SqliteEventViewTest.cpp'
69--- tests/plugins/sqlite/SqliteEventViewTest.cpp 2013-12-09 21:18:14 +0000
70+++ tests/plugins/sqlite/SqliteEventViewTest.cpp 2017-03-22 17:15:32 +0000
71@@ -39,6 +39,7 @@
72 void testNextPage();
73 void testFilter();
74 void testSort();
75+ void testSortWithMultipleFields();
76
77 private:
78 SQLiteHistoryPlugin *mPlugin;
79@@ -128,7 +129,26 @@
80 QCOMPARE(allEvents.first()[History::FieldEventId].toString(), QString("event%1").arg(EVENT_COUNT-1));
81 QCOMPARE(allEvents.last()[History::FieldEventId].toString(), QString("event00"));
82 delete view;
83-
84+}
85+
86+void SqliteEventViewTest::testSortWithMultipleFields()
87+{
88+ History::Sort ascendingSort(QString("%1, %2").arg(History::FieldAccountId).arg(History::FieldEventId), Qt::AscendingOrder);
89+ //History::Sort ascendingSort(QString("%1").arg(History::FieldEventId), Qt::AscendingOrder);
90+ History::PluginEventView *view = mPlugin->queryEvents(History::EventTypeText, ascendingSort);
91+ QVERIFY(view->IsValid());
92+ QList<QVariantMap> allEvents;
93+ QList<QVariantMap> events = view->NextPage();
94+ while (!events.isEmpty()) {
95+ allEvents << events;
96+ events = view->NextPage();
97+ }
98+
99+ QCOMPARE(allEvents[0][History::FieldEventId].toString(), QString("event00"));
100+ QCOMPARE(allEvents[0][History::FieldAccountId].toString(), QString("account0"));
101+ QCOMPARE(allEvents[1][History::FieldEventId].toString(), QString("event01"));
102+ QCOMPARE(allEvents[1][History::FieldAccountId].toString(), QString("account0"));
103+ delete view;
104 }
105
106 void SqliteEventViewTest::populateDatabase()
107@@ -136,7 +156,7 @@
108 mPlugin->beginBatchOperation();
109
110 // create two threads of each type
111- for (int i = 0; i < 2; ++i) {
112+ for (int i = 1; i >= 0; --i) {
113 QVariantMap voiceThread = mPlugin->createThreadForParticipants(QString("account%1").arg(i),
114 History::EventTypeVoice,
115 QStringList() << QString("participant%1").arg(i));

Subscribers

People subscribed via source and target branches

to all changes: