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
=== modified file 'Ubuntu/History/historymodel.cpp'
--- Ubuntu/History/historymodel.cpp 2017-03-22 17:15:32 +0000
+++ Ubuntu/History/historymodel.cpp 2017-03-22 17:15:32 +0000
@@ -415,10 +415,18 @@
415415
416bool HistoryModel::lessThan(const QVariantMap &left, const QVariantMap &right) const416bool HistoryModel::lessThan(const QVariantMap &left, const QVariantMap &right) const
417{417{
418 QVariant leftValue = left[sort()->sortField()];418 QStringList sortFields = sort()->sortField().split(",");
419 QVariant rightValue = right[sort()->sortField()];419
420420 while(!sortFields.isEmpty()) {
421 return leftValue < rightValue;421 QString sortField = sortFields.takeFirst().trimmed();
422 QVariant leftValue = left.value(sortField, QVariant());
423 QVariant rightValue = right.value(sortField, QVariant());
424
425 if (leftValue != rightValue) {
426 return leftValue < rightValue;
427 }
428 }
429 return false;
422}430}
423431
424int HistoryModel::positionForItem(const QVariantMap &item) const432int HistoryModel::positionForItem(const QVariantMap &item) const
425433
=== modified file 'plugins/sqlite/sqlitehistoryeventview.cpp'
--- plugins/sqlite/sqlitehistoryeventview.cpp 2015-01-28 23:08:01 +0000
+++ plugins/sqlite/sqlitehistoryeventview.cpp 2017-03-22 17:15:32 +0000
@@ -42,7 +42,14 @@
42 QString condition = mPlugin->filterToString(filter, filterValues);42 QString condition = mPlugin->filterToString(filter, filterValues);
43 QString order;43 QString order;
44 if (!sort.sortField().isNull()) {44 if (!sort.sortField().isNull()) {
45 order = QString("ORDER BY %1 %2").arg(sort.sortField(), sort.sortOrder() == Qt::AscendingOrder ? "ASC" : "DESC");45 // WORKAROUND: Supports multiple fields by split it using ','
46 Q_FOREACH(const QString& field, sort.sortField().split(",")) {
47 order += QString("%1 %2, ")
48 .arg(field.trimmed())
49 .arg(sort.sortOrder() == Qt::AscendingOrder ? "ASC" : "DESC");
50 }
51
52 order = QString("ORDER BY %1").arg(order.mid(0, order.lastIndexOf(",")));
46 // FIXME: check case sensitiviy53 // FIXME: check case sensitiviy
47 }54 }
4855
4956
=== modified file 'plugins/sqlite/sqlitehistorythreadview.cpp'
--- plugins/sqlite/sqlitehistorythreadview.cpp 2016-11-24 01:56:01 +0000
+++ plugins/sqlite/sqlitehistorythreadview.cpp 2017-03-22 17:15:32 +0000
@@ -43,7 +43,14 @@
43 QString condition = mPlugin->filterToString(filter, filterValues);43 QString condition = mPlugin->filterToString(filter, filterValues);
44 QString order;44 QString order;
45 if (!sort.sortField().isNull()) {45 if (!sort.sortField().isNull()) {
46 order = QString("ORDER BY %1 %2").arg(sort.sortField(), sort.sortOrder() == Qt::AscendingOrder ? "ASC" : "DESC");46 // WORKAROUND: Supports multiple fields by split it using ','
47 Q_FOREACH(const QString& field, sort.sortField().split(",")) {
48 order += QString("%1 %2, ")
49 .arg(field.trimmed())
50 .arg(sort.sortOrder() == Qt::AscendingOrder ? "ASC" : "DESC");
51 }
52
53 order = QString("ORDER BY %1").arg(order.mid(0, order.lastIndexOf(",")));
47 // FIXME: check case sensitiviy54 // FIXME: check case sensitiviy
48 }55 }
4956
5057
=== modified file 'tests/plugins/sqlite/SqliteEventViewTest.cpp'
--- tests/plugins/sqlite/SqliteEventViewTest.cpp 2013-12-09 21:18:14 +0000
+++ tests/plugins/sqlite/SqliteEventViewTest.cpp 2017-03-22 17:15:32 +0000
@@ -39,6 +39,7 @@
39 void testNextPage();39 void testNextPage();
40 void testFilter();40 void testFilter();
41 void testSort();41 void testSort();
42 void testSortWithMultipleFields();
4243
43private:44private:
44 SQLiteHistoryPlugin *mPlugin;45 SQLiteHistoryPlugin *mPlugin;
@@ -128,7 +129,26 @@
128 QCOMPARE(allEvents.first()[History::FieldEventId].toString(), QString("event%1").arg(EVENT_COUNT-1));129 QCOMPARE(allEvents.first()[History::FieldEventId].toString(), QString("event%1").arg(EVENT_COUNT-1));
129 QCOMPARE(allEvents.last()[History::FieldEventId].toString(), QString("event00"));130 QCOMPARE(allEvents.last()[History::FieldEventId].toString(), QString("event00"));
130 delete view;131 delete view;
131132}
133
134void SqliteEventViewTest::testSortWithMultipleFields()
135{
136 History::Sort ascendingSort(QString("%1, %2").arg(History::FieldAccountId).arg(History::FieldEventId), Qt::AscendingOrder);
137 //History::Sort ascendingSort(QString("%1").arg(History::FieldEventId), Qt::AscendingOrder);
138 History::PluginEventView *view = mPlugin->queryEvents(History::EventTypeText, ascendingSort);
139 QVERIFY(view->IsValid());
140 QList<QVariantMap> allEvents;
141 QList<QVariantMap> events = view->NextPage();
142 while (!events.isEmpty()) {
143 allEvents << events;
144 events = view->NextPage();
145 }
146
147 QCOMPARE(allEvents[0][History::FieldEventId].toString(), QString("event00"));
148 QCOMPARE(allEvents[0][History::FieldAccountId].toString(), QString("account0"));
149 QCOMPARE(allEvents[1][History::FieldEventId].toString(), QString("event01"));
150 QCOMPARE(allEvents[1][History::FieldAccountId].toString(), QString("account0"));
151 delete view;
132}152}
133153
134void SqliteEventViewTest::populateDatabase()154void SqliteEventViewTest::populateDatabase()
@@ -136,7 +156,7 @@
136 mPlugin->beginBatchOperation();156 mPlugin->beginBatchOperation();
137157
138 // create two threads of each type158 // create two threads of each type
139 for (int i = 0; i < 2; ++i) {159 for (int i = 1; i >= 0; --i) {
140 QVariantMap voiceThread = mPlugin->createThreadForParticipants(QString("account%1").arg(i),160 QVariantMap voiceThread = mPlugin->createThreadForParticipants(QString("account%1").arg(i),
141 History::EventTypeVoice,161 History::EventTypeVoice,
142 QStringList() << QString("participant%1").arg(i));162 QStringList() << QString("participant%1").arg(i));

Subscribers

People subscribed via source and target branches

to all changes: