on xenial help sign in
Ensure DashContent's ListView's currentItem is set if the model is not empty.

Approved by PS Jenkins bot, Albert Astals Cid.

commit2297b8bae9691afef975aab7053945d03c2f7745 authorMichal Hruby <michal.mhr@gmail.com> dateFri 29 Nov 2013, 15:29 (13 years ago) parent25523bd4aa8de8
2 files changed+35−2
Dash/DashContent.qml+8−2 tests/qmltests/Dash/tst_DashContent.qml+27
Dash/DashContent.qml+8−2
@@ -105,8 +105,14 @@ Item {
105105
106106 // If the number of items is less than the current index, then need to reset to another item.
107107 onCountChanged: {
108− if (currentIndex >= count)
109− dashContent.setCurrentScopeAtIndex(count-1, true, true)
108+ if (count > 0) {
109+ if (currentIndex >= count) {
110+ dashContent.setCurrentScopeAtIndex(count-1, true, true)
111+ } else if (currentIndex < 0) {
112+ // setting currentIndex directly, cause we don't want to loose set_current_index
113+ dashContent.currentIndex = 0
114+ }
115+ }
110116 }
111117
112118 delegate:
tests/qmltests/Dash/tst_DashContent.qml+27
@@ -127,6 +127,33 @@ Item {
127127 scopesModel.clear();
128128 // wait for dash to empty scopes.
129129 tryCompare(dashContentList, "count", 0);
130+ // this is the default state for empty model
131+ dashContentList.currentIndex = -1;
132+ }
133+
134+ function test_current_index() {
135+ var dashContentList = findChild(dashContent, "dashContentList");
136+ verify(dashContentList != undefined)
137+
138+ compare(dashContentList.count, 0, "DashContent should have 0 items when it starts");
139+ compare(dashContentList.currentIndex, -1, "DashContent's currentIndex should be -1 while there have been no items in the model");
140+
141+ tryCompare(scopeLoadedSpy, "count", 5);
142+
143+ verify(dashContentList.currentIndex >= 0);
144+ }
145+
146+ function test_current_index_after_reset() {
147+ var dashContentList = findChild(dashContent, "dashContentList");
148+ verify(dashContentList != undefined)
149+
150+ compare(dashContentList.count, 0, "DashContent should have 0 items when it starts");
151+ // pretend we're running after a model reset
152+ dashContentList.currentIndex = 27;
153+
154+ tryCompare(scopeLoadedSpy, "count", 5);
155+
156+ verify(dashContentList.currentIndex >= 0 && dashContentList.currentIndex < 5);
130157 }
131158
132159 function test_movement_started_signal() {