Merge lp:~zsombi/ubuntu-ui-toolkit/oneUbuntuListView into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Merged
Approved by: Zsombor Egri
Approved revision: 1777
Merged at revision: 1781
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/oneUbuntuListView
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 697 lines (+311/-84)
12 files modified
components.api (+2/-1)
examples/ubuntu-ui-toolkit-gallery/MainPage.qml (+5/-27)
examples/ubuntu-ui-toolkit-gallery/UbuntuListViews.qml (+7/-3)
src/Ubuntu/Components/1.3/UbuntuListView.qml (+178/-9)
src/Ubuntu/Components/1.3/UbuntuListView11.qdoc (+0/-38)
src/Ubuntu/Components/ComponentModule.pro (+0/-2)
src/Ubuntu/Components/Themes/Ambiance/1.3/PullToRefreshStyle.qml (+4/-2)
src/Ubuntu/Components/qmldir (+1/-1)
tests/autopilot/ubuntuuitoolkit/__init__.py (+2/-0)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py (+3/-1)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_ubuntulistview.py (+4/-0)
tests/unit_x11/tst_components/tst_ubuntulistview13.qml (+105/-0)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/oneUbuntuListView
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Cris Dywan Approve
Review via email: mp+280704@code.launchpad.net

Commit message

Move UbuntuListView 1.3 code into one single file

Description of the change

Move UbuntuListView 1.3 code into one single file

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
Cris Dywan (kalikiana) wrote :

Looks pretty straightforward, merge of two parts of the same class. Thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1776. By Zsombor Egri

rename UbuntuListView file to match the type; add 1.3 specific UbuntuListView

1777. By Zsombor Egri

sync staging

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 'components.api'
2--- components.api 2015-12-17 09:15:45 +0000
3+++ components.api 2015-12-17 13:53:59 +0000
4@@ -1561,7 +1561,8 @@
5 property int expandedIndex
6 Ubuntu.Components.UbuntuListView 1.1: UbuntuListView
7 readonly property PullToRefresh pullToRefresh
8-Ubuntu.Components.UbuntuListView 1.3: UbuntuListView
9+Ubuntu.Components.UbuntuListView 1.3: ListView
10+ property int expandedIndex
11 readonly property PullToRefresh pullToRefresh
12 Ubuntu.Components.UbuntuNumberAnimation 1.0 0.1: PropertyAnimation
13 Ubuntu.Components.UbuntuNumberAnimation 1.3: PropertyAnimation
14
15=== modified file 'examples/ubuntu-ui-toolkit-gallery/MainPage.qml'
16--- examples/ubuntu-ui-toolkit-gallery/MainPage.qml 2015-12-15 14:20:33 +0000
17+++ examples/ubuntu-ui-toolkit-gallery/MainPage.qml 2015-12-17 13:53:59 +0000
18@@ -101,36 +101,14 @@
19
20 delegate: ListItem {
21 objectName: model.objectName
22- contentItem {
23- anchors.leftMargin: units.gu(2)
24- anchors.rightMargin: units.gu(2)
25- }
26 enabled: source != ""
27 // Used by Autopilot
28 property string text: label
29 onClicked: widgetList.currentIndex = index
30- Label {
31- id: labelItem
32- anchors {
33- fill: parent
34- rightMargin: units.gu(4)
35- }
36- text: label
37- verticalAlignment: Text.AlignVCenter
38- }
39- Icon {
40- name: "next"
41- width: units.gu(2)
42- height: units.gu(2)
43- anchors {
44- verticalCenter: parent.verticalCenter
45- right: parent.right
46- }
47- }
48- }
49- highlight: Rectangle {
50- color: theme.palette.selected.background
51- }
52- highlightMoveDuration: 0
53+ ListItemLayout {
54+ title.text: label
55+ ProgressionSlot {}
56+ }
57+ }
58 }
59 }
60
61=== modified file 'examples/ubuntu-ui-toolkit-gallery/UbuntuListViews.qml'
62--- examples/ubuntu-ui-toolkit-gallery/UbuntuListViews.qml 2015-04-29 07:21:29 +0000
63+++ examples/ubuntu-ui-toolkit-gallery/UbuntuListViews.qml 2015-12-17 13:53:59 +0000
64@@ -16,7 +16,6 @@
65
66 import QtQuick 2.4
67 import Ubuntu.Components 1.3
68-import Ubuntu.Components.ListItems 1.3 as ListItem
69
70 Template {
71 objectName: "ubuntuListViewTemplate"
72@@ -52,9 +51,14 @@
73 height: units.gu(36)
74 model: fruitModel
75 clip: true
76+ currentIndex: -1
77
78- delegate: ListItem.Standard {
79- text: name
80+ delegate: ListItem {
81+ ListItemLayout {
82+ title.text: name
83+ }
84+ // to enable highlight
85+ onClicked: ListView.view.currentIndex = index
86 }
87
88 pullToRefresh {
89
90=== removed file 'src/Ubuntu/Components/1.3/UbuntuListView.qml'
91--- src/Ubuntu/Components/1.3/UbuntuListView.qml 2015-04-29 07:21:29 +0000
92+++ src/Ubuntu/Components/1.3/UbuntuListView.qml 1970-01-01 00:00:00 +0000
93@@ -1,143 +0,0 @@
94-/*
95- * Copyright 2014 Canonical Ltd.
96- *
97- * This program is free software; you can redistribute it and/or modify
98- * it under the terms of the GNU Lesser General Public License as published by
99- * the Free Software Foundation; version 3.
100- *
101- * This program is distributed in the hope that it will be useful,
102- * but WITHOUT ANY WARRANTY; without even the implied warranty of
103- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
104- * GNU Lesser General Public License for more details.
105- *
106- * You should have received a copy of the GNU Lesser General Public License
107- * along with this program. If not, see <http://www.gnu.org/licenses/>.
108- */
109-
110-import QtQuick 2.4
111-import Ubuntu.Components 1.3 as Toolkit
112-
113-/*!
114- \qmltype UbuntuListView
115- \inqmlmodule Ubuntu.Components 1.1
116- \ingroup ubuntu
117- \brief A ListView with special features tailored for a look and feel fitting the
118- Ubuntu Touch platform.
119- The UbuntuListView works just like a regular ListView, but it adds special features
120- such as expanding/collapsing items (when used together with the Expandable item).
121- It provides features like automatically positioning the expanding item when it
122- expands and collapsing it again when the user taps outside of it.
123-
124- Examples:
125- \qml
126- import Ubuntu.Components 1.3
127- import Ubuntu.Components.ListItems 1.3 as ListItem
128-
129- Item {
130- ListModel {
131- id: listModel
132- }
133-
134- UbuntuListView {
135- id: ubuntuListView
136- anchors { left: parent.left; right: parent.right }
137- height: units.gu(24)
138- model: listModel
139-
140- delegate: ListItem.Expandable {
141- id: expandingItem
142-
143- expandedHeight: units.gu(30)
144-
145- onClicked: {
146- ubuntuListView.expandedIndex = index;
147- }
148- }
149- }
150- }
151- \endqml
152-*/
153-
154-ListView {
155- id: root
156-
157- /*!
158- The index of the currently expanded item. -1 if no item is expanded.
159- */
160- property int expandedIndex: -1
161-
162- QtObject {
163- id: priv
164-
165- function positionViewAtIndexAnimated(expandedIndex) {
166- animation.from = root.contentY;
167- root.currentIndex = expandedIndex;
168- if (expandedIndex == root.count - 1) {
169- root.positionViewAtIndex(expandedIndex, ListView.End);
170- } else {
171- root.positionViewAtIndex(expandedIndex + 1, ListView.End);
172- }
173-
174- var effectiveExpandedHeight = Math.min(root.currentItem.expandedHeight, root.height - root.currentItem.collapsedHeight);
175- if (root.contentY - root.originY == 0) {
176- if (((root.currentIndex + 1) * root.currentItem.collapsedHeight) + effectiveExpandedHeight > root.height) {
177- animation.to = ((root.currentIndex + 1) * root.currentItem.collapsedHeight + effectiveExpandedHeight) - root.height + root.originY
178- } else {
179- animation.to = root.originY
180- }
181- } else {
182- animation.to = root.contentY + (effectiveExpandedHeight - root.currentItem.collapsedHeight);
183- }
184- animation.start();
185- }
186-
187- function requestFocus(reason) {
188- // lookup for the currentItem, and if it is a FocusScope, focus the view
189- // this will also focus the currentItem
190- if (root.currentItem && root.currentItem.hasOwnProperty("activeFocusOnPress")) {
191- root.forceActiveFocus(reason);
192- }
193- }
194- }
195-
196- focus: true
197-
198- /*!
199- \internal
200- Grab focus when moved, flicked or clicked
201- */
202- onMovementStarted: priv.requestFocus(Qt.MouseFocusReason)
203- onFlickStarted: priv.requestFocus(Qt.MouseFocusReason)
204- Toolkit.Mouse.onClicked: priv.requestFocus(Qt.MouseFocusReason)
205-
206- /*!
207- Expand the item at the given index.
208- */
209- onExpandedIndexChanged: {
210- if (expandedIndex < 0) {
211- return;
212- }
213- priv.positionViewAtIndexAnimated(expandedIndex, ListView.End)
214- }
215-
216- UbuntuNumberAnimation {
217- id: animation
218- target: root
219- property: "contentY"
220- }
221-
222- MouseArea {
223- parent: contentItem
224- anchors.fill: parent
225- z: 2
226- enabled: root.expandedIndex != -1
227- onClicked: root.expandedIndex = -1;
228- }
229-
230- // animate move displaced
231- moveDisplaced: Transition {
232- UbuntuNumberAnimation {
233- properties: "x,y"
234- }
235- }
236-}
237
238=== renamed file 'src/Ubuntu/Components/1.3/UbuntuListView11.qml' => 'src/Ubuntu/Components/1.3/UbuntuListView.qml'
239--- src/Ubuntu/Components/1.3/UbuntuListView11.qml 2015-04-25 08:54:58 +0000
240+++ src/Ubuntu/Components/1.3/UbuntuListView.qml 2015-12-17 13:53:59 +0000
241@@ -1,5 +1,5 @@
242 /*
243- * Copyright 2014 Canonical Ltd.
244+ * Copyright 2015 Canonical Ltd.
245 *
246 * This program is free software; you can redistribute it and/or modify
247 * it under the terms of the GNU Lesser General Public License as published by
248@@ -15,19 +15,188 @@
249 */
250
251 import QtQuick 2.4
252-
253-// documentation in UbuntuListView11.qdoc
254-UbuntuListView {
255-
256- /*!
257- \internal
258- \qmlproperty PullToRefresh pullToRefresh
259+import Ubuntu.Components 1.3 as Toolkit
260+
261+/*!
262+ \qmltype UbuntuListView
263+ \inqmlmodule Ubuntu.Components 1.1
264+ \ingroup ubuntu
265+ \inherits ListView
266+ \brief A ListView with special features tailored for a look and feel fitting the
267+ Ubuntu Touch platform.
268+ The UbuntuListView works just like a regular ListView, but it adds special features
269+ such as expanding/collapsing items (when used together with the Expandable item).
270+ It provides features like automatically positioning the expanding item when it
271+ expands and collapsing it again when the user taps outside of it.
272+
273+ Examples:
274+ \qml
275+ import Ubuntu.Components 1.3
276+ import Ubuntu.Components.ListItems 1.3 as ListItem
277+
278+ Item {
279+ ListModel {
280+ id: listModel
281+ }
282+
283+ UbuntuListView {
284+ id: ubuntuListView
285+ anchors { left: parent.left; right: parent.right }
286+ height: units.gu(24)
287+ model: listModel
288+
289+ delegate: ListItem.Expandable {
290+ id: expandingItem
291+
292+ expandedHeight: units.gu(30)
293+
294+ onClicked: {
295+ ubuntuListView.expandedIndex = index;
296+ }
297+ }
298+ }
299+ }
300+ \endqml
301+*/
302+
303+ListView {
304+ id: root
305+
306+ /*!
307+ \deprecated
308+ The index of the currently expanded item. -1 if no item is expanded.
309+ \b {THIS PROPERTY IS DEPRECATED. USE THE NEW ListItem TO HANDLE EXPANSION}
310+ */
311+ property int expandedIndex: -1
312+
313+ /*!
314+ \qmlproperty pullToRefresh UbuntuListView::pullToRefresh
315+ \readonly
316+ \since Ubuntu.Components 1.1
317+
318+ Attached PullToRefresh to control manual model refresh. The component is disabled
319+ by default.
320+
321+ \qml
322+ import QtQuick 2.4
323+ import Ubuntu.Components 1.3
324+
325+ UbuntuListView {
326+ width: units.gu(40)
327+ height: units.gu(71)
328+ model: XmlListModel {
329+ source: "http://feeds.reuters.com/reuters/topNews"
330+ query: "/rss/channel/item"
331+ XmlRole { name: "title"; query: "title/string()" }
332+ }
333+ // let refresh control know when the refresh gets completed
334+ pullToRefresh {
335+ enable: true
336+ refreshing: model.status === XmlListModel.Loading
337+ onRefresh: model.reload()
338+ }
339+ delegate: ListItem {
340+ ListItemLayout {
341+ title.text: modelData
342+ }
343+ onClicked: {
344+ ListView.view.model.reload();
345+ }
346+ }
347+ }
348+ \endqml
349 */
350- property alias pullToRefresh: refreshItem
351+ readonly property alias pullToRefresh: refreshItem
352
353 PullToRefresh {
354 objectName: "listview_pulltorefresh"
355 id: refreshItem
356 enabled: false
357 }
358+
359+ QtObject {
360+ id: priv
361+
362+ function positionViewAtIndexAnimated(expandedIndex) {
363+ animation.from = root.contentY;
364+ root.currentIndex = expandedIndex;
365+ if (expandedIndex == root.count - 1) {
366+ root.positionViewAtIndex(expandedIndex, ListView.End);
367+ } else {
368+ root.positionViewAtIndex(expandedIndex + 1, ListView.End);
369+ }
370+
371+ var effectiveExpandedHeight = Math.min(root.currentItem.expandedHeight, root.height - root.currentItem.collapsedHeight);
372+ if (root.contentY - root.originY == 0) {
373+ if (((root.currentIndex + 1) * root.currentItem.collapsedHeight) + effectiveExpandedHeight > root.height) {
374+ animation.to = ((root.currentIndex + 1) * root.currentItem.collapsedHeight + effectiveExpandedHeight) - root.height + root.originY
375+ } else {
376+ animation.to = root.originY
377+ }
378+ } else {
379+ animation.to = root.contentY + (effectiveExpandedHeight - root.currentItem.collapsedHeight);
380+ }
381+ animation.start();
382+ }
383+
384+ function requestFocus(reason) {
385+ // lookup for the currentItem, and if it is a FocusScope, focus the view
386+ // this will also focus the currentItem
387+ if (root.currentItem && root.currentItem.hasOwnProperty("activeFocusOnPress")) {
388+ // is the currentItem a ListItem?
389+ if (QuickUtils.inherits(root.currentItem, "UCListItem")) {
390+ root.currentItem.requestFocus(reason);
391+ } else {
392+ root.forceActiveFocus(reason);
393+ }
394+ }
395+ }
396+ }
397+
398+ focus: true
399+
400+ /*!
401+ \internal
402+ Grab focus when moved, flicked or clicked
403+ */
404+ onMovementStarted: priv.requestFocus(Qt.MouseFocusReason)
405+ onFlickStarted: priv.requestFocus(Qt.MouseFocusReason)
406+ Toolkit.Mouse.onClicked: priv.requestFocus(Qt.MouseFocusReason)
407+
408+ /*!
409+ Expand the item at the given index.
410+ */
411+ onExpandedIndexChanged: {
412+ if (expandedIndex < 0) {
413+ return;
414+ }
415+ priv.positionViewAtIndexAnimated(expandedIndex, ListView.End)
416+ }
417+
418+ UbuntuNumberAnimation {
419+ id: animation
420+ target: root
421+ property: "contentY"
422+ }
423+
424+ MouseArea {
425+ parent: contentItem
426+ anchors.fill: parent
427+ z: 2
428+ enabled: root.expandedIndex != -1
429+ onClicked: root.expandedIndex = -1;
430+ }
431+
432+ // animate move displaced
433+ moveDisplaced: Transition {
434+ UbuntuNumberAnimation {
435+ properties: "x,y"
436+ }
437+ }
438+
439+ // highlight current item
440+ highlight: Rectangle {
441+ color: theme.palette.selected.background
442+ }
443+ highlightMoveDuration: 0
444 }
445
446=== removed file 'src/Ubuntu/Components/1.3/UbuntuListView11.qdoc'
447--- src/Ubuntu/Components/1.3/UbuntuListView11.qdoc 2015-04-25 08:54:58 +0000
448+++ src/Ubuntu/Components/1.3/UbuntuListView11.qdoc 1970-01-01 00:00:00 +0000
449@@ -1,38 +0,0 @@
450-/*!
451- \qmlproperty pullToRefresh UbuntuListView::pullToRefresh
452- \readonly
453- \since Ubuntu.Components 1.1
454-
455- Attached PullToRefresh to control manual model refresh. The component is disabled
456- by default.
457-
458- \qml
459- import QtQuick 2.4
460- import Ubuntu.Components 1.2
461- import Ubuntu.Components.ListItems 1.0
462-
463- UbuntuListView {
464- width: units.gu(40)
465- height: units.gu(71)
466- model: XmlListModel {
467- source: "http://feeds.reuters.com/reuters/topNews"
468- query: "/rss/channel/item"
469- XmlRole { name: "title"; query: "title/string()" }
470- }
471- // let refresh control know when the refresh gets completed
472- pullToRefresh {
473- enable: true
474- refreshing: model.status === XmlListModel.Loading
475- onRefresh: model.reload()
476- }
477- delegate: ListItem.Standard {
478- width: ListView.view.width
479- height: units.gu(5)
480- text: modelData
481- onClicked: {
482- ListView.view.model.reload();
483- }
484- }
485- }
486- \endqml
487- */
488
489=== modified file 'src/Ubuntu/Components/ComponentModule.pro'
490--- src/Ubuntu/Components/ComponentModule.pro 2015-12-17 09:13:29 +0000
491+++ src/Ubuntu/Components/ComponentModule.pro 2015-12-17 13:53:59 +0000
492@@ -124,7 +124,6 @@
493 1.3/ToolbarItems.qml \
494 1.3/tree.js \
495 1.3/UbuntuColors.qml \
496- 1.3/UbuntuListView11.qml \
497 1.3/UbuntuListView.qml \
498 1.3/UbuntuNumberAnimation.qml \
499 1.3/ListItemPopover.qml \
500@@ -136,7 +135,6 @@
501
502 OTHER_FILES+= qmldir \
503 1.3/CrossFadeImage.qdoc \
504- 1.3/UbuntuListView11.qdoc \
505 1.3/PageHeadConfiguration.qdoc \
506 1.3/MainView.qdoc \
507 1.3/Icon.qdoc
508
509=== modified file 'src/Ubuntu/Components/Themes/Ambiance/1.3/PullToRefreshStyle.qml'
510--- src/Ubuntu/Components/Themes/Ambiance/1.3/PullToRefreshStyle.qml 2015-12-11 08:38:42 +0000
511+++ src/Ubuntu/Components/Themes/Ambiance/1.3/PullToRefreshStyle.qml 2015-12-17 13:53:59 +0000
512@@ -92,8 +92,10 @@
513 }
514
515 Component.onDestruction: {
516- rootItem.__propagated.header.visibleChanged.disconnect(fixTopMargin);
517- rootItem.__propagated.header.heightChanged.disconnect(fixTopMargin);
518+ if (rootItem && rootItem.__propagated && rootItem.__propagated.header) {
519+ rootItem.__propagated.header.visibleChanged.disconnect(fixTopMargin);
520+ rootItem.__propagated.header.heightChanged.disconnect(fixTopMargin);
521+ }
522 }
523
524 function fixTopMargin() {
525
526=== modified file 'src/Ubuntu/Components/qmldir'
527--- src/Ubuntu/Components/qmldir 2015-12-17 09:13:29 +0000
528+++ src/Ubuntu/Components/qmldir 2015-12-17 13:53:59 +0000
529@@ -130,7 +130,7 @@
530 OrientationHelper 1.3 1.3/OrientationHelper.qml
531 UbuntuNumberAnimation 1.3 1.3/UbuntuNumberAnimation.qml
532 PullToRefresh 1.3 1.3/PullToRefresh.qml
533-UbuntuListView 1.3 1.3/UbuntuListView11.qml
534+UbuntuListView 1.3 1.3/UbuntuListView.qml
535 Captions 1.3 1.3/Captions.qml
536 internal ColorUtils 1.3/colorUtils.js
537 DateUtils 1.3 1.3/dateUtils.js
538
539=== modified file 'tests/autopilot/ubuntuuitoolkit/__init__.py'
540--- tests/autopilot/ubuntuuitoolkit/__init__.py 2015-05-28 15:23:13 +0000
541+++ tests/autopilot/ubuntuuitoolkit/__init__.py 2015-12-17 13:53:59 +0000
542@@ -48,6 +48,7 @@
543 'ToolkitException',
544 'ubuntu_scenarios',
545 'UbuntuListView11',
546+ 'UbuntuListView',
547 'UbuntuUIToolkitCustomProxyObjectBase',
548 ]
549
550@@ -86,4 +87,5 @@
551 ToolkitException,
552 UbuntuUIToolkitCustomProxyObjectBase,
553 UbuntuListView11,
554+ UbuntuListView,
555 )
556
557=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py'
558--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py 2015-09-30 14:46:48 +0000
559+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py 2015-12-17 13:53:59 +0000
560@@ -44,6 +44,7 @@
561 'Toolbar',
562 'ToolkitException',
563 'UbuntuListView11',
564+ 'UbuntuListView',
565 'UbuntuUIToolkitCustomProxyObjectBase',
566 ]
567
568@@ -90,5 +91,6 @@
569 from ubuntuuitoolkit._custom_proxy_objects._textfield import TextField
570 from ubuntuuitoolkit._custom_proxy_objects._toolbar import Toolbar
571 from ubuntuuitoolkit._custom_proxy_objects._ubuntulistview import (
572- UbuntuListView11
573+ UbuntuListView11,
574+ UbuntuListView,
575 )
576
577=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_ubuntulistview.py'
578--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_ubuntulistview.py 2015-09-22 15:56:35 +0000
579+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_ubuntulistview.py 2015-12-17 13:53:59 +0000
580@@ -45,3 +45,7 @@
581 refresh.wait_for_refresh()
582 return True
583 return False
584+
585+
586+class UbuntuListView(UbuntuListView11):
587+ """Autopilot helper for the UbuntuListView 1.3."""
588
589=== added file 'tests/unit_x11/tst_components/tst_ubuntulistview13.qml'
590--- tests/unit_x11/tst_components/tst_ubuntulistview13.qml 1970-01-01 00:00:00 +0000
591+++ tests/unit_x11/tst_components/tst_ubuntulistview13.qml 2015-12-17 13:53:59 +0000
592@@ -0,0 +1,105 @@
593+/*
594+ * Copyright 2014 Canonical Ltd.
595+ *
596+ * This program is free software; you can redistribute it and/or modify
597+ * it under the terms of the GNU Lesser General Public License as published by
598+ * the Free Software Foundation; version 3.
599+ *
600+ * This program is distributed in the hope that it will be useful,
601+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
602+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
603+ * GNU Lesser General Public License for more details.
604+ *
605+ * You should have received a copy of the GNU Lesser General Public License
606+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
607+ */
608+
609+import QtQuick 2.4
610+import QtTest 1.0
611+import Ubuntu.Test 1.0
612+import Ubuntu.Components 1.3
613+
614+Item {
615+ width: units.gu(40)
616+ height: units.gu(60)
617+
618+ ListModel {
619+ id: dummyModel
620+ Component.onCompleted: {
621+ reload();
622+ }
623+ function reload() {
624+ clear();
625+ for (var i = 0; i < 20; ++i) {
626+ dummyModel.append({idx: i});
627+ }
628+ }
629+ }
630+
631+ // timer used to simulate the model refresh
632+ Timer {
633+ id: refreshTimer
634+ interval: 500
635+ onTriggered: {
636+ dummyModel.reload();
637+ }
638+ }
639+
640+ UbuntuListView {
641+ id: ubuntuListView
642+ anchors.fill: parent
643+ clip: true
644+ model: dummyModel
645+
646+ pullToRefresh {
647+ refreshing: refreshTimer.running
648+ onRefresh: refreshTimer.restart()
649+ }
650+
651+ delegate: ListItem {
652+ id: expandable
653+ Label { text: "item " + index }
654+ }
655+ }
656+
657+ UbuntuTestCase {
658+ name: "UbuntuListView"
659+ when: windowShown
660+
661+ SignalSpy {
662+ id: refreshSpy
663+ signalName: "onRefresh"
664+ }
665+
666+ function initTestCase() {
667+ tryCompare(dummyModel, "count", 20);
668+ }
669+
670+ function init() {
671+ waitForRendering(ubuntuListView, 1000);
672+ }
673+
674+ function cleanup() {
675+ // scroll the ListView back to top
676+ ubuntuListView.positionViewAtIndex(0, ListView.Beginning);
677+ refreshSpy.clear();
678+ refreshSpy.target = null;
679+ ubuntuListView.pullToRefresh.enabled = false;
680+ }
681+
682+ function test_0_defaults() {
683+ verify(ubuntuListView.hasOwnProperty("pullToRefresh"), "PullToRefresh is missing");
684+ compare(ubuntuListView.pullToRefresh.enabled, false, "PullToRefresh functionality is disabled by default");
685+ }
686+
687+ function test_pullToRefresh_manual_refresh() {
688+ ubuntuListView.pullToRefresh.enabled = true;
689+ refreshSpy.target = ubuntuListView.pullToRefresh
690+ var x = ubuntuListView.width / 2;
691+ mouseDrag(ubuntuListView, x, units.gu(1), 0, ubuntuListView.height);
692+ refreshSpy.wait();
693+ tryCompareFunction(function() { return ubuntuListView.pullToRefresh.refreshing; }, false, 1000);
694+ waitForRendering(ubuntuListView, 1000);
695+ }
696+ }
697+}

Subscribers

People subscribed via source and target branches