[vlc-devel] [PATCH 44/49] qml: avoid reloading pages completely when possible
Pierre Lamot
pierre at videolabs.io
Fri Oct 11 15:18:08 CEST 2019
this performs partial reload when navigating history rather than
reloading the whole page
---
.../gui/qt/qml/mediacenter/MCMainDisplay.qml | 49 +++++++++----------
.../gui/qt/qml/mediacenter/MCMusicDisplay.qml | 27 +++++++---
modules/gui/qt/qml/utils/StackViewExt.qml | 17 +++++++
3 files changed, 59 insertions(+), 34 deletions(-)
diff --git a/modules/gui/qt/qml/mediacenter/MCMainDisplay.qml b/modules/gui/qt/qml/mediacenter/MCMainDisplay.qml
index 24345d17c8..2e29a70d15 100644
--- a/modules/gui/qt/qml/mediacenter/MCMainDisplay.qml
+++ b/modules/gui/qt/qml/mediacenter/MCMainDisplay.qml
@@ -34,6 +34,28 @@ Utils.NavigableFocusScope {
property string view: ""
property var viewProperties: ({})
+ onViewChanged: loadView()
+ onViewPropertiesChanged: loadView()
+ Component.onCompleted: loadView()
+
+ function loadView() {
+ var found = stackView.loadView(root.pageModel, root.view, root.viewProperties)
+
+ sourcesBanner.subTabModel = stackView.currentItem.tabModel
+ sourcesBanner.sortModel = stackView.currentItem.sortModel
+ sourcesBanner.contentModel = stackView.currentItem.contentModel
+ sourcesBanner.extraLocalActions = stackView.currentItem.extraLocalActions
+ // Restore sourcesBanner state
+ sourcesBanner.selectedIndex = pageModel.findIndex(function (e) {
+ return e.name === root.view
+ })
+ if (stackView.currentItem.pageModel !== undefined)
+ sourcesBanner.subSelectedIndex = stackView.currentItem.pageModel.findIndex(function (e) {
+ return e.name === stackView.currentItem.view
+ })
+ }
+
+
Component {
id: musicComp
MCMusicDisplay {
@@ -129,17 +151,9 @@ Utils.NavigableFocusScope {
onItemClicked: {
sourcesBanner.subTabModel = undefined
-
var name = root.tabModel.get(index).name
- stackView.replace(root.pageModel[index].component)
- history.push(["mc", name], History.Stay)
-
- subTabModel = stackView.currentItem.tabModel
- sortModel = stackView.currentItem.sortModel
- contentModel = stackView.currentItem.contentModel
- extraLocalActions = stackView.currentItem.extraLocalActions
-
selectedIndex = index
+ history.push(["mc", name], History.Go)
}
onSubItemClicked: {
@@ -197,23 +211,6 @@ Utils.NavigableFocusScope {
bottom: parent.bottom
right: playlist.visible ? playlist.left : parent.right
}
-
- Component.onCompleted: {
- var found = stackView.loadView(root.pageModel, root.view, root.viewProperties)
- sourcesBanner.subTabModel = stackView.currentItem.tabModel
- sourcesBanner.sortModel = stackView.currentItem.sortModel
- sourcesBanner.contentModel = stackView.currentItem.contentModel
- sourcesBanner.extraLocalActions = stackView.currentItem.extraLocalActions
-
- // Restore sourcesBanner state
- sourcesBanner.selectedIndex = pageModel.findIndex(function (e) {
- return e.name === root.view
- })
- if (stackView.currentItem.pageModel !== undefined)
- sourcesBanner.subSelectedIndex = stackView.currentItem.pageModel.findIndex(function (e) {
- return e.name === stackView.currentItem.view
- })
- }
}
diff --git a/modules/gui/qt/qml/mediacenter/MCMusicDisplay.qml b/modules/gui/qt/qml/mediacenter/MCMusicDisplay.qml
index e97f116e76..68a2bd0384 100644
--- a/modules/gui/qt/qml/mediacenter/MCMusicDisplay.qml
+++ b/modules/gui/qt/qml/mediacenter/MCMusicDisplay.qml
@@ -37,14 +37,28 @@ Utils.NavigableFocusScope {
property var sortModel
property var contentModel
- function loadIndex(index) {
- stackView.replace(root.pageModel[index].component)
- history.push(["mc", "music", root.pageModel[index].name], History.Stay)
- stackView.focus = true
+ onViewChanged: loadView()
+ onViewProperties: loadView()
+ Component.onCompleted: loadView()
+
+ function loadView() {
+ var found = stackView.loadView(root.pageModel, view, viewProperties)
+ if (!found)
+ stackView.replace(root.pageModel[0].component)
sortModel = stackView.currentItem.sortModel
contentModel = stackView.currentItem.model
}
+ //reset view
+ function loadDefaultView() {
+ root.view = "albums"
+ root.viewProperties= ({})
+ }
+
+ function loadIndex(index) {
+ history.push(["mc", "music", root.pageModel[index].name], History.Go)
+ }
+
Component { id: albumComp; MusicAlbumsDisplay{ navigationParent: root } }
Component { id: artistComp; MusicArtistsDisplay{ navigationParent: root } }
Component { id: genresComp; MusicGenresDisplay{ navigationParent: root } }
@@ -92,12 +106,9 @@ Utils.NavigableFocusScope {
Layout.margins: VLCStyle.margin_normal
focus: true
- Component.onCompleted: {
- var found = stackView.loadView(root.pageModel, view, viewProperties)
+ onCurrentItemChanged: {
sortModel = stackView.currentItem.sortModel
contentModel = stackView.currentItem.model
- if (!found)
- replace(pageModel[0].component)
}
}
}
diff --git a/modules/gui/qt/qml/utils/StackViewExt.qml b/modules/gui/qt/qml/utils/StackViewExt.qml
index 7d988ad555..19554d09c7 100644
--- a/modules/gui/qt/qml/utils/StackViewExt.qml
+++ b/modules/gui/qt/qml/utils/StackViewExt.qml
@@ -24,6 +24,8 @@ import QtQuick.Controls 2.4
StackView {
id: root
+ property string _currentView: ""
+
replaceEnter: Transition {
PropertyAnimation {
property: "opacity"
@@ -52,6 +54,19 @@ StackView {
*/
function loadView(viewModel, view, viewProperties)
{
+ if (view === _currentView) {
+ if (Object.keys(viewProperties).length === 0 && root.currentItem.hasOwnProperty("loadDefaultView") ) {
+ root.currentItem.loadDefaultView()
+ } else {
+ for ( var viewProp in viewProperties ) {
+ if ( root.currentItem.hasOwnProperty(viewProp) ) {
+ root.currentItem[viewProp] = viewProperties[viewProp]
+ }
+ }
+ }
+ return true
+ }
+
var found = false
for (var tab = 0; tab < viewModel.length; tab++ )
{
@@ -81,6 +96,8 @@ StackView {
}
if (!found)
console.warn("unable to load view " + view)
+ else
+ _currentView = view
return found
}
}
--
2.20.1
More information about the vlc-devel
mailing list