on xenial help sign in
Need to wait until loaded is true to use the count property
4613522Albert Astals
qml/Dash/DashNavigationButton.qml+10−20
@@ -188,36 +188,26 @@ AbstractButton {
188 visible: root.showList
188 visible: root.showList
189 }
189 }
190
190
191+ property bool isFirstLoad: false
191 onScopeChanged: {
192 onScopeChanged: {
192− setNewNavigation();
193+ navigationModel.clear();
194+ isFirstLoad = true;
193 }
195 }
194−
195 function setNewNavigation() {
196 function setNewNavigation() {
196− navigationModel.clear();
197+ if (isFirstLoad && currentNavigation && currentNavigation.loaded) {
197− if (scope && scope[hasNavigation]) {
198+ isFirstLoad = false;
198− var navigation = getNavigation(scope[currentNavigationId]);
199+ if (currentNavigation.count > 0) {
199− if (navigation.count > 0) {
200 navigationModel.append({"navigationId": scope[currentNavigationId], "nullifyNavigation": false});
200 navigationModel.append({"navigationId": scope[currentNavigationId], "nullifyNavigation": false});
201 } else {
201 } else {
202− navigationModel.append({"navigationId": navigation.parentNavigationId, "nullifyNavigation": false});
202+ navigationModel.append({"navigationId": currentNavigation.parentNavigationId, "nullifyNavigation": false});
203 }
203 }
204 }
204 }
205 }
205 }
206−
207 Connections {
206 Connections {
208− target: scope
207+ target: currentNavigation
209− // This is duplicated since we can't have something based on the dynamic hasNavigation string property
210− onHasNavigationChanged: {
211− if (!root.isAltNavigation) {
212− setNewNavigation();
213− }
214− }
215− onHasAltNavigationChanged: {
216− if (root.isAltNavigation) {
217− setNewNavigation();
208+ onLoadedChanged: setNewNavigation();
218− }
219− }
220 }
209 }
210+ onCurrentNavigationChanged: setNewNavigation();
221
211
222 InverseMouseArea {
212 InverseMouseArea {
223 anchors.fill: navigationListView
213 anchors.fill: navigationListView
tests/mocks/Unity/fake_navigation.cpp+1−1
@@ -88,7 +88,7 @@ bool Navigation::hidden() const
88
88
89int Navigation::rowCount(const QModelIndex & /*parent*/) const
89int Navigation::rowCount(const QModelIndex & /*parent*/) const
90{
90{
91− if (!m_loaded || m_navigationId.startsWith("child") || m_navigationId == "middle3")
91+ if (!m_loaded || m_navigationId.startsWith("child") || m_navigationId.startsWith("altrootChild") || m_navigationId == "middle3")
92 return 0;
92 return 0;
93 else
93 else
94 return 8;
94 return 8;
tests/mocks/Unity/fake_scope.cpp+2−7
@@ -36,7 +36,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
36 , m_favorite(favorite)
36 , m_favorite(favorite)
37 , m_isActive(false)
37 , m_isActive(false)
38 , m_currentNavigationId("root")
38 , m_currentNavigationId("root")
39− , m_currentAltNavigationId("altroot")
39+ , m_currentAltNavigationId("altrootChild1")
40 , m_previewRendererName("preview-generic")
40 , m_previewRendererName("preview-generic")
41 , m_categories(new Categories(categories, this))
41 , m_categories(new Categories(categories, this))
42 , m_openScope(nullptr)
42 , m_openScope(nullptr)
@@ -297,12 +297,7 @@ unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const
297 parentId = "altroot";
297 parentId = "altroot";
298 parentLabel = "altroot";
298 parentLabel = "altroot";
299 }
299 }
300− auto result = new Navigation(id, id, "all"+id, parentId, parentLabel, this);
300+ return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
301− if (id == "altroot") {
302− m_currentAltNavigationId = "altrootChild1";
303− Q_EMIT currentAltNavigationIdChanged();
304− }
305− return result;
306}
301}
307
302
308void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
303void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
tests/qmltests/Dash/tst_DashContent.qml+13−6
@@ -288,12 +288,14 @@ Item {
288 var dashNavigationButton = findChild(dashContentList.currentItem, "navigationButton");
288 var dashNavigationButton = findChild(dashContentList.currentItem, "navigationButton");
289 compare(dashNavigationButton.showList, false);
289 compare(dashNavigationButton.showList, false);
290 waitForRendering(dashNavigationButton);
290 waitForRendering(dashNavigationButton);
291− mouseClick(dashNavigationButton, 0, 0);
291+ mouseClick(dashNavigationButton, dashNavigationButton.width / 2, dashNavigationButton.height / 2);
292 compare(dashNavigationButton.showList, true);
292 compare(dashNavigationButton.showList, true);
293
293
294 var navigationListView = findChild(dashNavigationButton, "navigationListView");
294 var navigationListView = findChild(dashNavigationButton, "navigationListView");
295+ tryCompareFunction(function() {
295− compare(navigationListView.count, 1);
296+ return navigationListView.currentItem &&
296− tryCompare(navigationListView.currentItem.navigation, "loaded", true);
297+ navigationListView.currentItem.navigation &&
298+ navigationListView.currentItem.navigation.loaded; }, true);
297
299
298 waitForRendering(navigationListView);
300 waitForRendering(navigationListView);
299 waitForRendering(navigationListView.currentItem);
301 waitForRendering(navigationListView.currentItem);
@@ -410,8 +412,10 @@ Item {
410 compare(dashNavigationButton.showList, true);
412 compare(dashNavigationButton.showList, true);
411
413
412 var navigationListView = findChild(dashNavigationButton, "navigationListView");
414 var navigationListView = findChild(dashNavigationButton, "navigationListView");
415+ tryCompareFunction(function() {
413− compare(navigationListView.count, 1);
416+ return navigationListView.currentItem &&
414− tryCompare(navigationListView.currentItem.navigation, "loaded", true);
417+ navigationListView.currentItem.navigation &&
418+ navigationListView.currentItem.navigation.loaded; }, true);
415
419
416 waitForRendering(navigationListView);
420 waitForRendering(navigationListView);
417 waitForRendering(navigationListView.currentItem);
421 waitForRendering(navigationListView.currentItem);
@@ -475,7 +479,10 @@ Item {
475 compare(dashAltNavigationButton.showList, true);
479 compare(dashAltNavigationButton.showList, true);
476
480
477 var navigationListView = findChild(dashAltNavigationButton, "navigationListView");
481 var navigationListView = findChild(dashAltNavigationButton, "navigationListView");
482+ tryCompareFunction(function() {
478− tryCompare(navigationListView.currentItem.navigation, "loaded", true);
483+ return navigationListView.currentItem &&
484+ navigationListView.currentItem.navigation &&
485+ navigationListView.currentItem.navigation.loaded; }, true);
479
486
480 var blackRect = findChild(dashNavigation, "blackRect");
487 var blackRect = findChild(dashNavigation, "blackRect");
481 tryCompare(blackRect, "opacity", 0.5);
488 tryCompare(blackRect, "opacity", 0.5);