From 251fe8a3a6975c83258237f7f58515601644ce9a Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 19 Feb 2018 17:03:30 +0100 Subject: [PATCH] WIP: Remove ContainerSettingModel --- cura/CuraApplication.py | 2 - cura/Settings/ContainerSettingsModel.py | 97 ------------------------- 2 files changed, 99 deletions(-) delete mode 100644 cura/Settings/ContainerSettingsModel.py diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 57054c5d3b..795c254d8c 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -81,7 +81,6 @@ from cura.Settings.MachineManager import MachineManager from cura.Settings.ExtruderManager import ExtruderManager from cura.Settings.UserChangesModel import UserChangesModel from cura.Settings.ExtrudersModel import ExtrudersModel -from cura.Settings.ContainerSettingsModel import ContainerSettingsModel from cura.Settings.MaterialSettingsVisibilityHandler import MaterialSettingsVisibilityHandler from cura.Machines.Models.QualitySettingsModel import QualitySettingsModel from cura.Settings.ContainerManager import ContainerManager @@ -942,7 +941,6 @@ class CuraApplication(QtApplication): qmlRegisterSingletonType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel", self.getMultiBuildPlateModel) qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer") qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel") - qmlRegisterType(ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel") qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel") qmlRegisterType(BrandMaterialsModel, "Cura", 1, 0, "BrandMaterialsModel") diff --git a/cura/Settings/ContainerSettingsModel.py b/cura/Settings/ContainerSettingsModel.py deleted file mode 100644 index 2c4bef6464..0000000000 --- a/cura/Settings/ContainerSettingsModel.py +++ /dev/null @@ -1,97 +0,0 @@ -# Copyright (c) 2016 Ultimaker B.V. -# Cura is released under the terms of the LGPLv3 or higher. - -from UM.Application import Application -from UM.Qt.ListModel import ListModel - -from PyQt5.QtCore import pyqtProperty, Qt, pyqtSignal, pyqtSlot, QUrl - -from UM.Settings.ContainerRegistry import ContainerRegistry -from UM.Settings.InstanceContainer import InstanceContainer -from UM.Settings.SettingFunction import SettingFunction - -class ContainerSettingsModel(ListModel): - LabelRole = Qt.UserRole + 1 - CategoryRole = Qt.UserRole + 2 - UnitRole = Qt.UserRole + 3 - ValuesRole = Qt.UserRole + 4 - - def __init__(self, parent = None): - super().__init__(parent) - self.addRoleName(self.LabelRole, "label") - self.addRoleName(self.CategoryRole, "category") - self.addRoleName(self.UnitRole, "unit") - self.addRoleName(self.ValuesRole, "values") - - self._container_ids = [] - self._containers = [] - - def _onPropertyChanged(self, key, property_name): - if property_name == "value": - self._update() - - def _update(self): - items = [] - - if len(self._container_ids) == 0: - return - - keys = [] - for container in self._containers: - keys = keys + list(container.getAllKeys()) - - keys = list(set(keys)) # remove duplicate keys - - for key in keys: - definition = None - category = None - values = [] - for container in self._containers: - instance = container.getInstance(key) - if instance: - definition = instance.definition - - # Traverse up to find the category - category = definition - while category.type != "category": - category = category.parent - - value = container.getProperty(key, "value") - if type(value) == SettingFunction: - values.append("=\u0192") - else: - values.append(container.getProperty(key, "value")) - else: - values.append("") - - items.append({ - "key": key, - "values": values, - "label": definition.label, - "unit": definition.unit, - "category": category.label - }) - items.sort(key = lambda k: (k["category"], k["key"])) - self.setItems(items) - - ## Set the ids of the containers which have the settings this model should list. - # Also makes sure the model updates when the containers have property changes - def setContainers(self, container_ids): - for container in self._containers: - container.propertyChanged.disconnect(self._onPropertyChanged) - - self._container_ids = container_ids - self._containers = [] - - for container_id in self._container_ids: - containers = ContainerRegistry.getInstance().findContainers(id = container_id) - if containers: - containers[0].propertyChanged.connect(self._onPropertyChanged) - self._containers.append(containers[0]) - - self._update() - - containersChanged = pyqtSignal() - @pyqtProperty("QVariantList", fset = setContainers, notify = containersChanged) - def containers(self): - return self.container_ids