on xenial help sign in
Move function out of delegate
3274b91Albert Astals Cid
qml/Dash/DashNavigation.qml+16−15
@@ -54,6 +54,20 @@ Item {
54 id: headersColumn
54 id: headersColumn
55 anchors.top: parent.top
55 anchors.top: parent.top
56 width: parent.width
56 width: parent.width
57+
58+ function pop(popsNeeded) {
59+ if (popsNeeded == 0)
60+ return;
61+ isEnteringChildren = false;
62+ navigationListView.currentIndex = navigationListView.currentIndex - popsNeeded;
63+ navigationModel.setProperty(navigationListView.currentIndex, "nullifyNavigation", false);
64+ navigationModel.remove(navigationModel.count - popsNeeded, popsNeeded);
65+
66+ popsNeeded = Math.min(headersModel.count, popsNeeded);
67+ // This is effectively deleting ourselves, so needs to be the last thing of the function
68+ headersModel.remove(headersModel.count - popsNeeded, popsNeeded);
69+ }
70+
57 Repeater {
71 Repeater {
58 model: ListModel {
72 model: ListModel {
59 id: headersModel
73 id: headersModel
@@ -71,31 +85,18 @@ Item {
71 text: headerText
85 text: headerText
72 foregroundColor: d.foregroundColor
86 foregroundColor: d.foregroundColor
73
87
74− function pop(popsNeeded) {
75− if (popsNeeded == 0)
76− return;
77− isEnteringChildren = false;
78− navigationListView.currentIndex = navigationListView.currentIndex - popsNeeded;
79− navigationModel.setProperty(navigationListView.currentIndex, "nullifyNavigation", false);
80− navigationModel.remove(navigationModel.count - popsNeeded, popsNeeded);
81−
82− popsNeeded = Math.min(headersModel.count, popsNeeded);
83− // This is effectively deleting ourselves, so needs to be the last thing of the function
84− headersModel.remove(headersModel.count - popsNeeded, popsNeeded);
85− }
86−
87 onBackClicked: {
88 onBackClicked: {
88 scope.setNavigationState(parentNavigationId);
89 scope.setNavigationState(parentNavigationId);
89
90
90 var popsNeeded = headersModel.count - index;
91 var popsNeeded = headersModel.count - index;
91− pop(popsNeeded);
92+ headersColumn.pop(popsNeeded);
92 }
93 }
93
94
94 onTextClicked: {
95 onTextClicked: {
95 scope.setNavigationState(navigationId);
96 scope.setNavigationState(navigationId);
96
97
97 var popsNeeded = headersModel.count - index - 1;
98 var popsNeeded = headersModel.count - index - 1;
98− pop(popsNeeded);
99+ headersColumn.pop(popsNeeded);
99
100
100 root.leafClicked();
101 root.leafClicked();
101 }
102 }