on xenial help sign in
Ensure currentItem is set if the model is not empty
39350c9Michal Hruby
Dash/DashContent.qml+5−1
@@ -105,8 +105,12 @@ Item {
105
105
106 // If the number of items is less than the current index, then need to reset to another item.
106 // If the number of items is less than the current index, then need to reset to another item.
107 onCountChanged: {
107 onCountChanged: {
108− if (currentIndex >= count)
108+ if (count > 0 && currentIndex >= count) {
109 dashContent.setCurrentScopeAtIndex(count-1, true, true)
109 dashContent.setCurrentScopeAtIndex(count-1, true, true)
110+ } else if (count > 0 && currentIndex < 0) {
111+ // setting currentIndex directly, cause we don't want to loose set_current_index
112+ dashContent.currentIndex = 0
113+ }
110 }
114 }
111
115
112 delegate:
116 delegate:
tests/qmltests/Dash/tst_DashContent.qml+14
@@ -127,6 +127,20 @@ Item {
127 scopesModel.clear();
127 scopesModel.clear();
128 // wait for dash to empty scopes.
128 // wait for dash to empty scopes.
129 tryCompare(dashContentList, "count", 0);
129 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 are no items in the model");
140+
141+ tryCompare(scopeLoadedSpy, "count", 5);
142+
143+ verify(dashContentList.currentIndex >= 0);
130 }
144 }
131
145
132 function test_movement_started_signal() {
146 function test_movement_started_signal() {