From a6e3828eaa0f2926203c2b771f04b37354c79a5b Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 4 Jul 2019 12:33:50 +0200 Subject: [PATCH] Efficiency: Don't update model if adding different container types In fact we might want to delay updating until after the program has started up. Contributes to issue CURA-6597. --- cura/Machines/Models/IntentCategoryModel.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cura/Machines/Models/IntentCategoryModel.py b/cura/Machines/Models/IntentCategoryModel.py index 83f03b158a..c7484808ee 100644 --- a/cura/Machines/Models/IntentCategoryModel.py +++ b/cura/Machines/Models/IntentCategoryModel.py @@ -3,11 +3,15 @@ from PyQt5.QtCore import Qt import collections +from typing import TYPE_CHECKING from cura.Settings.IntentManager import IntentManager from UM.Qt.ListModel import ListModel from UM.Settings.ContainerRegistry import ContainerRegistry #To update the list if anything changes. +if TYPE_CHECKING: + from UM.Settings.ContainerRegistry import ContainerInterface + from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") @@ -35,12 +39,17 @@ class IntentCategoryModel(ListModel): self.addRoleName(self.IntentCategoryRole, "intent_category") self.addRoleName(self.WeightRole, "weight") - ContainerRegistry.getInstance().containerAdded.connect(self.update) - ContainerRegistry.getInstance().containerRemoved.connect(self.update) + ContainerRegistry.getInstance().containerAdded.connect(self._onContainerChange) + ContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChange) IntentManager.getInstance().configurationChanged.connect(self.update) self.update() + ## Updates the list of intents if an intent profile was added or removed. + def _onContainerChange(self, container: "ContainerInterface") -> None: + if container.getMetaDataEntry("type") == "intent": + self.update() + ## Updates the list of intents. def update(self) -> None: available_categories = IntentManager.getInstance().currentAvailableIntentCategories()