on xenial help sign in
Optimize scope.preview() calls
673ab8eAlbert Astals Cid
qml/Dash/GenericScopeView.qml+21−15
@@ -95,23 +95,25 @@ FocusScope {
95 scopeView.maybePreviewLimitedCategoryItemCount = undefined;
95 scopeView.maybePreviewLimitedCategoryItemCount = undefined;
96 scopeView.maybePreviewCategoryId = "";
96 scopeView.maybePreviewCategoryId = "";
97
97
98− if (scope.preview(result, categoryId)) {
99− openPreview(index, resultsModel, limitedCategoryItemCount, categoryId);
98+ openPreview(result, index, resultsModel, limitedCategoryItemCount, categoryId);
100− }
101 }
99 }
102
100
103− function openPreview(index, resultsModel, limitedCategoryItemCount, categoryId) {
101+ function openPreview(result, index, resultsModel, limitedCategoryItemCount, categoryId) {
102+ var previewStack = scope.preview(result, categoryId);
103+ if (previewStack) {
104− if (limitedCategoryItemCount > 0) {
104+ if (limitedCategoryItemCount > 0) {
105− previewLimitModel.model = resultsModel;
105+ previewLimitModel.model = resultsModel;
106− previewLimitModel.limit = limitedCategoryItemCount;
106+ previewLimitModel.limit = limitedCategoryItemCount;
107− subPageLoader.model = previewLimitModel;
107+ subPageLoader.model = previewLimitModel;
108− } else {
108+ } else {
109− subPageLoader.model = resultsModel;
109+ subPageLoader.model = resultsModel;
110+ }
111+ subPageLoader.initialIndex = -1;
112+ subPageLoader.initialIndex = index;
113+ subPageLoader.categoryId = categoryId;
114+ subPageLoader.previewStack = previewStack;
115+ subPageLoader.openSubPage("preview");
110 }
116 }
111− subPageLoader.initialIndex = -1;
112− subPageLoader.initialIndex = index;
113− subPageLoader.categoryId = categoryId;
114− subPageLoader.openSubPage("preview");
115 }
117 }
116
118
117 Binding {
119 Binding {
@@ -159,7 +161,8 @@ FocusScope {
159 onHideDash: subPageLoader.closeSubPage()
161 onHideDash: subPageLoader.closeSubPage()
160 onPreviewRequested: { // (QVariant const& result)
162 onPreviewRequested: { // (QVariant const& result)
161 if (result === scopeView.maybePreviewResult) {
163 if (result === scopeView.maybePreviewResult) {
164+ openPreview(result,
162− openPreview(scopeView.maybePreviewIndex,
165+ scopeView.maybePreviewIndex,
163 scopeView.maybePreviewResultsModel,
166 scopeView.maybePreviewResultsModel,
164 scopeView.maybePreviewLimitedCategoryItemCount,
167 scopeView.maybePreviewLimitedCategoryItemCount,
165 scopeView.maybePreviewCategoryId);
168 scopeView.maybePreviewCategoryId);
@@ -758,6 +761,7 @@ FocusScope {
758 property var scope: scopeView.scope
761 property var scope: scopeView.scope
759 property var scopeStyle: scopeView.scopeStyle
762 property var scopeStyle: scopeView.scopeStyle
760 property int initialIndex: -1
763 property int initialIndex: -1
764+ property var previewStack;
761 property string categoryId
765 property string categoryId
762 property var model: null
766 property var model: null
763
767
@@ -791,6 +795,8 @@ FocusScope {
791 item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex; } )
795 item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex; } )
792 item.model = Qt.binding(function() { return subPageLoader.model; } )
796 item.model = Qt.binding(function() { return subPageLoader.model; } )
793 item.categoryId = Qt.binding(function() { return subPageLoader.categoryId; } )
797 item.categoryId = Qt.binding(function() { return subPageLoader.categoryId; } )
798+ item.initialIndexPreviewStack = subPageLoader.previewStack;
799+ subPageLoader.previewStack = null;
794 }
800 }
795 open = true;
801 open = true;
796 }
802 }
qml/Dash/PreviewListView.qml+14−4
@@ -24,9 +24,11 @@ Item {
24 id: root
24 id: root
25
25
26 property int initialIndex: -1
26 property int initialIndex: -1
27+ property var initialIndexPreviewStack: null
27 property var scope: null
28 property var scope: null
28 property var scopeStyle: null
29 property var scopeStyle: null
29 property string categoryId
30 property string categoryId
31+ property bool usedInitialIndex: false
30
32
31 property alias showSignatureLine: header.showSignatureLine
33 property alias showSignatureLine: header.showSignatureLine
32
34
@@ -85,9 +87,9 @@ Item {
85 }
87 }
86
88
87 onCountChanged: {
89 onCountChanged: {
88− if (count > 0 && initialIndex >= 0) {
90+ if (count > 0 && initialIndex >= 0 && !usedInitialIndex) {
91+ usedInitialIndex = true;
89 currentIndex = initialIndex;
92 currentIndex = initialIndex;
90− initialIndex = -1;
91 }
93 }
92 }
94 }
93
95
@@ -100,8 +102,16 @@ Item {
100 isCurrent: ListView.isCurrentItem
102 isCurrent: ListView.isCurrentItem
101
103
102 previewModel: {
104 previewModel: {
105+ if (root.open) {
106+ if (index === root.initialIndex) {
107+ return root.initialIndexPreviewStack.getPreviewModel(0);
108+ } else {
103− var previewStack = root.scope.preview(result, root.categoryId);
109+ var previewStack = root.scope.preview(result, root.categoryId);
104− return previewStack.getPreviewModel(0);
110+ return previewStack.getPreviewModel(0);
111+ }
112+ } else {
113+ return null;
114+ }
105 }
115 }
106 scopeStyle: root.scopeStyle
116 scopeStyle: root.scopeStyle
107 }
117 }