Merge lp:~osomon/webbrowser-app/use-qml-SortFilterModel into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 1154
Merged at revision: 1294
Proposed branch: lp:~osomon/webbrowser-app/use-qml-SortFilterModel
Merge into: lp:webbrowser-app
Diff against target: 2429 lines (+242/-1360)
42 files modified
src/app/webbrowser/CMakeLists.txt (+0/-4)
src/app/webbrowser/HistoryView.qml (+6/-6)
src/app/webbrowser/HistoryViewWide.qml (+12/-7)
src/app/webbrowser/NewTabView.qml (+1/-5)
src/app/webbrowser/NewTabViewWide.qml (+1/-6)
src/app/webbrowser/PreviewManager.qml (+1/-3)
src/app/webbrowser/TopSitesModel.qml (+31/-0)
src/app/webbrowser/history-domain-model.cpp (+4/-5)
src/app/webbrowser/history-domain-model.h (+5/-5)
src/app/webbrowser/history-domainlist-chronological-model.cpp (+0/-55)
src/app/webbrowser/history-domainlist-chronological-model.h (+0/-46)
src/app/webbrowser/history-domainlist-model.cpp (+4/-5)
src/app/webbrowser/history-domainlist-model.h (+6/-6)
src/app/webbrowser/history-lastvisitdate-model.cpp (+0/-141)
src/app/webbrowser/history-lastvisitdate-model.h (+0/-63)
src/app/webbrowser/history-lastvisitdatelist-model.cpp (+45/-7)
src/app/webbrowser/history-lastvisitdatelist-model.h (+1/-0)
src/app/webbrowser/history-model.cpp (+9/-1)
src/app/webbrowser/history-model.h (+2/-1)
src/app/webbrowser/history-timeframe-model.cpp (+0/-98)
src/app/webbrowser/history-timeframe-model.h (+0/-63)
src/app/webbrowser/limit-proxy-model.h (+1/-1)
src/app/webbrowser/top-sites-model.cpp (+0/-60)
src/app/webbrowser/top-sites-model.h (+0/-49)
src/app/webbrowser/webbrowser-app.cpp (+0/-8)
tests/unittests/CMakeLists.txt (+0/-4)
tests/unittests/history-domain-model/tst_HistoryDomainModelTests.cpp (+8/-14)
tests/unittests/history-domainlist-chronological-model/CMakeLists.txt (+0/-13)
tests/unittests/history-domainlist-chronological-model/tst_HistoryDomainListChronologicalModelTests.cpp (+0/-110)
tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp (+11/-25)
tests/unittests/history-lastvisitdate-model/CMakeLists.txt (+0/-11)
tests/unittests/history-lastvisitdate-model/tst_HistoryLastVisitDateModelTests.cpp (+0/-138)
tests/unittests/history-lastvisitdatelist-model/tst_HistoryLastVisitDateListModelTests.cpp (+14/-35)
tests/unittests/history-model/tst_HistoryModelTests.cpp (+1/-1)
tests/unittests/history-timeframe-model/CMakeLists.txt (+0/-13)
tests/unittests/history-timeframe-model/tst_HistoryTimeframeModelTests.cpp (+0/-160)
tests/unittests/limit-proxy-model/tst_LimitProxyModelTests.cpp (+79/-60)
tests/unittests/qml/CMakeLists.txt (+0/-3)
tests/unittests/qml/tst_HistoryViewWide.qml (+0/-1)
tests/unittests/qml/tst_QmlTests.cpp (+0/-6)
tests/unittests/top-sites-model/CMakeLists.txt (+0/-13)
tests/unittests/top-sites-model/tst_TopSitesModelTests.cpp (+0/-108)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/use-qml-SortFilterModel
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ugo Riboni (community) Approve
Review via email: mp+273203@code.launchpad.net

Commit message

Replace custom models (HistoryDomainListChronologicalModel, HistoryLastVisitDateModel and TopSitesModel) with simple, pure QML SortFilterModel instances.
Remove entirely HistoryTimeframeModel which was not needed any longer.

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: Needs Fixing (continuous-integration)
Revision history for this message
Ugo Riboni (uriboni) wrote :

One of the qml unit tests for NewTabViewWide seems to fail, apparently due to some issues with the history models.

review: Needs Fixing
Revision history for this message
Olivier Tilloy (osomon) wrote :

Not seeing that here (and CI runs are fine too, if we except bug #1498539). Which test are you seeing fail? Can you paste the detailed log of the failure?

Revision history for this message
Ugo Riboni (uriboni) wrote :

Apart of that code-wise all LGTM. Reviews that mostly remove code are always a pleasure. I left a few comments inline, but they are not major things.
Performing functional testing in a minute.

review: Needs Fixing
Revision history for this message
Ugo Riboni (uriboni) wrote :

> Not seeing that here (and CI runs are fine too, if we except bug #1498539).
> Which test are you seeing fail? Can you paste the detailed log of the failure?

Check the report from Jenkins a few comments up in this MR.
If you look at the failures you can dig down to this one:

FAIL! : QmlTests::HistoryViewWide::test_search_updates_dates_list() Compared values are not the same
   Actual (): 0
   Expected (): 1
   Loc: [/tmp/buildd/webbrowser-app-0.23+15.10.20151001bzr1147pkg0vivid1065/tests/unittests/qml/tst_HistoryViewWide.qml(416)]

Revision history for this message
Olivier Tilloy (osomon) wrote :

> Wouldn't it be safer and cleaner to add a role that exposes the lastVisit
> as a QString in ISO 8601 standard format and then use that for sorting
> and filtering ? You could do things like anchor the RegExp to the start
> for extra safety.

Agreed, this is safer. Done, I added a 'lastVisitDateString' role. It doesn’t include the time as there doesn’t seem to be a need for it anywhere, we can update the role to be 'lastVisitString' in the future if the need arises.

> Is there any particular reason why you prefer to declare this separately
> instead as directly assigned to the topSitesModel.model ? Same applies
> in other parts of the code. I don't mind but I would like to know if it
> is just a style preference you have or if there are other reasons for it.

Yes, there is a good reason for this structure. See comments 1 and 2 on bug #1495482.

> Maybe in the warning mention that null is allowed too ?

Good idea. Done.

Revision history for this message
Ugo Riboni (uriboni) wrote :

> > Is there any particular reason why you prefer to declare this separately
> > instead as directly assigned to the topSitesModel.model ? Same applies
> > in other parts of the code. I don't mind but I would like to know if it
> > is just a style preference you have or if there are other reasons for it.
>
> Yes, there is a good reason for this structure. See comments 1 and 2 on bug
> #1495482.

Ok, let's leave it like this for now, but I am unconvinced by the fact that we can not use the two syntaxes interchangeably. I feel like there is some other bug related to roles in our custom models. Won't be the first time.
Anyway, this MR is good to go regardless of that.

review: Approve
Revision history for this message
Olivier Tilloy (osomon) wrote :

QmlTests::HistoryViewWide::test_search_updates_dates_list() still fails in CI, need to investigate further.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1150. By Olivier Tilloy

Merge the latest changes from trunk and resolve conflicts.

1151. By Olivier Tilloy

Fix the PreviewManager’s use of TopSitesModel.

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: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1152. By Olivier Tilloy

Remove the custom HistoryTimeframeModel proxy model, as it’s not needed any longer.

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: Needs Fixing (continuous-integration)
1153. By Olivier Tilloy

Merge the latest changes from trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1154. By Olivier Tilloy

Merge the latest changes from trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
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)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webbrowser/CMakeLists.txt'
2--- src/app/webbrowser/CMakeLists.txt 2015-10-18 19:21:48 +0000
3+++ src/app/webbrowser/CMakeLists.txt 2015-12-03 09:02:16 +0000
4@@ -14,16 +14,12 @@
5 bookmarks-folder-model.cpp
6 bookmarks-folderlist-model.cpp
7 history-domain-model.cpp
8- history-domainlist-chronological-model.cpp
9 history-domainlist-model.cpp
10- history-lastvisitdate-model.cpp
11 history-lastvisitdatelist-model.cpp
12 history-model.cpp
13- history-timeframe-model.cpp
14 limit-proxy-model.cpp
15 tabs-model.cpp
16 text-search-filter-model.cpp
17- top-sites-model.cpp
18 )
19
20 set(WEBBROWSER_APP_MODELS webbrowser-app-models)
21
22=== modified file 'src/app/webbrowser/HistoryView.qml'
23--- src/app/webbrowser/HistoryView.qml 2015-10-15 19:09:59 +0000
24+++ src/app/webbrowser/HistoryView.qml 2015-12-03 09:02:16 +0000
25@@ -37,7 +37,7 @@
26 // the view is displayed as early as possible.
27 id: loadModelTimer
28 interval: 1
29- onTriggered: historyTimeframeModel.sourceModel = HistoryModel
30+ onTriggered: historyDomainListModel.sourceModel = HistoryModel
31 }
32
33 function loadModel() { loadModelTimer.restart() }
34@@ -53,12 +53,12 @@
35 rightMargin: units.gu(2)
36 }
37
38- model: HistoryDomainListChronologicalModel {
39- sourceModel: HistoryDomainListModel {
40- sourceModel: HistoryTimeframeModel {
41- id: historyTimeframeModel
42- }
43+ model: SortFilterModel {
44+ model: HistoryDomainListModel {
45+ id: historyDomainListModel
46 }
47+ sort.property: "lastVisit"
48+ sort.order: Qt.DescendingOrder
49 }
50
51 section.property: "lastVisitDate"
52
53=== modified file 'src/app/webbrowser/HistoryViewWide.qml'
54--- src/app/webbrowser/HistoryViewWide.qml 2015-10-15 19:09:59 +0000
55+++ src/app/webbrowser/HistoryViewWide.qml 2015-12-03 09:02:16 +0000
56@@ -123,7 +123,7 @@
57 currentIndex: 0
58 onCurrentIndexChanged: {
59 if (currentItem) {
60- historyLastVisitDateModel.setLastVisitDate(currentItem.lastVisitDate)
61+ historyLastVisitDateModel.lastVisitDate = currentItem.lastVisitDate
62 }
63 urlsListView.ViewItems.selectedIndices = []
64 }
65@@ -163,7 +163,7 @@
66 }
67
68 model: HistoryLastVisitDateListModel {
69- sourceModel: historyLastVisitDateModel.sourceModel
70+ sourceModel: historyLastVisitDateModel.model
71 }
72
73 delegate: ListItem {
74@@ -244,13 +244,18 @@
75 Keys.onReturnPressed: historyEntrySelected()
76 Keys.onEnterPressed: historyEntrySelected()
77
78- model: HistoryLastVisitDateModel {
79+ model: SortFilterModel {
80 id: historyLastVisitDateModel
81+ property date lastVisitDate
82+ filter {
83+ property: "lastVisitDateString"
84+ pattern: new RegExp(lastVisitDate.isValid() ? "^%1$".arg(Qt.formatDate(lastVisitDate, "yyyy-MM-dd")) : "")
85+ }
86 // Until a valid HistoryModel is assigned the TextSearchFilterModel
87- // will not report role names, and the HistoryLastVisit*Models will emit warnings
88- // since they need a dateLastVisit role to be present.
89- // We avoid this by delaying assigning the source model until it is ready.
90- sourceModel: historySearchModel.sourceModel ? historySearchModel : undefined
91+ // will not report role names, and the HistoryLastVisitDateListModel
92+ // will emit warnings since it needs a dateLastVisit role to be
93+ // present.
94+ model: historySearchModel.sourceModel ? historySearchModel : null
95 }
96
97 clip: true
98
99=== modified file 'src/app/webbrowser/NewTabView.qml'
100--- src/app/webbrowser/NewTabView.qml 2015-10-22 08:12:32 +0000
101+++ src/app/webbrowser/NewTabView.qml 2015-12-03 09:02:16 +0000
102@@ -20,7 +20,6 @@
103 import Qt.labs.settings 1.0
104 import Ubuntu.Components 1.3
105 import webbrowserapp.private 0.1
106-import ".."
107 import "."
108
109 Item {
110@@ -34,10 +33,7 @@
111
112 TopSitesModel {
113 id: topSitesModel
114- sourceModel: HistoryTimeframeModel {
115- id: historyTimeframeModel
116- sourceModel: HistoryModel
117- }
118+ model: HistoryModel
119 }
120
121 QtObject {
122
123=== modified file 'src/app/webbrowser/NewTabViewWide.qml'
124--- src/app/webbrowser/NewTabViewWide.qml 2015-10-22 08:12:32 +0000
125+++ src/app/webbrowser/NewTabViewWide.qml 2015-12-03 09:02:16 +0000
126@@ -17,10 +17,8 @@
127 */
128
129 import QtQuick 2.4
130-import Qt.labs.settings 1.0
131 import Ubuntu.Components 1.3
132 import webbrowserapp.private 0.1
133-import ".."
134 import "."
135
136 FocusScope {
137@@ -51,10 +49,7 @@
138 id: topSitesModel
139 limit: 10
140 sourceModel: TopSitesModel {
141- sourceModel: HistoryTimeframeModel {
142- id: historyTimeframeModel
143- sourceModel: HistoryModel
144- }
145+ model: HistoryModel
146 }
147 }
148
149
150=== modified file 'src/app/webbrowser/PreviewManager.qml'
151--- src/app/webbrowser/PreviewManager.qml 2015-11-04 14:42:56 +0000
152+++ src/app/webbrowser/PreviewManager.qml 2015-12-03 09:02:16 +0000
153@@ -30,9 +30,7 @@
154 id: topSites
155 limit: 10
156 sourceModel: TopSitesModel {
157- sourceModel: HistoryTimeframeModel {
158- sourceModel: HistoryModel
159- }
160+ model: HistoryModel
161 }
162 function contains(url) {
163 for (var i = 0; i < topSites.count; i++) {
164
165=== added file 'src/app/webbrowser/TopSitesModel.qml'
166--- src/app/webbrowser/TopSitesModel.qml 1970-01-01 00:00:00 +0000
167+++ src/app/webbrowser/TopSitesModel.qml 2015-12-03 09:02:16 +0000
168@@ -0,0 +1,31 @@
169+/*
170+ * Copyright 2015 Canonical Ltd.
171+ *
172+ * This file is part of webbrowser-app.
173+ *
174+ * webbrowser-app is free software; you can redistribute it and/or modify
175+ * it under the terms of the GNU General Public License as published by
176+ * the Free Software Foundation; version 3.
177+ *
178+ * webbrowser-app is distributed in the hope that it will be useful,
179+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
180+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
181+ * GNU General Public License for more details.
182+ *
183+ * You should have received a copy of the GNU General Public License
184+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
185+ */
186+
187+import QtQuick 2.4
188+import Ubuntu.Components 1.3
189+
190+SortFilterModel {
191+ sort {
192+ order: Qt.DescendingOrder
193+ property: "visits"
194+ }
195+ filter {
196+ pattern: /^false$/
197+ property: "hidden"
198+ }
199+}
200
201=== modified file 'src/app/webbrowser/history-domain-model.cpp'
202--- src/app/webbrowser/history-domain-model.cpp 2014-08-14 12:18:20 +0000
203+++ src/app/webbrowser/history-domain-model.cpp 2015-12-03 09:02:16 +0000
204@@ -1,5 +1,5 @@
205 /*
206- * Copyright 2013 Canonical Ltd.
207+ * Copyright 2013-2015 Canonical Ltd.
208 *
209 * This file is part of webbrowser-app.
210 *
211@@ -18,7 +18,6 @@
212
213 #include "history-domain-model.h"
214 #include "history-model.h"
215-#include "history-timeframe-model.h"
216
217 // Qt
218 #include <QtCore/QUrl>
219@@ -46,12 +45,12 @@
220 connect(this, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), SLOT(onModelChanged()));
221 }
222
223-HistoryTimeframeModel* HistoryDomainModel::sourceModel() const
224+HistoryModel* HistoryDomainModel::sourceModel() const
225 {
226- return qobject_cast<HistoryTimeframeModel*>(QSortFilterProxyModel::sourceModel());
227+ return qobject_cast<HistoryModel*>(QSortFilterProxyModel::sourceModel());
228 }
229
230-void HistoryDomainModel::setSourceModel(HistoryTimeframeModel* sourceModel)
231+void HistoryDomainModel::setSourceModel(HistoryModel* sourceModel)
232 {
233 if (sourceModel != this->sourceModel()) {
234 QSortFilterProxyModel::setSourceModel(sourceModel);
235
236=== modified file 'src/app/webbrowser/history-domain-model.h'
237--- src/app/webbrowser/history-domain-model.h 2014-07-15 14:59:37 +0000
238+++ src/app/webbrowser/history-domain-model.h 2015-12-03 09:02:16 +0000
239@@ -1,5 +1,5 @@
240 /*
241- * Copyright 2013 Canonical Ltd.
242+ * Copyright 2013-2015 Canonical Ltd.
243 *
244 * This file is part of webbrowser-app.
245 *
246@@ -25,13 +25,13 @@
247 #include <QtCore/QString>
248 #include <QtCore/QUrl>
249
250-class HistoryTimeframeModel;
251+class HistoryModel;
252
253 class HistoryDomainModel : public QSortFilterProxyModel
254 {
255 Q_OBJECT
256
257- Q_PROPERTY(HistoryTimeframeModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
258+ Q_PROPERTY(HistoryModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
259 Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged)
260 Q_PROPERTY(QDateTime lastVisit READ lastVisit NOTIFY lastVisitChanged)
261 Q_PROPERTY(QString lastVisitedTitle READ lastVisitedTitle NOTIFY lastVisitedTitleChanged)
262@@ -40,8 +40,8 @@
263 public:
264 HistoryDomainModel(QObject* parent=0);
265
266- HistoryTimeframeModel* sourceModel() const;
267- void setSourceModel(HistoryTimeframeModel* sourceModel);
268+ HistoryModel* sourceModel() const;
269+ void setSourceModel(HistoryModel* sourceModel);
270
271 const QString& domain() const;
272 void setDomain(const QString& domain);
273
274=== removed file 'src/app/webbrowser/history-domainlist-chronological-model.cpp'
275--- src/app/webbrowser/history-domainlist-chronological-model.cpp 2015-05-28 11:26:05 +0000
276+++ src/app/webbrowser/history-domainlist-chronological-model.cpp 1970-01-01 00:00:00 +0000
277@@ -1,55 +0,0 @@
278-/*
279- * Copyright 2013-2015 Canonical Ltd.
280- *
281- * This file is part of webbrowser-app.
282- *
283- * webbrowser-app is free software; you can redistribute it and/or modify
284- * it under the terms of the GNU General Public License as published by
285- * the Free Software Foundation; version 3.
286- *
287- * webbrowser-app is distributed in the hope that it will be useful,
288- * but WITHOUT ANY WARRANTY; without even the implied warranty of
289- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
290- * GNU General Public License for more details.
291- *
292- * You should have received a copy of the GNU General Public License
293- * along with this program. If not, see <http://www.gnu.org/licenses/>.
294- */
295-
296-#include "history-domainlist-chronological-model.h"
297-#include "history-domainlist-model.h"
298-
299-/*!
300- \class HistoryDomainListChronologicalModel
301- \brief Proxy model that sorts a domain list model in reverse chronological
302- order
303-
304- HistoryDomainListChronologicalModel is a proxy model that sorts a
305- HistoryDomainListModel in reverse chronological order
306- (i.e. the domain with the latest entry visited first).
307-*/
308-HistoryDomainListChronologicalModel::HistoryDomainListChronologicalModel(QObject* parent)
309- : QSortFilterProxyModel(parent)
310-{
311- setDynamicSortFilter(true);
312- setSortRole(HistoryDomainListModel::LastVisit);
313- sort(0, Qt::DescendingOrder);
314-}
315-
316-HistoryDomainListModel* HistoryDomainListChronologicalModel::sourceModel() const
317-{
318- return qobject_cast<HistoryDomainListModel*>(QSortFilterProxyModel::sourceModel());
319-}
320-
321-void HistoryDomainListChronologicalModel::setSourceModel(HistoryDomainListModel* sourceModel)
322-{
323- if (sourceModel != this->sourceModel()) {
324- QSortFilterProxyModel::setSourceModel(sourceModel);
325- Q_EMIT sourceModelChanged();
326- }
327-}
328-
329-QString HistoryDomainListChronologicalModel::get(int index) const
330-{
331- return data(this->index(index, 0), HistoryDomainListModel::Domain).toString();
332-}
333
334=== removed file 'src/app/webbrowser/history-domainlist-chronological-model.h'
335--- src/app/webbrowser/history-domainlist-chronological-model.h 2015-05-28 11:26:05 +0000
336+++ src/app/webbrowser/history-domainlist-chronological-model.h 1970-01-01 00:00:00 +0000
337@@ -1,46 +0,0 @@
338-/*
339- * Copyright 2013-2015 Canonical Ltd.
340- *
341- * This file is part of webbrowser-app.
342- *
343- * webbrowser-app is free software; you can redistribute it and/or modify
344- * it under the terms of the GNU General Public License as published by
345- * the Free Software Foundation; version 3.
346- *
347- * webbrowser-app is distributed in the hope that it will be useful,
348- * but WITHOUT ANY WARRANTY; without even the implied warranty of
349- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
350- * GNU General Public License for more details.
351- *
352- * You should have received a copy of the GNU General Public License
353- * along with this program. If not, see <http://www.gnu.org/licenses/>.
354- */
355-
356-#ifndef __HISTORY_DOMAINLIST_CHRONOLOGICAL_MODEL_H__
357-#define __HISTORY_DOMAINLIST_CHRONOLOGICAL_MODEL_H__
358-
359-// Qt
360-#include <QtCore/QSortFilterProxyModel>
361-#include <QtCore/QString>
362-
363-class HistoryDomainListModel;
364-
365-class HistoryDomainListChronologicalModel : public QSortFilterProxyModel
366-{
367- Q_OBJECT
368-
369- Q_PROPERTY(HistoryDomainListModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
370-
371-public:
372- HistoryDomainListChronologicalModel(QObject* parent=0);
373-
374- HistoryDomainListModel* sourceModel() const;
375- void setSourceModel(HistoryDomainListModel* sourceModel);
376-
377- Q_INVOKABLE QString get(int index) const;
378-
379-Q_SIGNALS:
380- void sourceModelChanged() const;
381-};
382-
383-#endif // __HISTORY_DOMAINLIST_CHRONOLOGICAL_MODEL_H__
384
385=== modified file 'src/app/webbrowser/history-domainlist-model.cpp'
386--- src/app/webbrowser/history-domainlist-model.cpp 2014-08-12 19:57:28 +0000
387+++ src/app/webbrowser/history-domainlist-model.cpp 2015-12-03 09:02:16 +0000
388@@ -1,5 +1,5 @@
389 /*
390- * Copyright 2013 Canonical Ltd.
391+ * Copyright 2013-2015 Canonical Ltd.
392 *
393 * This file is part of webbrowser-app.
394 *
395@@ -19,7 +19,6 @@
396 #include "history-domain-model.h"
397 #include "history-domainlist-model.h"
398 #include "history-model.h"
399-#include "history-timeframe-model.h"
400
401 // Qt
402 #include <QtCore/QStringList>
403@@ -29,7 +28,7 @@
404 \brief List model that exposes history entries grouped by domain name
405
406 HistoryDomainListModel is a list model that exposes history entries from a
407- HistoryTimeframeModel grouped by domain name. Each item in the list has
408+ HistoryModel grouped by domain name. Each item in the list has
409 three roles: 'domain' for the domain name, 'lastVisit' for the timestamp
410 of the last page visited in this domain, and 'entries' for the corresponding
411 HistoryDomainModel that contains all entries in this group.
412@@ -91,12 +90,12 @@
413 }
414 }
415
416-HistoryTimeframeModel* HistoryDomainListModel::sourceModel() const
417+HistoryModel* HistoryDomainListModel::sourceModel() const
418 {
419 return m_sourceModel;
420 }
421
422-void HistoryDomainListModel::setSourceModel(HistoryTimeframeModel* sourceModel)
423+void HistoryDomainListModel::setSourceModel(HistoryModel* sourceModel)
424 {
425 if (sourceModel != m_sourceModel) {
426 beginResetModel();
427
428=== modified file 'src/app/webbrowser/history-domainlist-model.h'
429--- src/app/webbrowser/history-domainlist-model.h 2014-07-15 14:59:37 +0000
430+++ src/app/webbrowser/history-domainlist-model.h 2015-12-03 09:02:16 +0000
431@@ -1,5 +1,5 @@
432 /*
433- * Copyright 2013 Canonical Ltd.
434+ * Copyright 2013-2015 Canonical Ltd.
435 *
436 * This file is part of webbrowser-app.
437 *
438@@ -25,13 +25,13 @@
439 #include <QtCore/QString>
440
441 class HistoryDomainModel;
442-class HistoryTimeframeModel;
443+class HistoryModel;
444
445 class HistoryDomainListModel : public QAbstractListModel
446 {
447 Q_OBJECT
448
449- Q_PROPERTY(HistoryTimeframeModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
450+ Q_PROPERTY(HistoryModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
451
452 Q_ENUMS(Roles)
453
454@@ -53,8 +53,8 @@
455 int rowCount(const QModelIndex& parent=QModelIndex()) const;
456 QVariant data(const QModelIndex& index, int role) const;
457
458- HistoryTimeframeModel* sourceModel() const;
459- void setSourceModel(HistoryTimeframeModel* sourceModel);
460+ HistoryModel* sourceModel() const;
461+ void setSourceModel(HistoryModel* sourceModel);
462
463 Q_SIGNALS:
464 void sourceModelChanged() const;
465@@ -67,7 +67,7 @@
466 void onDomainDataChanged();
467
468 private:
469- HistoryTimeframeModel* m_sourceModel;
470+ HistoryModel* m_sourceModel;
471 QMap<QString, HistoryDomainModel*> m_domains;
472
473 void clearDomains();
474
475=== removed file 'src/app/webbrowser/history-lastvisitdate-model.cpp'
476--- src/app/webbrowser/history-lastvisitdate-model.cpp 2015-08-20 12:14:02 +0000
477+++ src/app/webbrowser/history-lastvisitdate-model.cpp 1970-01-01 00:00:00 +0000
478@@ -1,141 +0,0 @@
479-/*
480- * Copyright 2015 Canonical Ltd.
481- *
482- * This file is part of webbrowser-app.
483- *
484- * webbrowser-app is free software; you can redistribute it and/or modify
485- * it under the terms of the GNU General Public License as published by
486- * the Free Software Foundation; version 3.
487- *
488- * webbrowser-app is distributed in the hope that it will be useful,
489- * but WITHOUT ANY WARRANTY; without even the implied warranty of
490- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
491- * GNU General Public License for more details.
492- *
493- * You should have received a copy of the GNU General Public License
494- * along with this program. If not, see <http://www.gnu.org/licenses/>.
495- */
496-
497-#include "history-lastvisitdate-model.h"
498-#include "history-model.h"
499-#include "history-timeframe-model.h"
500-
501-// Qt
502-#include <QtCore/QDebug>
503-#include <QtCore/QUrl>
504-
505-/*!
506- \class HistoryLastVisitDateModel
507- \brief Proxy model that filters the contents of a model based on last
508- visit date
509-
510- HistoryLastVisitDateModel is a proxy model that filters the contents
511- of any QAbstractItemModel-derived model based on a role called
512- "lastVisitDate".
513-
514- An entry in the history model matches if the last visit date equals
515- the filter visit date.
516-
517- When no visit date is set, all entries match. If the model does not have
518- the "lastVisitDate" role, then no entries are returned if a filter visit
519- date is set, otherwise all entries match.
520-*/
521-HistoryLastVisitDateModel::HistoryLastVisitDateModel(QObject* parent)
522- : QSortFilterProxyModel(parent)
523-{
524-}
525-
526-QVariant HistoryLastVisitDateModel::sourceModel() const
527-{
528- QAbstractItemModel* model = QSortFilterProxyModel::sourceModel();
529- return (model) ? QVariant::fromValue(model) : QVariant();
530-}
531-
532-void HistoryLastVisitDateModel::setSourceModel(QVariant sourceModel)
533-{
534- QAbstractItemModel* newSourceModel = qvariant_cast<QAbstractItemModel*>(sourceModel);
535- if (sourceModel.isValid() && newSourceModel == 0) {
536- qWarning() << "Only QAbstractItemModel-derived instances are allowed as"
537- << "source models";
538- }
539-
540- if (newSourceModel != QSortFilterProxyModel::sourceModel()) {
541- beginResetModel();
542-
543- QAbstractItemModel* currentModel = QSortFilterProxyModel::sourceModel();
544- if (currentModel != 0) {
545- currentModel->disconnect(this);
546- }
547- QSortFilterProxyModel::setSourceModel(newSourceModel);
548- updateSourceModelRole();
549-
550- if (newSourceModel != 0) {
551- connect(newSourceModel, SIGNAL(modelReset()), SLOT(updateSourceModelRole()));
552- connect(newSourceModel, SIGNAL(layoutChanged(QList<QPersistentModelIndex>, QAbstractItemModel::LayoutChangeHint)),
553- SLOT(updateSourceModelRole()));
554- }
555-
556- endResetModel();
557- Q_EMIT sourceModelChanged();
558- }
559-}
560-
561-const QDate& HistoryLastVisitDateModel::lastVisitDate() const
562-{
563- return m_lastVisitDate;
564-}
565-
566-void HistoryLastVisitDateModel::setLastVisitDate(const QDate& lastVisitDate)
567-{
568- if (lastVisitDate != m_lastVisitDate) {
569- m_lastVisitDate = lastVisitDate;
570- invalidate();
571- Q_EMIT lastVisitDateChanged();
572- }
573-}
574-
575-QVariantMap HistoryLastVisitDateModel::get(int i) const
576-{
577- QVariantMap item;
578- QHash<int, QByteArray> roles = roleNames();
579-
580- QModelIndex modelIndex = index(i, 0);
581- if (modelIndex.isValid()) {
582- Q_FOREACH(int role, roles.keys()) {
583- QString roleName = QString::fromUtf8(roles.value(role));
584- item.insert(roleName, data(modelIndex, role));
585- }
586- }
587- return item;
588-}
589-
590-bool HistoryLastVisitDateModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
591-{
592- if (m_lastVisitDate.isNull()) {
593- return true;
594- }
595-
596- if (m_sourceModelRole == -1) {
597- return false;
598- }
599-
600- QAbstractItemModel* model = QSortFilterProxyModel::sourceModel();
601- if (model) {
602- QModelIndex index = model->index(source_row, 0, source_parent);
603- return m_lastVisitDate == model->data(index, m_sourceModelRole).toDate();
604- } else {
605- return false;
606- }
607-}
608-
609-void HistoryLastVisitDateModel::updateSourceModelRole()
610-{
611- QAbstractItemModel* sourceModel = QSortFilterProxyModel::sourceModel();
612- if (sourceModel && sourceModel->roleNames().count() > 0) {
613- m_sourceModelRole = sourceModel->roleNames().key("lastVisitDate", -1);
614- if (m_sourceModelRole == -1) {
615- qWarning() << "No results will be returned because the sourceModel"
616- << "does not have a role named \"lastVisitDate\"";
617- }
618- }
619-}
620
621=== removed file 'src/app/webbrowser/history-lastvisitdate-model.h'
622--- src/app/webbrowser/history-lastvisitdate-model.h 2015-08-20 12:14:02 +0000
623+++ src/app/webbrowser/history-lastvisitdate-model.h 1970-01-01 00:00:00 +0000
624@@ -1,63 +0,0 @@
625-/*
626- * Copyright 2015 Canonical Ltd.
627- *
628- * This file is part of webbrowser-app.
629- *
630- * webbrowser-app is free software; you can redistribute it and/or modify
631- * it under the terms of the GNU General Public License as published by
632- * the Free Software Foundation; version 3.
633- *
634- * webbrowser-app is distributed in the hope that it will be useful,
635- * but WITHOUT ANY WARRANTY; without even the implied warranty of
636- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
637- * GNU General Public License for more details.
638- *
639- * You should have received a copy of the GNU General Public License
640- * along with this program. If not, see <http://www.gnu.org/licenses/>.
641- */
642-
643-#ifndef __HISTORY_LASTVISITDATE_MODEL_H__
644-#define __HISTORY_LASTVISITDATE_MODEL_H__
645-
646-// Qt
647-#include <QtCore/QDate>
648-#include <QtCore/QSortFilterProxyModel>
649-#include <QtCore/QString>
650-#include <QtCore/QUrl>
651-#include <QtCore/QVariant>
652-
653-class HistoryLastVisitDateModel : public QSortFilterProxyModel
654-{
655- Q_OBJECT
656-
657- Q_PROPERTY(QVariant sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
658- Q_PROPERTY(QDate lastVisitDate READ lastVisitDate WRITE setLastVisitDate NOTIFY lastVisitDateChanged)
659-
660-public:
661- HistoryLastVisitDateModel(QObject* parent=0);
662-
663- QVariant sourceModel() const;
664- void setSourceModel(QVariant sourceModel);
665-
666- const QDate& lastVisitDate() const;
667- Q_INVOKABLE void setLastVisitDate(const QDate& lastVisitDate);
668-
669- Q_INVOKABLE QVariantMap get(int index) const;
670-
671-Q_SIGNALS:
672- void sourceModelChanged() const;
673- void lastVisitDateChanged() const;
674-
675-protected:
676- // reimplemented from QSortFilterProxyModel
677- bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
678-
679-private Q_SLOTS:
680- void updateSourceModelRole();
681-
682-private:
683- QDate m_lastVisitDate;
684- int m_sourceModelRole;
685-};
686-
687-#endif // __HISTORY_LASTVISITDATE_MODEL_H__
688
689=== modified file 'src/app/webbrowser/history-lastvisitdatelist-model.cpp'
690--- src/app/webbrowser/history-lastvisitdatelist-model.cpp 2015-08-20 12:12:55 +0000
691+++ src/app/webbrowser/history-lastvisitdatelist-model.cpp 2015-12-03 09:02:16 +0000
692@@ -18,7 +18,6 @@
693
694 #include "history-lastvisitdatelist-model.h"
695 #include "history-model.h"
696-#include "history-timeframe-model.h"
697
698 // Qt
699 #include <QtCore/QDebug>
700@@ -28,10 +27,10 @@
701 \class HistoryLastVisitDateListModel
702 \brief List model that exposes a list of all last visit dates from history
703
704- HistoryLastVisitiDateListModel is a list model that exposes all last visit
705+ HistoryLastVisitDateListModel is a list model that exposes all last visit
706 dates from the source model. Each item has one single role: 'lastVisitDate'
707 for a date in which there is at least one url visited on the source model.
708- A special entry is added to the begining of the list to represent all dates.
709+ A special entry is added to the beginning of the list to represent all dates.
710
711 The source model needs to expose a role named 'lastVisitDate', from which
712 the input dates will be read. If such role is not present, this model will
713@@ -86,9 +85,9 @@
714 void HistoryLastVisitDateListModel::setSourceModel(QVariant sourceModel)
715 {
716 QAbstractItemModel* newSourceModel = qvariant_cast<QAbstractItemModel*>(sourceModel);
717- if (sourceModel.isValid() && newSourceModel == 0) {
718- qWarning() << "Only QAbstractItemModel-derived instances are allowed as"
719- << "source models";
720+ if (sourceModel.isValid() && (newSourceModel == 0) && !sourceModel.canConvert<void*>()) {
721+ qWarning() << "Only QAbstractItemModel-derived instances and null are"
722+ << "allowed as source models";
723 }
724
725 if (newSourceModel != m_sourceModel) {
726@@ -107,6 +106,9 @@
727 SLOT(onRowsInserted(const QModelIndex&, int, int)));
728 connect(m_sourceModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
729 SLOT(onRowsRemoved(const QModelIndex&, int, int)));
730+ connect(m_sourceModel,
731+ SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)),
732+ SLOT(onRowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)));
733 connect(m_sourceModel, SIGNAL(modelReset()), SLOT(onModelReset()));
734 connect(m_sourceModel, SIGNAL(layoutChanged(QList<QPersistentModelIndex>, QAbstractItemModel::LayoutChangeHint)),
735 SLOT(onModelReset()));
736@@ -160,6 +162,7 @@
737 int removeAt = m_orderedDates.indexOf(lastVisitDate.key());
738 beginRemoveRows(QModelIndex(), removeAt, removeAt);
739 m_orderedDates.removeAt(removeAt);
740+ delete lastVisitDate.value();
741 lastVisitDate = m_lastVisitDates.erase(lastVisitDate);
742 endRemoveRows();
743 } else {
744@@ -175,6 +178,41 @@
745 }
746 }
747
748+void HistoryLastVisitDateListModel::onRowsMoved(const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row)
749+{
750+ Q_UNUSED(parent);
751+ Q_UNUSED(destination);
752+
753+ // Rows were moved in the source model, meaning that their last visit dates
754+ // were potentially updated, so we remove all the dates corresponding to
755+ // the rows before they were moved, and we add all the dates corresponding
756+ // to the rows after they were moved.
757+
758+ // Determine a lower and upper bound for the dates that should be removed
759+ // by looking at the indexes surrounding the rows before they were moved.
760+ QDate lower = m_sourceModel->data(m_sourceModel->index((row < start) ? end + 1 : start, 0), m_sourceModelRole).toDate();
761+ if (!lower.isValid()) {
762+ // The last row was moved too, we don’t have a strict lower bound.
763+ lower = m_orderedDates.last().addDays(-1);
764+ }
765+ QDate upper = m_sourceModel->data(m_sourceModel->index((row < start) ? end : start - 1, 0), m_sourceModelRole).toDate();
766+ for (QDate i = upper.addDays(-1); i > lower; i = i.addDays(-1)) {
767+ if (m_orderedDates.contains(i)) {
768+ int removeAt = m_orderedDates.indexOf(i);
769+ beginRemoveRows(QModelIndex(), removeAt, removeAt);
770+ m_orderedDates.removeAt(removeAt);
771+ delete m_lastVisitDates.take(i);
772+ endRemoveRows();
773+ }
774+ }
775+
776+ // Now add back dates for all the rows after they were moved.
777+ for (int i = 0; i <= (end - start); ++i) {
778+ int index = i + row + ((row < start) ? 0 : start - end);
779+ insertNewHistoryEntry(new QPersistentModelIndex(m_sourceModel->index(index, 0)), true);
780+ }
781+}
782+
783 void HistoryLastVisitDateListModel::updateSourceModelRole()
784 {
785 if (m_sourceModel && m_sourceModel->roleNames().count() > 0) {
786@@ -198,7 +236,7 @@
787 void HistoryLastVisitDateListModel::insertNewHistoryEntry(QPersistentModelIndex* index, bool notify)
788 {
789 if (m_sourceModelRole == -1) {
790- return;
791+ return;
792 }
793
794 QDate lastVisitDate = index->data(m_sourceModelRole).toDate();
795
796=== modified file 'src/app/webbrowser/history-lastvisitdatelist-model.h'
797--- src/app/webbrowser/history-lastvisitdatelist-model.h 2015-09-16 17:05:10 +0000
798+++ src/app/webbrowser/history-lastvisitdatelist-model.h 2015-12-03 09:02:16 +0000
799@@ -55,6 +55,7 @@
800 private Q_SLOTS:
801 void onRowsInserted(const QModelIndex& parent, int start, int end);
802 void onRowsRemoved(const QModelIndex& parent, int start, int end);
803+ void onRowsMoved(const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row);
804 void onModelReset();
805
806 private:
807
808=== modified file 'src/app/webbrowser/history-model.cpp'
809--- src/app/webbrowser/history-model.cpp 2015-08-18 11:01:52 +0000
810+++ src/app/webbrowser/history-model.cpp 2015-12-03 09:02:16 +0000
811@@ -1,5 +1,5 @@
812 /*
813- * Copyright 2013 Canonical Ltd.
814+ * Copyright 2013-2015 Canonical Ltd.
815 *
816 * This file is part of webbrowser-app.
817 *
818@@ -150,6 +150,7 @@
819 roles[Visits] = "visits";
820 roles[LastVisit] = "lastVisit";
821 roles[LastVisitDate] = "lastVisitDate";
822+ roles[LastVisitDateString] = "lastVisitDateString";
823 roles[Hidden] = "hidden";
824 }
825 return roles;
826@@ -182,6 +183,8 @@
827 return entry.lastVisit;
828 case LastVisitDate:
829 return entry.lastVisit.toLocalTime().date();
830+ case LastVisitDateString:
831+ return entry.lastVisit.toLocalTime().date().toString(Qt::ISODate);
832 case Hidden:
833 return entry.hidden;
834 default:
835@@ -261,6 +264,10 @@
836 }
837 count = ++entry.visits;
838 if (now != entry.lastVisit) {
839+ if (now.date() != entry.lastVisit.date()) {
840+ roles << LastVisitDate;
841+ roles << LastVisitDateString;
842+ }
843 entry.lastVisit = now;
844 roles << LastVisit;
845 }
846@@ -279,6 +286,7 @@
847 if (now != entry.lastVisit) {
848 if (now.date() != entry.lastVisit.date()) {
849 roles << LastVisitDate;
850+ roles << LastVisitDateString;
851 }
852 entry.lastVisit = now;
853 roles << LastVisit;
854
855=== modified file 'src/app/webbrowser/history-model.h'
856--- src/app/webbrowser/history-model.h 2015-09-03 12:41:12 +0000
857+++ src/app/webbrowser/history-model.h 2015-12-03 09:02:16 +0000
858@@ -1,5 +1,5 @@
859 /*
860- * Copyright 2013 Canonical Ltd.
861+ * Copyright 2013-2015 Canonical Ltd.
862 *
863 * This file is part of webbrowser-app.
864 *
865@@ -49,6 +49,7 @@
866 Visits,
867 LastVisit,
868 LastVisitDate,
869+ LastVisitDateString,
870 Hidden,
871 };
872
873
874=== removed file 'src/app/webbrowser/history-timeframe-model.cpp'
875--- src/app/webbrowser/history-timeframe-model.cpp 2015-08-20 12:19:17 +0000
876+++ src/app/webbrowser/history-timeframe-model.cpp 1970-01-01 00:00:00 +0000
877@@ -1,98 +0,0 @@
878-/*
879- * Copyright 2013 Canonical Ltd.
880- *
881- * This file is part of webbrowser-app.
882- *
883- * webbrowser-app is free software; you can redistribute it and/or modify
884- * it under the terms of the GNU General Public License as published by
885- * the Free Software Foundation; version 3.
886- *
887- * webbrowser-app is distributed in the hope that it will be useful,
888- * but WITHOUT ANY WARRANTY; without even the implied warranty of
889- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
890- * GNU General Public License for more details.
891- *
892- * You should have received a copy of the GNU General Public License
893- * along with this program. If not, see <http://www.gnu.org/licenses/>.
894- */
895-
896-#include "history-timeframe-model.h"
897-#include "history-model.h"
898-
899-/*!
900- \class HistoryTimeframeModel
901- \brief Proxy model that filters the contents of the history model
902- excluding all entries that are not contained in a given timeframe
903-
904- HistoryTimeframeModel is a proxy model that filters the contents of a
905- HistoryModel, excluding all entries that are not contained in a given
906- timeframe specified by a start datetime and an end datetime.
907-
908- To leave one side of the timeframe open, do not set either the start or end
909- datetime (or reset them to an invalid datetime).
910-*/
911-HistoryTimeframeModel::HistoryTimeframeModel(QObject* parent)
912- : QSortFilterProxyModel(parent)
913-{
914-}
915-
916-HistoryModel* HistoryTimeframeModel::sourceModel() const
917-{
918- return qobject_cast<HistoryModel*>(QSortFilterProxyModel::sourceModel());
919-}
920-
921-void HistoryTimeframeModel::setSourceModel(HistoryModel* sourceModel)
922-{
923- if (sourceModel != this->sourceModel()) {
924- beginResetModel();
925- QSortFilterProxyModel::setSourceModel(sourceModel);
926- endResetModel();
927- Q_EMIT sourceModelChanged();
928- }
929-}
930-
931-const QDateTime& HistoryTimeframeModel::start() const
932-{
933- return m_start;
934-}
935-
936-void HistoryTimeframeModel::setStart(const QDateTime& start)
937-{
938- if (start != m_start) {
939- m_start = start;
940- invalidate();
941- Q_EMIT startChanged();
942- }
943-}
944-
945-const QDateTime& HistoryTimeframeModel::end() const
946-{
947- return m_end;
948-}
949-
950-void HistoryTimeframeModel::setEnd(const QDateTime& end)
951-{
952- if (end != m_end) {
953- m_end = end;
954- invalidate();
955- Q_EMIT endChanged();
956- }
957-}
958-
959-bool HistoryTimeframeModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
960-{
961- QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
962- QDateTime lastVisit = sourceModel()->data(index, HistoryModel::LastVisit).toDateTime();
963- if (m_start.isValid() && (lastVisit < m_start)) {
964- return false;
965- }
966- if (m_end.isValid() && (lastVisit > m_end)) {
967- return false;
968- }
969- return true;
970-}
971-
972-QHash<int, QByteArray> HistoryTimeframeModel::roleNames() const
973-{
974- return (sourceModel()) ? sourceModel()->roleNames() : QHash<int, QByteArray>();
975-}
976
977=== removed file 'src/app/webbrowser/history-timeframe-model.h'
978--- src/app/webbrowser/history-timeframe-model.h 2015-08-20 12:19:17 +0000
979+++ src/app/webbrowser/history-timeframe-model.h 1970-01-01 00:00:00 +0000
980@@ -1,63 +0,0 @@
981-/*
982- * Copyright 2013 Canonical Ltd.
983- *
984- * This file is part of webbrowser-app.
985- *
986- * webbrowser-app is free software; you can redistribute it and/or modify
987- * it under the terms of the GNU General Public License as published by
988- * the Free Software Foundation; version 3.
989- *
990- * webbrowser-app is distributed in the hope that it will be useful,
991- * but WITHOUT ANY WARRANTY; without even the implied warranty of
992- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
993- * GNU General Public License for more details.
994- *
995- * You should have received a copy of the GNU General Public License
996- * along with this program. If not, see <http://www.gnu.org/licenses/>.
997- */
998-
999-#ifndef __HISTORY_TIMEFRAME_MODEL_H__
1000-#define __HISTORY_TIMEFRAME_MODEL_H__
1001-
1002-// Qt
1003-#include <QtCore/QDateTime>
1004-#include <QtCore/QSortFilterProxyModel>
1005-
1006-class HistoryModel;
1007-
1008-class HistoryTimeframeModel : public QSortFilterProxyModel
1009-{
1010- Q_OBJECT
1011-
1012- Q_PROPERTY(HistoryModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
1013- Q_PROPERTY(QDateTime start READ start WRITE setStart NOTIFY startChanged)
1014- Q_PROPERTY(QDateTime end READ end WRITE setEnd NOTIFY endChanged)
1015-
1016-public:
1017- HistoryTimeframeModel(QObject* parent=0);
1018-
1019- HistoryModel* sourceModel() const;
1020- void setSourceModel(HistoryModel* sourceModel);
1021-
1022- const QDateTime& start() const;
1023- void setStart(const QDateTime& start);
1024-
1025- const QDateTime& end() const;
1026- void setEnd(const QDateTime& end);
1027-
1028-Q_SIGNALS:
1029- void sourceModelChanged() const;
1030- void startChanged() const;
1031- void endChanged() const;
1032-
1033-protected:
1034- // reimplemented from QSortFilterProxyModel
1035- bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
1036- QHash<int, QByteArray> roleNames() const;
1037-
1038-private:
1039- QDateTime m_start;
1040- QDateTime m_end;
1041-};
1042-
1043-#endif // __HISTORY_TIMEFRAME_MODEL_H__
1044
1045=== modified file 'src/app/webbrowser/limit-proxy-model.h'
1046--- src/app/webbrowser/limit-proxy-model.h 2015-11-13 17:14:45 +0000
1047+++ src/app/webbrowser/limit-proxy-model.h 2015-12-03 09:02:16 +0000
1048@@ -1,5 +1,5 @@
1049 /*
1050- * Copyright 2014 Canonical Ltd.
1051+ * Copyright 2014-2015 Canonical Ltd.
1052 *
1053 * This file is part of webbrowser-app.
1054 *
1055
1056=== removed file 'src/app/webbrowser/top-sites-model.cpp'
1057--- src/app/webbrowser/top-sites-model.cpp 2015-06-01 21:24:04 +0000
1058+++ src/app/webbrowser/top-sites-model.cpp 1970-01-01 00:00:00 +0000
1059@@ -1,60 +0,0 @@
1060-/*
1061- * Copyright 2015 Canonical Ltd.
1062- *
1063- * This file is part of webbrowser-app.
1064- *
1065- * webbrowser-app is free software; you can redistribute it and/or modify
1066- * it under the terms of the GNU General Public License as published by
1067- * the Free Software Foundation; version 3.
1068- *
1069- * webbrowser-app is distributed in the hope that it will be useful,
1070- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1071- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1072- * GNU General Public License for more details.
1073- *
1074- * You should have received a copy of the GNU General Public License
1075- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1076- */
1077-
1078-#include "history-model.h"
1079-#include "history-timeframe-model.h"
1080-#include "top-sites-model.h"
1081-
1082-/*!
1083- \class TopSitesModel
1084- \brief Proxy model that filters a history model based on hidden role and sorts it by number of visits
1085-
1086- TopSitesModel is a proxy model that filters a HistoryTimeframeModel
1087- based on the hidden rule and sorts it by the number of visits
1088- (i.e. the history with the greatest number of visits first ignoring entries marked as removed by user).
1089-*/
1090-TopSitesModel::TopSitesModel(QObject* parent)
1091- : QSortFilterProxyModel(parent)
1092-{
1093- setDynamicSortFilter(true);
1094- setSortRole(HistoryModel::Visits);
1095- sort(0, Qt::DescendingOrder);
1096- connect(this, SIGNAL(rowsInserted(const QModelIndex&, int, int)), SIGNAL(countChanged()));
1097- connect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SIGNAL(countChanged()));
1098- connect(this, SIGNAL(modelReset()), SIGNAL(countChanged()));
1099-}
1100-
1101-HistoryTimeframeModel* TopSitesModel::sourceModel() const
1102-{
1103- return qobject_cast<HistoryTimeframeModel*>(QSortFilterProxyModel::sourceModel());
1104-}
1105-
1106-void TopSitesModel::setSourceModel(HistoryTimeframeModel* sourceModel)
1107-{
1108- if (sourceModel != this->sourceModel()) {
1109- QSortFilterProxyModel::setSourceModel(sourceModel);
1110- Q_EMIT sourceModelChanged();
1111- Q_EMIT countChanged();
1112- }
1113-}
1114-
1115-bool TopSitesModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
1116-{
1117- QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
1118- return !sourceModel()->data(index, HistoryModel::Hidden).toBool();
1119-}
1120
1121=== removed file 'src/app/webbrowser/top-sites-model.h'
1122--- src/app/webbrowser/top-sites-model.h 2015-05-28 13:56:52 +0000
1123+++ src/app/webbrowser/top-sites-model.h 1970-01-01 00:00:00 +0000
1124@@ -1,49 +0,0 @@
1125-/*
1126- * Copyright 2015 Canonical Ltd.
1127- *
1128- * This file is part of webbrowser-app.
1129- *
1130- * webbrowser-app is free software; you can redistribute it and/or modify
1131- * it under the terms of the GNU General Public License as published by
1132- * the Free Software Foundation; version 3.
1133- *
1134- * webbrowser-app is distributed in the hope that it will be useful,
1135- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1136- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1137- * GNU General Public License for more details.
1138- *
1139- * You should have received a copy of the GNU General Public License
1140- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1141- */
1142-
1143-#ifndef __TOP_SITES_MODEL_H__
1144-#define __TOP_SITES_MODEL_H__
1145-
1146-// Qt
1147-#include <QtCore/QSortFilterProxyModel>
1148-
1149-class HistoryTimeframeModel;
1150-
1151-class TopSitesModel : public QSortFilterProxyModel
1152-{
1153- Q_OBJECT
1154-
1155- Q_PROPERTY(HistoryTimeframeModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
1156- Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
1157-
1158-public:
1159- TopSitesModel(QObject* parent=0);
1160-
1161- HistoryTimeframeModel* sourceModel() const;
1162- void setSourceModel(HistoryTimeframeModel* sourceModel);
1163-
1164-Q_SIGNALS:
1165- void sourceModelChanged() const;
1166- void countChanged() const;
1167-
1168-protected:
1169- // reimplemented from QSortFilterProxyModel
1170- bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
1171-};
1172-
1173-#endif // __TOP_SITES_MODEL_H__
1174
1175=== modified file 'src/app/webbrowser/webbrowser-app.cpp'
1176--- src/app/webbrowser/webbrowser-app.cpp 2015-10-22 15:07:26 +0000
1177+++ src/app/webbrowser/webbrowser-app.cpp 2015-12-03 09:02:16 +0000
1178@@ -21,17 +21,13 @@
1179 #include "cache-deleter.h"
1180 #include "config.h"
1181 #include "file-operations.h"
1182-#include "history-domainlist-chronological-model.h"
1183 #include "history-domainlist-model.h"
1184 #include "history-lastvisitdatelist-model.h"
1185-#include "history-lastvisitdate-model.h"
1186 #include "history-model.h"
1187-#include "history-timeframe-model.h"
1188 #include "limit-proxy-model.h"
1189 #include "searchengine.h"
1190 #include "text-search-filter-model.h"
1191 #include "tabs-model.h"
1192-#include "top-sites-model.h"
1193 #include "webbrowser-app.h"
1194
1195 // Qt
1196@@ -82,12 +78,8 @@
1197 {
1198 const char* uri = "webbrowserapp.private";
1199 qmlRegisterSingletonType<HistoryModel>(uri, 0, 1, "HistoryModel", HistoryModel_singleton_factory);
1200- qmlRegisterType<HistoryTimeframeModel>(uri, 0, 1, "HistoryTimeframeModel");
1201- qmlRegisterType<TopSitesModel>(uri, 0 , 1, "TopSitesModel");
1202 qmlRegisterType<HistoryDomainListModel>(uri, 0, 1, "HistoryDomainListModel");
1203- qmlRegisterType<HistoryDomainListChronologicalModel>(uri, 0, 1, "HistoryDomainListChronologicalModel");
1204 qmlRegisterType<HistoryLastVisitDateListModel>(uri, 0, 1, "HistoryLastVisitDateListModel");
1205- qmlRegisterType<HistoryLastVisitDateModel>(uri, 0, 1, "HistoryLastVisitDateModel");
1206 qmlRegisterType<LimitProxyModel>(uri, 0 , 1, "LimitProxyModel");
1207 qmlRegisterType<TabsModel>(uri, 0, 1, "TabsModel");
1208 qmlRegisterSingletonType<BookmarksModel>(uri, 0, 1, "BookmarksModel", BookmarksModel_singleton_factory);
1209
1210=== modified file 'tests/unittests/CMakeLists.txt'
1211--- tests/unittests/CMakeLists.txt 2015-10-06 09:48:38 +0000
1212+++ tests/unittests/CMakeLists.txt 2015-12-03 09:02:16 +0000
1213@@ -2,13 +2,9 @@
1214 add_subdirectory(qml)
1215 add_subdirectory(domain-utils)
1216 add_subdirectory(history-model)
1217-add_subdirectory(history-timeframe-model)
1218 add_subdirectory(history-domain-model)
1219 add_subdirectory(history-domainlist-model)
1220-add_subdirectory(history-domainlist-chronological-model)
1221-add_subdirectory(history-lastvisitdate-model)
1222 add_subdirectory(history-lastvisitdatelist-model)
1223-add_subdirectory(top-sites-model)
1224 add_subdirectory(session-utils)
1225 add_subdirectory(tabs-model)
1226 add_subdirectory(bookmarks-model)
1227
1228=== modified file 'tests/unittests/history-domain-model/tst_HistoryDomainModelTests.cpp'
1229--- tests/unittests/history-domain-model/tst_HistoryDomainModelTests.cpp 2013-10-04 15:07:52 +0000
1230+++ tests/unittests/history-domain-model/tst_HistoryDomainModelTests.cpp 2015-12-03 09:02:16 +0000
1231@@ -1,5 +1,5 @@
1232 /*
1233- * Copyright 2013 Canonical Ltd.
1234+ * Copyright 2013-2015 Canonical Ltd.
1235 *
1236 * This file is part of webbrowser-app.
1237 *
1238@@ -23,8 +23,6 @@
1239 // local
1240 #include "history-model.h"
1241 #include "history-domain-model.h"
1242-#include "history-timeframe-model.h"
1243-
1244
1245 class HistoryDomainModelTests : public QObject
1246 {
1247@@ -32,7 +30,6 @@
1248
1249 private:
1250 HistoryModel* history;
1251- HistoryTimeframeModel* timeframe;
1252 HistoryDomainModel* model;
1253
1254 private Q_SLOTS:
1255@@ -40,16 +37,13 @@
1256 {
1257 history = new HistoryModel;
1258 history->setDatabasePath(":memory:");
1259- timeframe = new HistoryTimeframeModel;
1260- timeframe->setSourceModel(history);
1261 model = new HistoryDomainModel;
1262- model->setSourceModel(timeframe);
1263+ model->setSourceModel(history);
1264 }
1265
1266 void cleanup()
1267 {
1268 delete model;
1269- delete timeframe;
1270 delete history;
1271 }
1272
1273@@ -61,15 +55,15 @@
1274 void shouldNotifyWhenChangingSourceModel()
1275 {
1276 QSignalSpy spy(model, SIGNAL(sourceModelChanged()));
1277- model->setSourceModel(timeframe);
1278+ model->setSourceModel(history);
1279 QVERIFY(spy.isEmpty());
1280- HistoryTimeframeModel* timeframe2 = new HistoryTimeframeModel(model);
1281- model->setSourceModel(timeframe2);
1282+ HistoryModel history2;
1283+ model->setSourceModel(&history2);
1284 QCOMPARE(spy.count(), 1);
1285- QCOMPARE(model->sourceModel(), timeframe2);
1286- model->setSourceModel(0);
1287+ QCOMPARE(model->sourceModel(), &history2);
1288+ model->setSourceModel(nullptr);
1289 QCOMPARE(spy.count(), 2);
1290- QCOMPARE(model->sourceModel(), (HistoryTimeframeModel*) 0);
1291+ QCOMPARE(model->sourceModel(), (HistoryModel*) nullptr);
1292 }
1293
1294 void shouldNotifyWhenChangingDomain()
1295
1296=== removed directory 'tests/unittests/history-domainlist-chronological-model'
1297=== removed file 'tests/unittests/history-domainlist-chronological-model/CMakeLists.txt'
1298--- tests/unittests/history-domainlist-chronological-model/CMakeLists.txt 2015-06-22 10:29:20 +0000
1299+++ tests/unittests/history-domainlist-chronological-model/CMakeLists.txt 1970-01-01 00:00:00 +0000
1300@@ -1,13 +0,0 @@
1301-find_package(Qt5Core REQUIRED)
1302-find_package(Qt5Sql REQUIRED)
1303-find_package(Qt5Test REQUIRED)
1304-set(TEST tst_HistoryDomainListChronologicalModelTests)
1305-add_executable(${TEST} tst_HistoryDomainListChronologicalModelTests.cpp)
1306-include_directories(${webbrowser-app_SOURCE_DIR})
1307-target_link_libraries(${TEST}
1308- Qt5::Core
1309- Qt5::Sql
1310- Qt5::Test
1311- webbrowser-app-models
1312-)
1313-add_test(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${TEST} -xunitxml -o ${TEST}.xml)
1314
1315=== removed file 'tests/unittests/history-domainlist-chronological-model/tst_HistoryDomainListChronologicalModelTests.cpp'
1316--- tests/unittests/history-domainlist-chronological-model/tst_HistoryDomainListChronologicalModelTests.cpp 2015-05-28 11:26:05 +0000
1317+++ tests/unittests/history-domainlist-chronological-model/tst_HistoryDomainListChronologicalModelTests.cpp 1970-01-01 00:00:00 +0000
1318@@ -1,110 +0,0 @@
1319-/*
1320- * Copyright 2013 Canonical Ltd.
1321- *
1322- * This file is part of webbrowser-app.
1323- *
1324- * webbrowser-app is free software; you can redistribute it and/or modify
1325- * it under the terms of the GNU General Public License as published by
1326- * the Free Software Foundation; version 3.
1327- *
1328- * webbrowser-app is distributed in the hope that it will be useful,
1329- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1330- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1331- * GNU General Public License for more details.
1332- *
1333- * You should have received a copy of the GNU General Public License
1334- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1335- */
1336-
1337-// Qt
1338-#include <QtTest/QSignalSpy>
1339-#include <QtTest/QtTest>
1340-
1341-// local
1342-#include "domain-utils.h"
1343-#include "history-model.h"
1344-#include "history-domain-model.h"
1345-#include "history-domainlist-model.h"
1346-#include "history-domainlist-chronological-model.h"
1347-#include "history-timeframe-model.h"
1348-
1349-class HistoryDomainListChronologicalModelTests : public QObject
1350-{
1351- Q_OBJECT
1352-
1353-private:
1354- HistoryModel* history;
1355- HistoryTimeframeModel* timeframe;
1356- HistoryDomainListModel* domainlist;
1357- HistoryDomainListChronologicalModel* model;
1358-
1359-private Q_SLOTS:
1360- void init()
1361- {
1362- history = new HistoryModel;
1363- history->setDatabasePath(":memory:");
1364- timeframe = new HistoryTimeframeModel;
1365- timeframe->setSourceModel(history);
1366- domainlist = new HistoryDomainListModel;
1367- domainlist->setSourceModel(timeframe);
1368- model = new HistoryDomainListChronologicalModel;
1369- model->setSourceModel(domainlist);
1370- }
1371-
1372- void cleanup()
1373- {
1374- delete model;
1375- delete domainlist;
1376- delete timeframe;
1377- delete history;
1378- }
1379-
1380- void shouldBeInitiallyEmpty()
1381- {
1382- QCOMPARE(model->rowCount(), 0);
1383- }
1384-
1385- void shouldNotifyWhenChangingSourceModel()
1386- {
1387- QSignalSpy spy(model, SIGNAL(sourceModelChanged()));
1388- model->setSourceModel(domainlist);
1389- QVERIFY(spy.isEmpty());
1390- HistoryDomainListModel* domainlist2 = new HistoryDomainListModel;
1391- model->setSourceModel(domainlist2);
1392- QCOMPARE(spy.count(), 1);
1393- QCOMPARE(model->sourceModel(), domainlist2);
1394- model->setSourceModel(0);
1395- QCOMPARE(spy.count(), 2);
1396- QCOMPARE(model->sourceModel(), (HistoryDomainListModel*) 0);
1397- delete domainlist2;
1398- }
1399-
1400- void shouldRemainSorted()
1401- {
1402- history->add(QUrl("http://example.org/"), "Example Domain", QUrl());
1403- QTest::qWait(1001);
1404- history->add(QUrl("http://ubuntu.com/"), "Ubuntu", QUrl());
1405- QCOMPARE(model->data(model->index(0, 0), HistoryDomainListModel::Domain).toString(), QString("ubuntu.com"));
1406- QCOMPARE(model->data(model->index(1, 0), HistoryDomainListModel::Domain).toString(), QString("example.org"));
1407- }
1408-
1409- void shouldRemoveDomain() {
1410- history->add(QUrl("http://example.org/"), "Example Domain", QUrl());
1411- QTest::qWait(1001);
1412- history->add(QUrl("http://ubuntu.com/"), "Ubuntu", QUrl());
1413- QSignalSpy spy(model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
1414- history->removeEntriesByDomain("ubuntu.com");
1415- QCOMPARE(spy.count(), 1);
1416- QList<QVariant> args = spy.takeFirst();
1417- QCOMPARE(args.at(1).toInt(), 0);
1418- QCOMPARE(args.at(2).toInt(), 0);
1419- }
1420-
1421- void shouldReturnDomain() {
1422- history->add(QUrl("http://example.org/"), "Example Domain", QUrl());
1423- QCOMPARE(model->get(0), QString("example.org"));
1424- }
1425-};
1426-
1427-QTEST_MAIN(HistoryDomainListChronologicalModelTests)
1428-#include "tst_HistoryDomainListChronologicalModelTests.moc"
1429
1430=== modified file 'tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp'
1431--- tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp 2013-08-06 15:42:38 +0000
1432+++ tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp 2015-12-03 09:02:16 +0000
1433@@ -1,5 +1,5 @@
1434 /*
1435- * Copyright 2013 Canonical Ltd.
1436+ * Copyright 2013-2015 Canonical Ltd.
1437 *
1438 * This file is part of webbrowser-app.
1439 *
1440@@ -25,7 +25,6 @@
1441 #include "history-model.h"
1442 #include "history-domain-model.h"
1443 #include "history-domainlist-model.h"
1444-#include "history-timeframe-model.h"
1445
1446 class HistoryDomainListModelTests : public QObject
1447 {
1448@@ -33,7 +32,6 @@
1449
1450 private:
1451 HistoryModel* history;
1452- HistoryTimeframeModel* timeframe;
1453 HistoryDomainListModel* model;
1454
1455 void verifyDataChanged(QSignalSpy& spy, int row)
1456@@ -54,16 +52,13 @@
1457 {
1458 history = new HistoryModel;
1459 history->setDatabasePath(":memory:");
1460- timeframe = new HistoryTimeframeModel;
1461- timeframe->setSourceModel(history);
1462 model = new HistoryDomainListModel;
1463- model->setSourceModel(timeframe);
1464+ model->setSourceModel(history);
1465 }
1466
1467 void cleanup()
1468 {
1469 delete model;
1470- delete timeframe;
1471 delete history;
1472 }
1473
1474@@ -108,20 +103,12 @@
1475 void shouldUpdateDomainListWhenRemovingEntries()
1476 {
1477 history->add(QUrl("http://example.org/"), "Example Domain", QUrl());
1478- QTest::qWait(100);
1479- QDateTime t0 = QDateTime::currentDateTimeUtc();
1480- QTest::qWait(100);
1481 history->add(QUrl("http://example.com/"), "Example Domain", QUrl());
1482- QTest::qWait(100);
1483- QDateTime t1 = QDateTime::currentDateTimeUtc();
1484- QTest::qWait(100);
1485 history->add(QUrl("http://example.org/test"), "Example Domain", QUrl());
1486 QCOMPARE(model->rowCount(), 2);
1487-
1488- timeframe->setEnd(t1);
1489+ history->removeEntryByUrl(QUrl("http://example.org/test"));
1490 QCOMPARE(model->rowCount(), 2);
1491-
1492- timeframe->setStart(t0);
1493+ history->removeEntryByUrl(QUrl("http://example.org/"));
1494 QCOMPARE(model->rowCount(), 1);
1495 }
1496
1497@@ -168,21 +155,20 @@
1498 history->add(QUrl("http://ubuntu.com/"), "Ubuntu", QUrl());
1499 QCOMPARE(model->rowCount(), 3);
1500
1501- model->setSourceModel(timeframe);
1502+ model->setSourceModel(history);
1503 QVERIFY(spy.isEmpty());
1504 QCOMPARE(model->rowCount(), 3);
1505
1506- model->setSourceModel(0);
1507+ model->setSourceModel(nullptr);
1508 QCOMPARE(spy.count(), 1);
1509- QCOMPARE(model->sourceModel(), (HistoryTimeframeModel*) 0);
1510+ QCOMPARE(model->sourceModel(), (HistoryModel*) nullptr);
1511 QCOMPARE(model->rowCount(), 0);
1512
1513- HistoryTimeframeModel* timeframe2 = new HistoryTimeframeModel(history);
1514- timeframe2->setSourceModel(history);
1515- model->setSourceModel(timeframe2);
1516+ HistoryModel history2;
1517+ model->setSourceModel(&history2);
1518 QCOMPARE(spy.count(), 2);
1519- QCOMPARE(model->sourceModel(), timeframe2);
1520- QCOMPARE(model->rowCount(), 3);
1521+ QCOMPARE(model->sourceModel(), &history2);
1522+ QCOMPARE(model->rowCount(), 0);
1523 }
1524
1525 void shouldKeepDomainsSorted()
1526
1527=== removed directory 'tests/unittests/history-lastvisitdate-model'
1528=== removed file 'tests/unittests/history-lastvisitdate-model/CMakeLists.txt'
1529--- tests/unittests/history-lastvisitdate-model/CMakeLists.txt 2015-07-29 00:25:59 +0000
1530+++ tests/unittests/history-lastvisitdate-model/CMakeLists.txt 1970-01-01 00:00:00 +0000
1531@@ -1,11 +0,0 @@
1532-find_package(Qt5Sql REQUIRED)
1533-find_package(Qt5Test REQUIRED)
1534-set(TEST tst_HistoryLastVisitDateModelTests)
1535-add_executable(${TEST} tst_HistoryLastVisitDateModelTests.cpp)
1536-include_directories(${webbrowser-app_SOURCE_DIR})
1537-target_link_libraries(${TEST}
1538- webbrowser-app-models
1539- Qt5::Sql
1540- Qt5::Test
1541-)
1542-add_test(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${TEST} -xunitxml -o ${TEST}.xml)
1543
1544=== removed file 'tests/unittests/history-lastvisitdate-model/tst_HistoryLastVisitDateModelTests.cpp'
1545--- tests/unittests/history-lastvisitdate-model/tst_HistoryLastVisitDateModelTests.cpp 2015-08-20 12:19:17 +0000
1546+++ tests/unittests/history-lastvisitdate-model/tst_HistoryLastVisitDateModelTests.cpp 1970-01-01 00:00:00 +0000
1547@@ -1,138 +0,0 @@
1548-/*
1549- * Copyright 2015 Canonical Ltd.
1550- *
1551- * This file is part of webbrowser-app.
1552- *
1553- * webbrowser-app is free software; you can redistribute it and/or modify
1554- * it under the terms of the GNU General Public License as published by
1555- * the Free Software Foundation; version 3.
1556- *
1557- * webbrowser-app is distributed in the hope that it will be useful,
1558- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1559- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1560- * GNU General Public License for more details.
1561- *
1562- * You should have received a copy of the GNU General Public License
1563- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1564- */
1565-
1566-// Qt
1567-#include <QtTest/QSignalSpy>
1568-#include <QtTest/QtTest>
1569-
1570-// local
1571-#include "bookmarks-model.h"
1572-#include "history-lastvisitdate-model.h"
1573-#include "history-model.h"
1574-#include "history-timeframe-model.h"
1575-
1576-
1577-class HistoryLastVisitDateModelTests : public QObject
1578-{
1579- Q_OBJECT
1580-
1581-private:
1582- HistoryModel* history;
1583- HistoryTimeframeModel* timeframe;
1584- HistoryLastVisitDateModel* model;
1585-
1586-private Q_SLOTS:
1587- void init()
1588- {
1589- history = new HistoryModel;
1590- history->setDatabasePath(":memory:");
1591- timeframe = new HistoryTimeframeModel;
1592- timeframe->setSourceModel(history);
1593- model = new HistoryLastVisitDateModel;
1594- model->setSourceModel(QVariant::fromValue(timeframe));
1595- }
1596-
1597- void cleanup()
1598- {
1599- delete model;
1600- delete timeframe;
1601- delete history;
1602- }
1603-
1604- void shouldBeInitiallyEmpty()
1605- {
1606- QCOMPARE(model->rowCount(), 0);
1607- }
1608-
1609- void shouldNotifyWhenChangingSourceModel()
1610- {
1611- QSignalSpy spy(model, SIGNAL(sourceModelChanged()));
1612- model->setSourceModel(QVariant::fromValue(timeframe));
1613- QVERIFY(spy.isEmpty());
1614-
1615- HistoryTimeframeModel* timeframe2 = new HistoryTimeframeModel(model);
1616- model->setSourceModel(QVariant::fromValue(timeframe2));
1617- QCOMPARE(spy.count(), 1);
1618- QCOMPARE(model->sourceModel(), QVariant::fromValue(timeframe2));
1619-
1620- model->setSourceModel(QVariant());
1621- QCOMPARE(spy.count(), 2);
1622- QVERIFY(!model->sourceModel().isValid());
1623-
1624- QTest::ignoreMessage(QtWarningMsg, "Only QAbstractItemModel-derived instances are allowed as source models");
1625- model->setSourceModel(QVariant::fromValue(QString("not a model")));
1626- QVERIFY(!model->sourceModel().isValid());
1627- QCOMPARE(model->rowCount(), 0);
1628- QCOMPARE(spy.count(), 2); // model is still invalid internally so no signal emitted
1629-
1630- QTest::ignoreMessage(QtWarningMsg, "No results will be returned because the sourceModel does not have a role named \"lastVisitDate\"");
1631- BookmarksModel bookmarks;
1632- bookmarks.setDatabasePath(":memory:");
1633- bookmarks.add(QUrl("http://example.org/"), "Example Domain", QUrl(), "");
1634- model->setSourceModel(QVariant::fromValue(&bookmarks));
1635- QCOMPARE(spy.count(), 3);
1636- // with no filter, all entries match even if the model doesn't have the lastVisitDate role
1637- QCOMPARE(model->rowCount(), 1);
1638- model->setLastVisitDate(QDate::currentDate());
1639- QCOMPARE(model->rowCount(), 0);
1640-
1641- delete timeframe2;
1642- }
1643-
1644- void shouldNotifyWhenChangingLastVisitDate()
1645- {
1646- QSignalSpy spy(model, SIGNAL(lastVisitDateChanged()));
1647- model->setLastVisitDate(QDate());
1648- QVERIFY(spy.isEmpty());
1649- model->setLastVisitDate(QDate::currentDate());
1650- QCOMPARE(spy.count(), 1);
1651- }
1652-
1653- void shouldMatchAllWhenNoLastVisitDateSet()
1654- {
1655- history->add(QUrl("http://example.org"), "Example Domain", QUrl());
1656- history->add(QUrl("http://example.com"), "Example Domain", QUrl());
1657- QCOMPARE(model->rowCount(), 2);
1658- }
1659-
1660- void shouldFilterOutNonMatchingLastVisitDate()
1661- {
1662- history->add(QUrl("http://example.org/"), "Example Domain", QUrl());
1663- QTest::qWait(1001);
1664- history->add(QUrl("http://example.com/"), "Example Domain", QUrl());
1665- model->setLastVisitDate(QDate::currentDate());
1666- QCOMPARE(model->rowCount(), 2);
1667- model->setLastVisitDate(QDate(1970, 1, 1));
1668- QCOMPARE(model->rowCount(), 0);
1669- }
1670-
1671- void shouldReturnDataByIndex()
1672- {
1673- history->add(QUrl("http://example.org"), "Example Domain", QUrl());
1674- QTest::qWait(1001);
1675- history->add(QUrl("http://example.com"), "Example Domain", QUrl());
1676- QCOMPARE(model->rowCount(), 2);
1677- QVariantMap entry = model->get(2);
1678- QVERIFY(entry.isEmpty());
1679- entry = model->get(1);
1680- QCOMPARE(entry.value("url").toUrl(), QUrl("http://example.org"));
1681- }
1682-};
1683-
1684-QTEST_MAIN(HistoryLastVisitDateModelTests)
1685-#include "tst_HistoryLastVisitDateModelTests.moc"
1686
1687=== modified file 'tests/unittests/history-lastvisitdatelist-model/tst_HistoryLastVisitDateListModelTests.cpp'
1688--- tests/unittests/history-lastvisitdatelist-model/tst_HistoryLastVisitDateListModelTests.cpp 2015-09-16 17:05:35 +0000
1689+++ tests/unittests/history-lastvisitdatelist-model/tst_HistoryLastVisitDateListModelTests.cpp 2015-12-03 09:02:16 +0000
1690@@ -25,7 +25,6 @@
1691 #include "domain-utils.h"
1692 #include "history-lastvisitdatelist-model.h"
1693 #include "history-model.h"
1694-#include "history-timeframe-model.h"
1695
1696 class MockHistoryModel : public HistoryModel
1697 {
1698@@ -145,7 +144,6 @@
1699
1700 private:
1701 MockHistoryModel* mockHistory;
1702- HistoryTimeframeModel* timeframe;
1703 HistoryLastVisitDateListModel* model;
1704 BookmarksModel* bookmarks;
1705
1706@@ -154,10 +152,8 @@
1707 {
1708 mockHistory = new MockHistoryModel;
1709 mockHistory->setDatabasePath(":memory:");
1710- timeframe = new HistoryTimeframeModel;
1711- timeframe->setSourceModel(mockHistory);
1712 model = new HistoryLastVisitDateListModel;
1713- model->setSourceModel(QVariant::fromValue(timeframe));
1714+ model->setSourceModel(QVariant::fromValue(mockHistory));
1715 bookmarks = new BookmarksModel;
1716 bookmarks->setDatabasePath(":memory:");
1717 }
1718@@ -165,7 +161,6 @@
1719 void cleanup()
1720 {
1721 delete model;
1722- delete timeframe;
1723 delete mockHistory;
1724 delete bookmarks;
1725 }
1726@@ -175,7 +170,7 @@
1727 QCOMPARE(model->rowCount(), 0);
1728 }
1729
1730- void shouldUpdateLastVsitDateListWhenInsertingEntries()
1731+ void shouldUpdateLastVisitDateListWhenInsertingEntries()
1732 {
1733 QSignalSpy spyRowsInserted(model, SIGNAL(rowsInserted(const QModelIndex&, int, int)));
1734 qRegisterMetaType<QVector<int> >();
1735@@ -224,26 +219,6 @@
1736 QCOMPARE(model->rowCount(), 0);
1737 }
1738
1739- void shouldUpdateLastVisitDateListWhenChangingTimeFrame()
1740- {
1741- QDateTime dt1 = QDateTime(QDate(1970, 1, 1), QTime(6, 0, 0));
1742- QDateTime dt2 = QDateTime(QDate(1970, 1, 2), QTime(6, 0, 0));
1743- QDateTime dt3 = QDateTime(QDate(1970, 1, 3), QTime(6, 0, 0));
1744-
1745- mockHistory->add(QUrl("http://example.com/"), "Example Domain", "example.com", QUrl(), dt1);
1746- mockHistory->add(QUrl("http://example.org/"), "Example Domain", "example.org", QUrl(), dt2);
1747- mockHistory->add(QUrl("http://example.net/"), "Example Domain", "example.net", QUrl(), dt3);
1748- QDateTime t0 = QDateTime(QDate(1970, 1, 1), QTime(7, 0, 0));
1749- QDateTime t1 = QDateTime(QDate(1970, 1, 2), QTime(7, 0, 0));
1750- QCOMPARE(model->rowCount(), 4);
1751-
1752- timeframe->setEnd(t1);
1753- QCOMPARE(model->rowCount(), 3);
1754-
1755- timeframe->setStart(t0);
1756- QCOMPARE(model->rowCount(), 2);
1757- }
1758-
1759 void shouldUpdateLastVisitDateListWhenRemovingEntries()
1760 {
1761 QSignalSpy spyRowsRemoved(model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
1762@@ -313,24 +288,23 @@
1763 mockHistory->add(QUrl("http://example.net/"), "Example Domain", "example.net", QUrl(), dt3);
1764 QCOMPARE(model->rowCount(), 4);
1765
1766- model->setSourceModel(QVariant::fromValue(timeframe));
1767+ model->setSourceModel(QVariant::fromValue(mockHistory));
1768 QVERIFY(spy.isEmpty());
1769 QCOMPARE(model->rowCount(), 4);
1770
1771- QTest::ignoreMessage(QtWarningMsg, "Only QAbstractItemModel-derived instances are allowed as source models");
1772+ QTest::ignoreMessage(QtWarningMsg, "Only QAbstractItemModel-derived instances and null are allowed as source models");
1773 model->setSourceModel(0);
1774 QCOMPARE(spy.count(), 1);
1775 QVERIFY(!model->sourceModel().isValid());
1776 QCOMPARE(model->rowCount(), 0);
1777
1778- HistoryTimeframeModel timeframe2(mockHistory);
1779- timeframe2.setSourceModel(mockHistory);
1780- model->setSourceModel(QVariant::fromValue(&timeframe2));
1781+ MockHistoryModel mockHistory2;
1782+ model->setSourceModel(QVariant::fromValue(&mockHistory2));
1783 QCOMPARE(spy.count(), 2);
1784- QCOMPARE(model->sourceModel(), QVariant::fromValue(&timeframe2));
1785- QCOMPARE(model->rowCount(), 4);
1786+ QCOMPARE(model->sourceModel().value<MockHistoryModel*>(), &mockHistory2);
1787+ QCOMPARE(model->rowCount(), 0);
1788
1789- QTest::ignoreMessage(QtWarningMsg, "Only QAbstractItemModel-derived instances are allowed as source models");
1790+ QTest::ignoreMessage(QtWarningMsg, "Only QAbstractItemModel-derived instances and null are allowed as source models");
1791 model->setSourceModel(QVariant::fromValue(QString("not a model")));
1792 QCOMPARE(spy.count(), 3);
1793 QVERIFY(!model->sourceModel().isValid());
1794@@ -340,6 +314,11 @@
1795 bookmarks->add(QUrl("http://example.org/"), "Example Domain", QUrl(), "");
1796 model->setSourceModel(QVariant::fromValue(bookmarks));
1797 QCOMPARE(model->rowCount(), 0);
1798+
1799+ spy.clear();
1800+ model->setSourceModel(QVariant());
1801+ QCOMPARE(spy.count(), 1);
1802+ QVERIFY(model->sourceModel().isNull());
1803 }
1804
1805 void shouldKeepLastVisitDatesSorted()
1806
1807=== modified file 'tests/unittests/history-model/tst_HistoryModelTests.cpp'
1808--- tests/unittests/history-model/tst_HistoryModelTests.cpp 2015-08-17 19:32:01 +0000
1809+++ tests/unittests/history-model/tst_HistoryModelTests.cpp 2015-12-03 09:02:16 +0000
1810@@ -184,7 +184,7 @@
1811 QCOMPARE(model->data(model->index(0, 0), HistoryModel::Icon).toUrl(), QUrl("image://webicon/123"));
1812 QCOMPARE(model->data(model->index(0, 0), HistoryModel::Visits).toInt(), 1);
1813 QVERIFY(model->data(model->index(0, 0), HistoryModel::LastVisit).toDateTime() >= now);
1814- QVERIFY(!model->data(model->index(0, 0), HistoryModel::LastVisit + 3).isValid());
1815+ QVERIFY(!model->data(model->index(0, 0), HistoryModel::LastVisit + 4).isValid());
1816 }
1817
1818 void shouldReturnDatabasePath()
1819
1820=== removed directory 'tests/unittests/history-timeframe-model'
1821=== removed file 'tests/unittests/history-timeframe-model/CMakeLists.txt'
1822--- tests/unittests/history-timeframe-model/CMakeLists.txt 2015-06-22 10:29:20 +0000
1823+++ tests/unittests/history-timeframe-model/CMakeLists.txt 1970-01-01 00:00:00 +0000
1824@@ -1,13 +0,0 @@
1825-find_package(Qt5Core REQUIRED)
1826-find_package(Qt5Sql REQUIRED)
1827-find_package(Qt5Test REQUIRED)
1828-set(TEST tst_HistoryTimeframeModelTests)
1829-add_executable(${TEST} tst_HistoryTimeframeModelTests.cpp)
1830-include_directories(${webbrowser-app_SOURCE_DIR})
1831-target_link_libraries(${TEST}
1832- Qt5::Core
1833- Qt5::Sql
1834- Qt5::Test
1835- webbrowser-app-models
1836-)
1837-add_test(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${TEST})
1838
1839=== removed file 'tests/unittests/history-timeframe-model/tst_HistoryTimeframeModelTests.cpp'
1840--- tests/unittests/history-timeframe-model/tst_HistoryTimeframeModelTests.cpp 2013-08-01 21:42:00 +0000
1841+++ tests/unittests/history-timeframe-model/tst_HistoryTimeframeModelTests.cpp 1970-01-01 00:00:00 +0000
1842@@ -1,160 +0,0 @@
1843-/*
1844- * Copyright 2013 Canonical Ltd.
1845- *
1846- * This file is part of webbrowser-app.
1847- *
1848- * webbrowser-app is free software; you can redistribute it and/or modify
1849- * it under the terms of the GNU General Public License as published by
1850- * the Free Software Foundation; version 3.
1851- *
1852- * webbrowser-app is distributed in the hope that it will be useful,
1853- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1854- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1855- * GNU General Public License for more details.
1856- *
1857- * You should have received a copy of the GNU General Public License
1858- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1859- */
1860-
1861-// Qt
1862-#include <QtTest/QSignalSpy>
1863-#include <QtTest/QtTest>
1864-
1865-// local
1866-#include "history-model.h"
1867-#include "history-timeframe-model.h"
1868-
1869-
1870-class HistoryTimeframeModelTests : public QObject
1871-{
1872- Q_OBJECT
1873-
1874-private:
1875- HistoryModel* model;
1876- HistoryTimeframeModel* timeframe;
1877-
1878-private Q_SLOTS:
1879- void init()
1880- {
1881- model = new HistoryModel;
1882- model->setDatabasePath(":memory:");
1883- timeframe = new HistoryTimeframeModel;
1884- timeframe->setSourceModel(model);
1885- }
1886-
1887- void cleanup()
1888- {
1889- delete timeframe;
1890- delete model;
1891- }
1892-
1893- void shouldBeInitiallyEmpty()
1894- {
1895- QCOMPARE(timeframe->rowCount(), 0);
1896- }
1897-
1898- void shouldNotifyWhenChangingSourceModel()
1899- {
1900- QSignalSpy spy(timeframe, SIGNAL(sourceModelChanged()));
1901- timeframe->setSourceModel(model);
1902- QVERIFY(spy.isEmpty());
1903- HistoryModel* model2 = new HistoryModel;
1904- timeframe->setSourceModel(model2);
1905- QCOMPARE(spy.count(), 1);
1906- QCOMPARE(timeframe->sourceModel(), model2);
1907- timeframe->setSourceModel(0);
1908- QCOMPARE(spy.count(), 2);
1909- QCOMPARE(timeframe->sourceModel(), (HistoryModel*) 0);
1910- delete model2;
1911- }
1912-
1913- void shouldNotifyWhenChangingStart()
1914- {
1915- QSignalSpy spy(timeframe, SIGNAL(startChanged()));
1916- QDateTime start = QDateTime::currentDateTimeUtc();
1917- timeframe->setStart(start);
1918- QCOMPARE(timeframe->start(), start);
1919- QCOMPARE(spy.count(), 1);
1920- timeframe->setStart(start);
1921- QCOMPARE(spy.count(), 1);
1922- QTest::qWait(100);
1923- timeframe->setStart(QDateTime::currentDateTimeUtc());
1924- QCOMPARE(spy.count(), 2);
1925- timeframe->setStart(QDateTime());
1926- QCOMPARE(spy.count(), 3);
1927- }
1928-
1929- void shouldNotifyWhenChangingEnd()
1930- {
1931- QSignalSpy spy(timeframe, SIGNAL(endChanged()));
1932- QDateTime end = QDateTime::currentDateTimeUtc();
1933- timeframe->setEnd(end);
1934- QCOMPARE(timeframe->end(), end);
1935- QCOMPARE(spy.count(), 1);
1936- timeframe->setEnd(end);
1937- QCOMPARE(spy.count(), 1);
1938- QTest::qWait(100);
1939- timeframe->setEnd(QDateTime::currentDateTimeUtc());
1940- QCOMPARE(spy.count(), 2);
1941- timeframe->setEnd(QDateTime());
1942- QCOMPARE(spy.count(), 3);
1943- }
1944-
1945- void shouldMatchAllWhenNoBoundsSet()
1946- {
1947- model->add(QUrl("http://example.org"), "Example Domain", QUrl());
1948- QTest::qWait(100);
1949- model->add(QUrl("http://example.com"), "Example Domain", QUrl());
1950- QCOMPARE(timeframe->rowCount(), 2);
1951- }
1952-
1953- void shouldFilterOutOlderEntries()
1954- {
1955- model->add(QUrl("http://example.org"), "Example Domain", QUrl());
1956- QTest::qWait(100);
1957- QDateTime start = QDateTime::currentDateTimeUtc();
1958- QTest::qWait(100);
1959- model->add(QUrl("http://example.com"), "Example Domain", QUrl());
1960- QCOMPARE(timeframe->rowCount(), 2);
1961- timeframe->setStart(start);
1962- QCOMPARE(timeframe->rowCount(), 1);
1963- QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
1964- QUrl("http://example.com"));
1965- }
1966-
1967- void shouldFilterOutMoreRecentEntries()
1968- {
1969- model->add(QUrl("http://example.org"), "Example Domain", QUrl());
1970- QTest::qWait(100);
1971- QDateTime end = QDateTime::currentDateTimeUtc();
1972- QTest::qWait(100);
1973- model->add(QUrl("http://example.com"), "Example Domain", QUrl());
1974- QCOMPARE(timeframe->rowCount(), 2);
1975- timeframe->setEnd(end);
1976- QCOMPARE(timeframe->rowCount(), 1);
1977- QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
1978- QUrl("http://example.org"));
1979- }
1980-
1981- void shouldFilterOutOlderAndMoreRecentEntries()
1982- {
1983- model->add(QUrl("http://example.org"), "Example Domain", QUrl());
1984- QTest::qWait(100);
1985- QDateTime start = QDateTime::currentDateTimeUtc();
1986- QTest::qWait(100);
1987- model->add(QUrl("http://ubuntu.com"), "Ubuntu", QUrl());
1988- QTest::qWait(100);
1989- QDateTime end = QDateTime::currentDateTimeUtc();
1990- QTest::qWait(100);
1991- model->add(QUrl("http://example.com"), "Example Domain", QUrl());
1992- QCOMPARE(timeframe->rowCount(), 3);
1993- timeframe->setStart(start);
1994- timeframe->setEnd(end);
1995- QCOMPARE(timeframe->rowCount(), 1);
1996- QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
1997- QUrl("http://ubuntu.com"));
1998- }
1999-};
2000-
2001-QTEST_MAIN(HistoryTimeframeModelTests)
2002-#include "tst_HistoryTimeframeModelTests.moc"
2003
2004=== modified file 'tests/unittests/limit-proxy-model/tst_LimitProxyModelTests.cpp'
2005--- tests/unittests/limit-proxy-model/tst_LimitProxyModelTests.cpp 2015-06-11 18:40:30 +0000
2006+++ tests/unittests/limit-proxy-model/tst_LimitProxyModelTests.cpp 2015-12-03 09:02:16 +0000
2007@@ -17,45 +17,92 @@
2008 */
2009
2010 // Qt
2011+#include <QtCore/QAbstractListModel>
2012+#include <QtCore/QStringList>
2013 #include <QtTest/QSignalSpy>
2014 #include <QtTest/QtTest>
2015
2016 // local
2017-#include "domain-utils.h"
2018-#include "history-model.h"
2019-#include "history-timeframe-model.h"
2020 #include "limit-proxy-model.h"
2021-#include "top-sites-model.h"
2022+
2023+class SimpleListModel : public QAbstractListModel {
2024+ Q_OBJECT
2025+
2026+public:
2027+ enum Roles {
2028+ Index = Qt::UserRole + 1,
2029+ String
2030+ };
2031+
2032+ QHash<int, QByteArray> roleNames() const
2033+ {
2034+ static QHash<int, QByteArray> roles;
2035+ if (roles.isEmpty()) {
2036+ roles[Index] = "index";
2037+ roles[String] = "string";
2038+ }
2039+ return roles;
2040+ }
2041+
2042+ int rowCount(const QModelIndex& parent=QModelIndex()) const
2043+ {
2044+ return m_strings.count();
2045+ }
2046+
2047+ QVariant data(const QModelIndex& index, int role) const
2048+ {
2049+ if (!index.isValid()) {
2050+ return QVariant();
2051+ }
2052+ switch (role) {
2053+ case Index:
2054+ return index.row();
2055+ case String:
2056+ return m_strings.at(index.row());
2057+ default:
2058+ return QVariant();
2059+ }
2060+ }
2061+
2062+ void append(const QStringList& strings)
2063+ {
2064+ int index = m_strings.count();
2065+ beginInsertRows(QModelIndex(), index, index + strings.count() - 1);
2066+ m_strings << strings;
2067+ endInsertRows();
2068+ }
2069+
2070+ void remove(int index)
2071+ {
2072+ beginRemoveRows(QModelIndex(), index, index);
2073+ m_strings.removeAt(index);
2074+ endRemoveRows();
2075+ }
2076+
2077+private:
2078+ QStringList m_strings;
2079+};
2080
2081 class LimitProxyModelTests : public QObject
2082 {
2083 Q_OBJECT
2084
2085 private:
2086- HistoryModel* history;
2087- HistoryTimeframeModel* timeframe;
2088- TopSitesModel* topsites;
2089+ SimpleListModel* strings;
2090 LimitProxyModel* model;
2091
2092 private Q_SLOTS:
2093 void init()
2094 {
2095- history = new HistoryModel;
2096- history->setDatabasePath(":memory:");
2097- timeframe = new HistoryTimeframeModel;
2098- timeframe->setSourceModel(history);
2099- topsites = new TopSitesModel;
2100- topsites->setSourceModel(timeframe);
2101+ strings = new SimpleListModel;
2102 model = new LimitProxyModel;
2103- model->setSourceModel(topsites);
2104+ model->setSourceModel(strings);
2105 }
2106
2107 void cleanup()
2108 {
2109 delete model;
2110- delete topsites;
2111- delete timeframe;
2112- delete history;
2113+ delete strings;
2114 }
2115
2116 void shouldBeInitiallyEmpty()
2117@@ -71,38 +118,29 @@
2118 void shouldNotifyWhenChangingSourceModel()
2119 {
2120 QSignalSpy spy(model, SIGNAL(sourceModelChanged()));
2121- model->setSourceModel(topsites);
2122+ model->setSourceModel(strings);
2123 QVERIFY(spy.isEmpty());
2124- TopSitesModel* topsites2 = new TopSitesModel;
2125- model->setSourceModel(topsites2);
2126+ QStringListModel strings2;
2127+ model->setSourceModel(&strings2);
2128 QCOMPARE(spy.count(), 1);
2129- QCOMPARE(model->sourceModel(), topsites2);
2130+ QCOMPARE(model->sourceModel(), &strings2);
2131 model->setSourceModel(0);
2132 QCOMPARE(spy.count(), 2);
2133- QCOMPARE(model->sourceModel(), (TopSitesModel*) 0);
2134- delete topsites2;
2135+ QCOMPARE(model->sourceModel(), (QAbstractItemModel*) 0);
2136 }
2137
2138 void shouldLimitEntriesWithLimitSetBeforePopulating()
2139 {
2140 model->setLimit(2);
2141-
2142- history->add(QUrl("http://example1.org/"), "Example 1 Domain", QUrl());
2143- history->add(QUrl("http://example2.org/"), "Example 2 Domain", QUrl());
2144- history->add(QUrl("http://example3.org/"), "Example 3 Domain", QUrl());
2145-
2146+ strings->append({"a", "b", "c"});
2147 QCOMPARE(model->rowCount(), 2);
2148 QCOMPARE(model->unlimitedRowCount(), 3);
2149 }
2150
2151 void shouldLimitEntriesWithLimitSetAfterPopulating()
2152 {
2153- history->add(QUrl("http://example1.org/"), "Example 1 Domain", QUrl());
2154- history->add(QUrl("http://example2.org/"), "Example 2 Domain", QUrl());
2155- history->add(QUrl("http://example3.org/"), "Example 3 Domain", QUrl());
2156-
2157+ strings->append({"a", "b", "c"});
2158 model->setLimit(2);
2159-
2160 QCOMPARE(model->rowCount(), 2);
2161 QCOMPARE(model->unlimitedRowCount(), 3);
2162 }
2163@@ -110,11 +148,7 @@
2164 void shouldNotLimitEntriesIfLimitIsMinusOne()
2165 {
2166 model->setLimit(-1);
2167-
2168- history->add(QUrl("http://example1.org/"), "Example 1 Domain", QUrl());
2169- history->add(QUrl("http://example2.org/"), "Example 2 Domain", QUrl());
2170- history->add(QUrl("http://example3.org/"), "Example 3 Domain", QUrl());
2171-
2172+ strings->append({"a", "b", "c"});
2173 QCOMPARE(model->unlimitedRowCount(), 3);
2174 QCOMPARE(model->rowCount(), model->unlimitedRowCount());
2175 }
2176@@ -122,11 +156,7 @@
2177 void shouldNotLimitEntriesIfLimitIsGreaterThanRowCount()
2178 {
2179 model->setLimit(4);
2180-
2181- history->add(QUrl("http://example1.org/"), "Example 1 Domain", QUrl());
2182- history->add(QUrl("http://example2.org/"), "Example 2 Domain", QUrl());
2183- history->add(QUrl("http://example3.org/"), "Example 3 Domain", QUrl());
2184-
2185+ strings->append({"a", "b", "c"});
2186 QCOMPARE(model->unlimitedRowCount(), 3);
2187 QCOMPARE(model->rowCount(), model->unlimitedRowCount());
2188 }
2189@@ -134,25 +164,17 @@
2190 void shouldUpdateRowCountAndNotifyAfterAnEntryIsRemoved()
2191 {
2192 model->setLimit(2);
2193+ strings->append({"a", "b", "c", "d"});
2194
2195- qRegisterMetaType<QVector<int> >();
2196 QSignalSpy spyChanged(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
2197 QSignalSpy spyRemoved(model, SIGNAL(rowsRemoved(QModelIndex, int, int)));
2198
2199- history->add(QUrl("http://example1.org/"), "Example 1 Domain", QUrl());
2200- history->add(QUrl("http://example2.org/"), "Example 2 Domain", QUrl());
2201- QTest::qWait(1001);
2202- history->add(QUrl("http://example3.org/"), "Example 3 Domain", QUrl());
2203- QTest::qWait(1001);
2204- history->add(QUrl("http://example4.org/"), "Example 4 Domain", QUrl());
2205-
2206- history->removeEntryByUrl(QUrl("http://example1.org/"));
2207-
2208+ strings->remove(0);
2209 QCOMPARE(spyChanged.count(), 1);
2210- QCOMPARE(spyRemoved.count(), 0);
2211+ QVERIFY(spyRemoved.isEmpty());
2212
2213- QCOMPARE(model->data(model->index(0, 0), HistoryModel::Url).toUrl(), QUrl("http://example2.org/"));
2214- QCOMPARE(model->data(model->index(1, 0), HistoryModel::Url).toUrl(), QUrl("http://example3.org/"));
2215+ QCOMPARE(model->data(model->index(0, 0), SimpleListModel::String).toString(), QString("b"));
2216+ QCOMPARE(model->data(model->index(1, 0), SimpleListModel::String).toString(), QString("c"));
2217
2218 QCOMPARE(model->unlimitedRowCount(), 3);
2219 QCOMPARE(model->rowCount(), 2);
2220@@ -160,13 +182,10 @@
2221
2222 void shouldGetItemWithCorrectValues()
2223 {
2224- history->add(QUrl("http://example1.org/"), "Example 1 Domain", QUrl());
2225-
2226+ strings->append({"a"});
2227 QVariantMap item = model->get(0);
2228 QHash<int, QByteArray> roles = model->roleNames();
2229-
2230 QCOMPARE(roles.count(), item.count());
2231-
2232 Q_FOREACH(int role, roles.keys()) {
2233 QString roleName = QString::fromUtf8(roles.value(role));
2234 QCOMPARE(model->data(model->index(0, 0), role), item.value(roleName));
2235
2236=== modified file 'tests/unittests/qml/CMakeLists.txt'
2237--- tests/unittests/qml/CMakeLists.txt 2015-10-06 09:48:38 +0000
2238+++ tests/unittests/qml/CMakeLists.txt 2015-12-03 09:02:16 +0000
2239@@ -22,14 +22,11 @@
2240 ${webbrowser-app_SOURCE_DIR}/bookmarks-folderlist-model.cpp
2241 ${webbrowser-app_SOURCE_DIR}/file-operations.cpp
2242 ${webbrowser-app_SOURCE_DIR}/history-model.cpp
2243- ${webbrowser-app_SOURCE_DIR}/history-lastvisitdate-model.cpp
2244 ${webbrowser-app_SOURCE_DIR}/history-lastvisitdatelist-model.cpp
2245- ${webbrowser-app_SOURCE_DIR}/history-timeframe-model.cpp
2246 ${webbrowser-app_SOURCE_DIR}/limit-proxy-model.cpp
2247 ${webbrowser-app_SOURCE_DIR}/searchengine.cpp
2248 ${webbrowser-app_SOURCE_DIR}/tabs-model.cpp
2249 ${webbrowser-app_SOURCE_DIR}/text-search-filter-model.cpp
2250- ${webbrowser-app_SOURCE_DIR}/top-sites-model.cpp
2251 tst_QmlTests.cpp
2252 )
2253 add_executable(${TEST} ${SOURCES})
2254
2255=== modified file 'tests/unittests/qml/tst_HistoryViewWide.qml'
2256--- tests/unittests/qml/tst_HistoryViewWide.qml 2015-11-17 17:16:37 +0000
2257+++ tests/unittests/qml/tst_HistoryViewWide.qml 2015-12-03 09:02:16 +0000
2258@@ -19,7 +19,6 @@
2259 import QtQuick 2.4
2260 import QtTest 1.0
2261 import Ubuntu.Components 1.3
2262-import Ubuntu.Components.ListItems 1.3 as ListItems
2263 import webbrowserapp.private 0.1
2264 import webbrowsertest.private 0.1
2265 import "../../../src/app/webbrowser"
2266
2267=== modified file 'tests/unittests/qml/tst_QmlTests.cpp'
2268--- tests/unittests/qml/tst_QmlTests.cpp 2015-10-22 15:07:26 +0000
2269+++ tests/unittests/qml/tst_QmlTests.cpp 2015-12-03 09:02:16 +0000
2270@@ -30,14 +30,11 @@
2271 #include "favicon-fetcher.h"
2272 #include "file-operations.h"
2273 #include "history-model.h"
2274-#include "history-timeframe-model.h"
2275-#include "history-lastvisitdate-model.h"
2276 #include "history-lastvisitdatelist-model.h"
2277 #include "limit-proxy-model.h"
2278 #include "searchengine.h"
2279 #include "tabs-model.h"
2280 #include "text-search-filter-model.h"
2281-#include "top-sites-model.h"
2282
2283 static QObject* FileOperations_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)
2284 {
2285@@ -193,12 +190,9 @@
2286 qmlRegisterSingletonType<BookmarksModel>(browserUri, 0, 1, "BookmarksModel", BookmarksModel_singleton_factory);
2287 qmlRegisterType<BookmarksFolderListModel>(browserUri, 0, 1, "BookmarksFolderListModel");
2288 qmlRegisterSingletonType<HistoryModel>(browserUri, 0, 1, "HistoryModel", HistoryModel_singleton_factory);
2289- qmlRegisterType<HistoryTimeframeModel>(browserUri, 0, 1, "HistoryTimeframeModel");
2290 qmlRegisterType<HistoryLastVisitDateListModel>(browserUri, 0, 1, "HistoryLastVisitDateListModel");
2291- qmlRegisterType<HistoryLastVisitDateModel>(browserUri, 0, 1, "HistoryLastVisitDateModel");
2292 qmlRegisterType<LimitProxyModel>(browserUri, 0, 1, "LimitProxyModel");
2293 qmlRegisterType<TextSearchFilterModel>(browserUri, 0, 1, "TextSearchFilterModel");
2294- qmlRegisterType<TopSitesModel>(browserUri, 0, 1, "TopSitesModel");
2295 qmlRegisterSingletonType<FileOperations>(browserUri, 0, 1, "FileOperations", FileOperations_singleton_factory);
2296
2297 const char* testUri = "webbrowsertest.private";
2298
2299=== removed directory 'tests/unittests/top-sites-model'
2300=== removed file 'tests/unittests/top-sites-model/CMakeLists.txt'
2301--- tests/unittests/top-sites-model/CMakeLists.txt 2015-06-22 10:29:20 +0000
2302+++ tests/unittests/top-sites-model/CMakeLists.txt 1970-01-01 00:00:00 +0000
2303@@ -1,13 +0,0 @@
2304-find_package(Qt5Core REQUIRED)
2305-find_package(Qt5Sql REQUIRED)
2306-find_package(Qt5Test REQUIRED)
2307-set(TEST tst_TopSitesModelTests)
2308-add_executable(${TEST} tst_TopSitesModelTests.cpp)
2309-include_directories(${webbrowser-app_SOURCE_DIR})
2310-target_link_libraries(${TEST}
2311- Qt5::Core
2312- Qt5::Sql
2313- Qt5::Test
2314- webbrowser-app-models
2315-)
2316-add_test(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${TEST} -xunitxml -o ${TEST}.xml)
2317
2318=== removed file 'tests/unittests/top-sites-model/tst_TopSitesModelTests.cpp'
2319--- tests/unittests/top-sites-model/tst_TopSitesModelTests.cpp 2015-05-28 13:56:52 +0000
2320+++ tests/unittests/top-sites-model/tst_TopSitesModelTests.cpp 1970-01-01 00:00:00 +0000
2321@@ -1,108 +0,0 @@
2322-/*
2323- * Copyright 2015 Canonical Ltd.
2324- *
2325- * This file is part of webbrowser-app.
2326- *
2327- * webbrowser-app is free software; you can redistribute it and/or modify
2328- * it under the terms of the GNU General Public License as published by
2329- * the Free Software Foundation; version 3.
2330- *
2331- * webbrowser-app is distributed in the hope that it will be useful,
2332- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2333- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2334- * GNU General Public License for more details.
2335- *
2336- * You should have received a copy of the GNU General Public License
2337- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2338- */
2339-
2340-// Qt
2341-#include <QtTest/QSignalSpy>
2342-#include <QtTest/QtTest>
2343-
2344-// local
2345-#include "history-model.h"
2346-#include "history-timeframe-model.h"
2347-#include "top-sites-model.h"
2348-
2349-class TopSitesModelTests : public QObject
2350-{
2351- Q_OBJECT
2352-
2353-private:
2354- HistoryModel* model;
2355- HistoryTimeframeModel* timeframe;
2356- TopSitesModel* topsites;
2357-
2358-private Q_SLOTS:
2359- void init()
2360- {
2361- model = new HistoryModel;
2362- model->setDatabasePath(":memory:");
2363- timeframe = new HistoryTimeframeModel;
2364- timeframe->setSourceModel(model);
2365- topsites = new TopSitesModel;
2366- topsites->setSourceModel(timeframe);
2367- }
2368-
2369- void cleanup()
2370- {
2371- delete topsites;
2372- delete timeframe;
2373- delete model;
2374- }
2375-
2376- void shouldBeInitiallyEmpty()
2377- {
2378- QCOMPARE(topsites->rowCount(), 0);
2379- }
2380-
2381- void shouldNotifyWhenChangingSourceModel()
2382- {
2383- QSignalSpy spy(topsites, SIGNAL(sourceModelChanged()));
2384- topsites->setSourceModel(timeframe);
2385- QVERIFY(spy.isEmpty());
2386- HistoryTimeframeModel* timeframe2 = new HistoryTimeframeModel;
2387- topsites->setSourceModel(timeframe2);
2388- QCOMPARE(spy.count(), 1);
2389- QCOMPARE(topsites->sourceModel(), timeframe2);
2390- topsites->setSourceModel(0);
2391- QCOMPARE(spy.count(), 2);
2392- QCOMPARE(topsites->sourceModel(), (HistoryTimeframeModel*) 0);
2393- delete timeframe2;
2394- }
2395-
2396- void shouldMatchAllWhenNothingIsHidden()
2397- {
2398- QSignalSpy spy(topsites, SIGNAL(countChanged()));
2399- model->add(QUrl("http://example.org"), "Example Domain", QUrl());
2400- model->add(QUrl("http://example.com"), "Example Domain", QUrl());
2401- QCOMPARE(spy.count(), 2);
2402- QCOMPARE(topsites->rowCount(), 2);
2403- }
2404-
2405- void shouldFilterOutHiddenUrls()
2406- {
2407- QSignalSpy spy(topsites, SIGNAL(countChanged()));
2408- model->add(QUrl("http://example.org"), "Example Domain", QUrl());
2409- model->add(QUrl("http://example.com"), "Example Domain", QUrl());
2410- QCOMPARE(spy.count(), 2);
2411- QCOMPARE(topsites->rowCount(), 2);
2412- model->hide(QUrl("http://example.org"));
2413- QCOMPARE(spy.count(), 3);
2414- QCOMPARE(topsites->rowCount(), 1);
2415- QCOMPARE(topsites->data(topsites->index(0, 0), HistoryModel::Url).toUrl(), QUrl("http://example.com"));
2416- }
2417-
2418- void shouldBeSortedByVisits()
2419- {
2420- model->add(QUrl("http://example.org/"), "Example Domain", QUrl());
2421- model->add(QUrl("http://ubuntu.com/"), "Ubuntu", QUrl());
2422- model->add(QUrl("http://ubuntu.com/"), "Ubuntu", QUrl());
2423- QCOMPARE(model->data(model->index(0, 0), HistoryModel::Domain).toString(), QString("ubuntu.com"));
2424- QCOMPARE(model->data(model->index(1, 0), HistoryModel::Domain).toString(), QString("example.org"));
2425- }
2426-};
2427-
2428-QTEST_MAIN(TopSitesModelTests)
2429-#include "tst_TopSitesModelTests.moc"

Subscribers

People subscribed via source and target branches

to status/vote changes: