From a2db4740b9654fde55f0f811cb33797dc9e63320 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 6 Jun 2016 15:09:21 +0200 Subject: [PATCH 1/4] Fix removing custom (quality) profiles CURA-1585 --- cura/MachineManagerModel.py | 22 +++++++++++++++++++++- resources/qml/Preferences/ProfilesPage.qml | 8 ++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index 3a584a2797..6e1a6185e7 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -301,7 +301,7 @@ class MachineManagerModel(QObject): new_quality_container._id = name UM.Settings.ContainerRegistry.getInstance().addContainer(new_quality_container) - self.clearUserSettings() # As all users settings are noq a quality, remove them. + self.clearUserSettings() # As all users settings are now transfered to the new quality profile, remove them. self.setActiveQuality(name) return name @@ -325,6 +325,26 @@ class MachineManagerModel(QObject): return "" + + @pyqtSlot(str) + def removeQualityContainer(self, container_id): + containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id) + if not containers or not self._global_container_stack: + return + + # If the container that is being removed is the currently active container, set another machine as the active container + activate_new_container = container_id == self.activeQualityId + + UM.Settings.ContainerRegistry.getInstance().removeContainer(container_id) + + if activate_new_container: + old_container = self._global_container_stack.findInstanceContainers({"type": "quality"}) + containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = container_type) + if containers and old_container: + container_index = self._global_container_stack.getContainerIndex(old_container) + self._global_container_stack.replaceContainer(container_index, containers[0]) + + @pyqtSlot() def updateUserContainerToQuality(self): if not self._global_container_stack: diff --git a/resources/qml/Preferences/ProfilesPage.qml b/resources/qml/Preferences/ProfilesPage.qml index 0b57405b56..f5d3169508 100644 --- a/resources/qml/Preferences/ProfilesPage.qml +++ b/resources/qml/Preferences/ProfilesPage.qml @@ -66,8 +66,8 @@ UM.ManagementPage activateEnabled: currentItem != null ? currentItem.id != Cura.MachineManager.activeQualityId : false; addEnabled: currentItem != null; - removeEnabled: currentItem != null ? !currentItem.readOnly : false; - renameEnabled: currentItem != null ? !currentItem.readOnly : false; + removeEnabled: currentItem != null ? !currentItem.metadata.read_only : false; + renameEnabled: currentItem != null ? !currentItem.metadata.read_only : false; scrollviewCaption: catalog.i18nc("@label %1 is printer name","Printer: %1").arg(Cura.MachineManager.activeMachineName) @@ -137,7 +137,7 @@ UM.ManagementPage Label { text: base.currentItem == null ? "" : base.currentItem.id == -1 ? Cura.MachineManager.activeQualityName: - base.currentItem.readOnly ? catalog.i18nc("@label", "Protected profile") : catalog.i18nc("@label", "Custom profile") + base.currentItem.metadata.read_only ? catalog.i18nc("@label", "Protected profile") : catalog.i18nc("@label", "Custom profile") } Column { @@ -186,7 +186,7 @@ UM.ManagementPage { id: confirmDialog; object: base.currentItem != null ? base.currentItem.name : ""; - onYes: base.model.removeProfile(base.currentItem.name); + onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id); } UM.RenameDialog { From 0b57728d9d7042fff3b5d694732b09a697564779 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 6 Jun 2016 15:55:14 +0200 Subject: [PATCH 2/4] Fix creating a unique name for profiles CURA-1585 --- cura/MachineManagerModel.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index 6e1a6185e7..4deea99afc 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -9,7 +9,8 @@ from UM.Logger import Logger import UM.Settings from UM.Settings.Validator import ValidatorState from UM.Settings.InstanceContainer import InstanceContainer - +from UM.i18n import i18nCatalog +catalog = i18nCatalog("cura") class MachineManagerModel(QObject): def __init__(self, parent = None): @@ -118,7 +119,7 @@ class MachineManagerModel(QObject): definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id=definition_id) if definitions: definition = definitions[0] - name = self._createUniqueStackName(name, definition.getName()) + name = self._createUniqueName("machine", name, definition.getName()) new_global_stack = UM.Settings.ContainerStack(name) new_global_stack.addMetaDataEntry("type", "machine") @@ -168,7 +169,7 @@ class MachineManagerModel(QObject): Application.getInstance().setGlobalContainerStack(new_global_stack) # Create a name that is not empty and unique - def _createUniqueStackName(self, name, fallback_name): + def _createUniqueName(self, object_type, name, fallback_name): name = name.strip() num_check = re.compile("(.*?)\s*#\d$").match(name) if(num_check): @@ -179,10 +180,16 @@ class MachineManagerModel(QObject): i = 1 # Check both the id and the name, because they may not be the same and it is better if they are both unique - while UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = unique_name, type = "machine") or \ - UM.Settings.ContainerRegistry.getInstance().findContainerStacks(name = unique_name, type = "machine"): - i += 1 - unique_name = "%s #%d" % (name, i) + if object_type == "machine": + while UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = unique_name, type = "machine") or \ + UM.Settings.ContainerRegistry.getInstance().findContainerStacks(name = unique_name, type = "machine"): + i += 1 + unique_name = "%s #%d" % (name, i) + else: + while UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = unique_name, type = object_type) or \ + UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(name = unique_name, type = object_type): + i += 1 + unique_name = "%s #%d" % (name, i) return unique_name @@ -282,7 +289,7 @@ class MachineManagerModel(QObject): if not self._global_container_stack: return - name = self._createUniqueStackName("Custom profile", "") + name = self._createUniqueName("quality", self.activeQualityName, catalog.i18nc("@label", "Custom profile")) user_settings = self._global_container_stack.getTop() new_quality_container = InstanceContainer("") @@ -311,7 +318,7 @@ class MachineManagerModel(QObject): return containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=container_id) if containers: - new_name = self._createUniqueStackName(containers[0].getName(), "") + new_name = self._createUniqueName("quality", containers[0].getName(), catalog.i18nc("@label", "Custom profile")) new_container = InstanceContainer("") @@ -424,7 +431,7 @@ class MachineManagerModel(QObject): def renameMachine(self, machine_id, new_name): containers = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = machine_id) if containers: - new_name = self._createUniqueStackName(new_name, containers[0].getBottom().getName()) + new_name = self._createUniqueName("machine", new_name, containers[0].getBottom().getName()) containers[0].setName(new_name) self.globalContainerChanged.emit() From df71269f8244ed4c3e15b32a20af241df4463384 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 6 Jun 2016 15:56:45 +0200 Subject: [PATCH 3/4] Mark custom profiles as not read-only CURA-1585 --- cura/MachineManagerModel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index 4deea99afc..ad7669b43a 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -303,7 +303,8 @@ class MachineManagerModel(QObject): new_quality_container.setDefinition(UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0]) ## Change type / id / name - new_quality_container.setMetaDataEntry("type","quality") + new_quality_container.setMetaDataEntry("type", "quality") + new_quality_container.setMetaDataEntry("read_only", False) new_quality_container.setName(name) new_quality_container._id = name From 03914674c7f105be37a3a7dc222a9659c3d741f4 Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Mon, 6 Jun 2016 16:03:16 +0200 Subject: [PATCH 4/4] Cache all of the settings list items instead of recreating them all the time. Fixes CURA-1630 Settings disappear after selecting all options of Experimental Modes --- resources/qml/Settings/SettingView.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/qml/Settings/SettingView.qml b/resources/qml/Settings/SettingView.qml index 0eb13d668c..ba7b5e32a9 100644 --- a/resources/qml/Settings/SettingView.qml +++ b/resources/qml/Settings/SettingView.qml @@ -24,6 +24,7 @@ ScrollView { id: contents spacing: UM.Theme.getSize("default_lining").height; + cacheBuffer: 1000000; // A huge to cache to effectively cache everything. model: UM.SettingDefinitionsModel { id: definitionsModel;