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.
This commit is contained in:
Ghostkeeper 2019-07-04 12:33:50 +02:00
parent cf68157508
commit a6e3828eaa
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276

View file

@ -3,11 +3,15 @@
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
import collections import collections
from typing import TYPE_CHECKING
from cura.Settings.IntentManager import IntentManager from cura.Settings.IntentManager import IntentManager
from UM.Qt.ListModel import ListModel from UM.Qt.ListModel import ListModel
from UM.Settings.ContainerRegistry import ContainerRegistry #To update the list if anything changes. 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 from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
@ -35,12 +39,17 @@ class IntentCategoryModel(ListModel):
self.addRoleName(self.IntentCategoryRole, "intent_category") self.addRoleName(self.IntentCategoryRole, "intent_category")
self.addRoleName(self.WeightRole, "weight") self.addRoleName(self.WeightRole, "weight")
ContainerRegistry.getInstance().containerAdded.connect(self.update) ContainerRegistry.getInstance().containerAdded.connect(self._onContainerChange)
ContainerRegistry.getInstance().containerRemoved.connect(self.update) ContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChange)
IntentManager.getInstance().configurationChanged.connect(self.update) IntentManager.getInstance().configurationChanged.connect(self.update)
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. ## Updates the list of intents.
def update(self) -> None: def update(self) -> None:
available_categories = IntentManager.getInstance().currentAvailableIntentCategories() available_categories = IntentManager.getInstance().currentAvailableIntentCategories()