From d1330e5ffa88d11d30e44bd64f4ed044eace6591 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 25 Sep 2019 08:52:53 +0200 Subject: [PATCH] Fix updating custom quality menu model CURA-6599 --- .../CustomQualityProfilesDropDownMenuModel.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cura/Machines/Models/CustomQualityProfilesDropDownMenuModel.py b/cura/Machines/Models/CustomQualityProfilesDropDownMenuModel.py index 8fe9b26517..1ab7e21700 100644 --- a/cura/Machines/Models/CustomQualityProfilesDropDownMenuModel.py +++ b/cura/Machines/Models/CustomQualityProfilesDropDownMenuModel.py @@ -1,17 +1,35 @@ # Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +from typing import Optional, TYPE_CHECKING + from UM.Logger import Logger import cura.CuraApplication # Imported this way to prevent circular references. from cura.Machines.ContainerTree import ContainerTree from cura.Machines.Models.QualityProfilesDropDownMenuModel import QualityProfilesDropDownMenuModel +if TYPE_CHECKING: + from PyQt5.QtCore import QObject + from UM.Settings.Interfaces import ContainerInterface + ## This model is used for the custom profile items in the profile drop down # menu. class CustomQualityProfilesDropDownMenuModel(QualityProfilesDropDownMenuModel): + def __init__(self, parent: Optional["QObject"] = None) -> None: + super().__init__(parent) + + container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry() + container_registry.containerAdded.connect(self._qualityChangesListChanged) + container_registry.containerRemoved.connect(self._qualityChangesListChanged) + container_registry.containerMetaDataChanged.connect(self._qualityChangesListChanged) + + def _qualityChangesListChanged(self, container: "ContainerInterface") -> None: + if container.getMetaDataEntry("type") == "quality_changes": + self._update() + def _update(self) -> None: Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))