on xenial help sign in
Ensure currentItem is set if the model is not empty
commit39350c9a82982dedb760c4db2bf8a248ceaccf3e authorMichal Hruby <michal.mhr@gmail.com> dateWed 27 Nov 2013, 17:11 (13 years ago) parent4d4c90e
2 files changed+19−1
Dash/DashContent.qml+5−1 tests/qmltests/Dash/tst_DashContent.qml+14
Dash/DashContent.qml+5−1
@@ -105,8 +105,12 @@ 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)
108+ if (count > 0 && currentIndex >= count) {
109109 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+ }
110114 }
111115
112116 delegate:
tests/qmltests/Dash/tst_DashContent.qml+14
@@ -127,6 +127,20 @@ 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 are no items in the model");
140+
141+ tryCompare(scopeLoadedSpy, "count", 5);
142+
143+ verify(dashContentList.currentIndex >= 0);
130144 }
131145
132146 function test_movement_started_signal() {