From 7fe327fb483ca58b1d2a47409d5e322c39841f51 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 30 Nov 2021 15:57:44 +0100 Subject: [PATCH] Fix resetting when Marketplace is closed and re-opened Previously, this would cause the Marketplace to freeze. We're still not entirely sure why. It seems to be a bug in Qt, but it's rather hard to deal with. This new solution is nicer in some ways but not as neat in others. - We're no longer clearing the content of the loader, so the QML and the package data remains in memory while the Marketplace is closed. We deem this to not be a problem, because the memory usage of this package data is only a couple of kB, nothing compared to the memory used by the slicer when it loads a model. - On the other hand, it's now possible to programmatically change the tab there, instead of manually having to click the buttons. - Fixes a bug where the highlighted tab of of the tab bar doesn't update when closing and re-opening the Marketplace. And a bug where there was a search bar for the manage page while it didn't work. Contributes to issue CURA-8565. --- .../Marketplace/resources/qml/Marketplace.qml | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/plugins/Marketplace/resources/qml/Marketplace.qml b/plugins/Marketplace/resources/qml/Marketplace.qml index 951de77f19..a02c0e0d5f 100644 --- a/plugins/Marketplace/resources/qml/Marketplace.qml +++ b/plugins/Marketplace/resources/qml/Marketplace.qml @@ -21,8 +21,14 @@ Window width: minimumWidth height: minimumHeight - // Set and unset the content. No need to keep things in memory if it's not visible. - onVisibleChanged: content.source = visible ? "Plugins.qml" : "" + onVisibleChanged: + { + pageSelectionTabBar.currentIndex = 0; //Go back to the initial tab. + while(contextStack.depth > 1) + { + contextStack.pop(); //Do NOT use the StackView.Immediate transition here, since it causes the window to stay empty. Seemingly a Qt bug: https://bugreports.qt.io/browse/QTBUG-60670? + } + } Connections { @@ -116,33 +122,33 @@ Window spacing: 0 background: Rectangle { color: "transparent" } + onCurrentIndexChanged: + { + searchBar.text = ""; + searchBar.visible = currentItem.hasSearch; + content.source = currentItem.sourcePage; + } + PackageTypeTab { id: pluginTabText width: implicitWidth text: catalog.i18nc("@button", "Plugins") - onClicked: - { - searchBar.text = "" - searchBar.visible = true - content.source = "Plugins.qml" - } + property string sourcePage: "Plugins.qml" + property bool hasSearch: true } PackageTypeTab { id: materialsTabText width: implicitWidth text: catalog.i18nc("@button", "Materials") - onClicked: - { - searchBar.text = "" - searchBar.visible = true - content.source = "Materials.qml" - } + property string sourcePage: "Materials.qml" + property bool hasSearch: true } ManagePackagesButton { - onClicked: content.source = "ManagedPackages.qml" + property string sourcePage: "ManagedPackages.qml" + property bool hasSearch: false } }