Browse Source

Merge branch 'master' of github.com:Ultimaker/Cura

Jack Ha 7 years ago
parent
commit
1dba5629f7

+ 13 - 10
cura/CuraApplication.py

@@ -1,9 +1,6 @@
 # Copyright (c) 2018 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
-#Type hinting.
-from typing import Dict
-
 from PyQt5.QtCore import QObject, QTimer
 from PyQt5.QtNetwork import QLocalServer
 from PyQt5.QtNetwork import QLocalSocket
@@ -68,6 +65,8 @@ from cura.Machines.Models.QualityManagementModel import QualityManagementModel
 from cura.Machines.Models.QualitySettingsModel import QualitySettingsModel
 from cura.Machines.Models.MachineManagementModel import MachineManagementModel
 
+from cura.Machines.Models.SettingVisibilityPresetsModel import SettingVisibilityPresetsModel
+
 from cura.Machines.MachineErrorChecker import MachineErrorChecker
 
 from cura.Settings.SettingInheritanceManager import SettingInheritanceManager
@@ -91,7 +90,6 @@ from cura.Settings.UserChangesModel import UserChangesModel
 from cura.Settings.ExtrudersModel import ExtrudersModel
 from cura.Settings.MaterialSettingsVisibilityHandler import MaterialSettingsVisibilityHandler
 from cura.Settings.ContainerManager import ContainerManager
-from cura.Settings.SettingVisibilityPresetsModel import SettingVisibilityPresetsModel
 
 from cura.ObjectsModel import ObjectsModel
 
@@ -101,7 +99,6 @@ from PyQt5.QtGui import QColor, QIcon
 from PyQt5.QtWidgets import QMessageBox
 from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType
 
-from configparser import ConfigParser
 import sys
 import os.path
 import numpy
@@ -226,6 +223,7 @@ class CuraApplication(QtApplication):
         self._object_manager = None
         self._build_plate_model = None
         self._multi_build_plate_model = None
+        self._setting_visibility_presets_model = None
         self._setting_inheritance_manager = None
         self._simple_mode_settings_manager = None
         self._cura_scene_controller = None
@@ -381,10 +379,6 @@ class CuraApplication(QtApplication):
 
         preferences.setDefault("local_file/last_used_type", "text/x-gcode")
 
-        default_visibility_profile = SettingVisibilityPresetsModel.getInstance().getItem(0)
-
-        preferences.setDefault("general/visible_settings", ";".join(default_visibility_profile["settings"]))
-
         self.applicationShuttingDown.connect(self.saveSettings)
         self.engineCreatedSignal.connect(self._onEngineCreated)
 
@@ -687,6 +681,11 @@ class CuraApplication(QtApplication):
         self._print_information = PrintInformation.PrintInformation()
         self._cura_actions = CuraActions.CuraActions(self)
 
+        # Initialize setting visibility presets model
+        self._setting_visibility_presets_model = SettingVisibilityPresetsModel(self)
+        default_visibility_profile = self._setting_visibility_presets_model.getItem(0)
+        Preferences.getInstance().setDefault("general/visible_settings", ";".join(default_visibility_profile["settings"]))
+
         # Detect in which mode to run and execute that mode
         if self.getCommandLineOption("headless", False):
             self.runWithoutGUI()
@@ -769,6 +768,10 @@ class CuraApplication(QtApplication):
     def hasGui(self):
         return self._use_gui
 
+    @pyqtSlot(result = QObject)
+    def getSettingVisibilityPresetsModel(self, *args) -> SettingVisibilityPresetsModel:
+        return self._setting_visibility_presets_model
+
     def getMachineErrorChecker(self, *args) -> MachineErrorChecker:
         return self._machine_error_checker
 
@@ -895,11 +898,11 @@ class CuraApplication(QtApplication):
         qmlRegisterType(NozzleModel, "Cura", 1, 0, "NozzleModel")
 
         qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
+        qmlRegisterType(SettingVisibilityPresetsModel, "Cura", 1, 0, "SettingVisibilityPresetsModel")
         qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
         qmlRegisterType(MachineNameValidator, "Cura", 1, 0, "MachineNameValidator")
         qmlRegisterType(UserChangesModel, "Cura", 1, 0, "UserChangesModel")
         qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager)
-        qmlRegisterSingletonType(SettingVisibilityPresetsModel, "Cura", 1, 0, "SettingVisibilityPresetsModel", SettingVisibilityPresetsModel.createSettingVisibilityPresetsModel)
 
         # As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work.
         actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))

+ 176 - 0
cura/Machines/Models/SettingVisibilityPresetsModel.py

@@ -0,0 +1,176 @@
+# Copyright (c) 2018 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+from typing import Optional
+import os
+import urllib.parse
+from configparser import ConfigParser
+
+from PyQt5.QtCore import pyqtProperty, Qt, pyqtSignal, pyqtSlot
+
+from UM.Logger import Logger
+from UM.Qt.ListModel import ListModel
+from UM.Preferences import Preferences
+from UM.Resources import Resources
+from UM.MimeTypeDatabase import MimeTypeDatabase, MimeTypeNotFoundError
+
+from UM.i18n import i18nCatalog
+catalog = i18nCatalog("cura")
+
+
+class SettingVisibilityPresetsModel(ListModel):
+    IdRole = Qt.UserRole + 1
+    NameRole = Qt.UserRole + 2
+    SettingsRole = Qt.UserRole + 3
+
+    def __init__(self, parent = None):
+        super().__init__(parent)
+        self.addRoleName(self.IdRole, "id")
+        self.addRoleName(self.NameRole, "name")
+        self.addRoleName(self.SettingsRole, "settings")
+
+        self._populate()
+        basic_item = self.items[1]
+        basic_visibile_settings = ";".join(basic_item["settings"])
+
+        self._preferences = Preferences.getInstance()
+        # Preference to store which preset is currently selected
+        self._preferences.addPreference("cura/active_setting_visibility_preset", "basic")
+        # Preference that stores the "custom" set so it can always be restored (even after a restart)
+        self._preferences.addPreference("cura/custom_visible_settings", basic_visibile_settings)
+        self._preferences.preferenceChanged.connect(self._onPreferencesChanged)
+
+        self._active_preset_item = self._getItem(self._preferences.getValue("cura/active_setting_visibility_preset"))
+        # Initialize visible settings if it is not done yet
+        visible_settings = self._preferences.getValue("general/visible_settings")
+        if not visible_settings:
+            self._preferences.setValue("general/visible_settings", ";".join(self._active_preset_item["settings"]))
+
+        self.activePresetChanged.emit()
+
+    def _getItem(self, item_id: str) -> Optional[dict]:
+        result = None
+        for item in self.items:
+            if item["id"] == item_id:
+                result = item
+                break
+        return result
+
+    def _populate(self):
+        from cura.CuraApplication import CuraApplication
+        items = []
+        for file_path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.SettingVisibilityPreset):
+            try:
+                mime_type = MimeTypeDatabase.getMimeTypeForFile(file_path)
+            except MimeTypeNotFoundError:
+                Logger.log("e", "Could not determine mime type of file %s", file_path)
+                continue
+
+            item_id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(file_path)))
+            if not os.path.isfile(file_path):
+                Logger.log("e", "[%s] is not a file", file_path)
+                continue
+
+            parser = ConfigParser(allow_no_value = True)  # accept options without any value,
+            try:
+                parser.read([file_path])
+                if not parser.has_option("general", "name") or not parser.has_option("general", "weight"):
+                    continue
+
+                settings = []
+                for section in parser.sections():
+                    if section == 'general':
+                        continue
+
+                    settings.append(section)
+                    for option in parser[section].keys():
+                        settings.append(option)
+
+                items.append({
+                    "id": item_id,
+                    "name": catalog.i18nc("@action:inmenu", parser["general"]["name"]),
+                    "weight": parser["general"]["weight"],
+                    "settings": settings,
+                })
+
+            except Exception:
+                Logger.logException("e", "Failed to load setting preset %s", file_path)
+
+        items.sort(key = lambda k: (int(k["weight"]), k["id"]))
+        # Put "custom" at the top
+        items.insert(0, {"id": "custom",
+                         "name": "Custom selection",
+                         "weight": -100,
+                         "settings": []})
+
+        self.setItems(items)
+
+    @pyqtSlot(str)
+    def setActivePreset(self, preset_id: str):
+        if preset_id == self._active_preset_item["id"]:
+            Logger.log("d", "Same setting visibility preset [%s] selected, do nothing.", preset_id)
+            return
+
+        preset_item = None
+        for item in self.items:
+            if item["id"] == preset_id:
+                preset_item = item
+                break
+        if preset_item is None:
+            Logger.log("w", "Tried to set active preset to unknown id [%s]", preset_id)
+            return
+
+        need_to_save_to_custom = self._active_preset_item["id"] == "custom" and preset_id != "custom"
+        if need_to_save_to_custom:
+            # Save the current visibility settings to custom
+            current_visibility_string = self._preferences.getValue("general/visible_settings")
+            if current_visibility_string:
+                self._preferences.setValue("cura/custom_visible_settings", current_visibility_string)
+
+        new_visibility_string = ";".join(preset_item["settings"])
+        if preset_id == "custom":
+            # Get settings from the stored custom data
+            new_visibility_string = self._preferences.getValue("cura/custom_visible_settings")
+            if new_visibility_string is None:
+                new_visibility_string = self._preferences.getValue("general/visible_settings")
+        self._preferences.setValue("general/visible_settings", new_visibility_string)
+
+        self._preferences.setValue("cura/active_setting_visibility_preset", preset_id)
+        self._active_preset_item = preset_item
+        self.activePresetChanged.emit()
+
+    activePresetChanged = pyqtSignal()
+
+    @pyqtProperty(str, notify = activePresetChanged)
+    def activePreset(self) -> str:
+        return self._active_preset_item["id"]
+
+    def _onPreferencesChanged(self, name: str):
+        if name != "general/visible_settings":
+            return
+
+        # Find the preset that matches with the current visible settings setup
+        visibility_string = self._preferences.getValue("general/visible_settings")
+        if not visibility_string:
+            return
+
+        visibility_set = set(visibility_string.split(";"))
+        matching_preset_item = None
+        for item in self.items:
+            if item["id"] == "custom":
+                continue
+            if set(item["settings"]) == visibility_set:
+                matching_preset_item = item
+                break
+
+        if matching_preset_item is None:
+            # The new visibility setup is "custom" should be custom
+            if self._active_preset_item["id"] == "custom":
+                # We are already in custom, just save the settings
+                self._preferences.setValue("cura/custom_visible_settings", visibility_string)
+            else:
+                self._active_preset_item = self.items[0]  # 0 is custom
+                self.activePresetChanged.emit()
+        else:
+            self._active_preset_item = matching_preset_item
+            self.activePresetChanged.emit()

+ 16 - 0
cura/PrinterOutput/NetworkedPrinterOutputDevice.py

@@ -3,6 +3,7 @@
 
 from UM.Application import Application
 from UM.Logger import Logger
+from UM.Settings.ContainerRegistry import ContainerRegistry
 
 from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
 
@@ -254,6 +255,21 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
         self._last_manager_create_time = time()
         self._manager.authenticationRequired.connect(self._onAuthenticationRequired)
 
+        self._checkCorrectGroupName()
+
+    ##  This method checks if the name of the group stored in the definition container is correct.
+    #   After updating from 3.2 to 3.3 some group names may be temporary. If there is a mismatch in the name of the group
+    #   then all the container stacks are updated, both the current and the hidden ones.
+    def _checkCorrectGroupName(self):
+        global_container_stack = Application.getInstance().getGlobalContainerStack()
+        if global_container_stack and self.getId() == global_container_stack.getMetaDataEntry("um_network_key"):
+            # Check if the connect_group_name is correct. If not, update all the containers connected to the same printer
+            if global_container_stack.getMetaDataEntry("connect_group_name") != self.name:
+                metadata_filter = {"um_network_key": global_container_stack.getMetaDataEntry("um_network_key")}
+                hidden_containers = ContainerRegistry.getInstance().findContainerStacks(type = "machine", **metadata_filter)
+                for container in hidden_containers:
+                    container.setMetaDataEntry("connect_group_name", self.name)
+
     def _registerOnFinishedCallback(self, reply: QNetworkReply, onFinished: Optional[Callable[[Any, QNetworkReply], None]]) -> None:
         if onFinished is not None:
             self._onFinishedCallbacks[reply.url().toString() + str(reply.operation())] = onFinished

+ 0 - 2
cura/Settings/MachineManager.py

@@ -10,7 +10,6 @@ from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
 from UM.Signal import Signal
 
 from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QTimer
-import UM.FlameProfiler
 from UM.FlameProfiler import pyqtSlot
 from UM import Util
 
@@ -24,7 +23,6 @@ from UM.Settings.SettingFunction import SettingFunction
 from UM.Signal import postponeSignals, CompressTechnique
 
 from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch
-from cura.Machines.VariantManager import VariantType
 from cura.PrinterOutputDevice import PrinterOutputDevice
 from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
 from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel

+ 0 - 136
cura/Settings/SettingVisibilityPresetsModel.py

@@ -1,136 +0,0 @@
-# Copyright (c) 2018 Ultimaker B.V.
-# Cura is released under the terms of the LGPLv3 or higher.
-
-import os
-import urllib
-from configparser import ConfigParser
-
-from PyQt5.QtCore import pyqtProperty, Qt, pyqtSignal, pyqtSlot, QUrl
-
-from UM.Logger import Logger
-from UM.Qt.ListModel import ListModel
-from UM.Preferences import Preferences
-from UM.Resources import Resources
-from UM.MimeTypeDatabase import MimeTypeDatabase, MimeTypeNotFoundError
-
-import cura.CuraApplication
-
-
-class SettingVisibilityPresetsModel(ListModel):
-    IdRole = Qt.UserRole + 1
-    NameRole = Qt.UserRole + 2
-    SettingsRole = Qt.UserRole + 4
-
-    def __init__(self, parent = None):
-        super().__init__(parent)
-        self.addRoleName(self.IdRole, "id")
-        self.addRoleName(self.NameRole, "name")
-        self.addRoleName(self.SettingsRole, "settings")
-
-        self._populate()
-
-        self._preferences = Preferences.getInstance()
-        self._preferences.addPreference("cura/active_setting_visibility_preset", "custom") # Preference to store which preset is currently selected
-        self._preferences.addPreference("cura/custom_visible_settings", "") # Preference that stores the "custom" set so it can always be restored (even after a restart)
-        self._preferences.preferenceChanged.connect(self._onPreferencesChanged)
-
-        self._active_preset = self._preferences.getValue("cura/active_setting_visibility_preset")
-        if self.find("id", self._active_preset) < 0:
-            self._active_preset = "custom"
-
-        self.activePresetChanged.emit()
-
-
-    def _populate(self):
-        items = []
-        for item in Resources.getAllResourcesOfType(cura.CuraApplication.CuraApplication.ResourceTypes.SettingVisibilityPreset):
-            try:
-                mime_type = MimeTypeDatabase.getMimeTypeForFile(item)
-            except MimeTypeNotFoundError:
-                Logger.log("e", "Could not determine mime type of file %s", item)
-                continue
-
-            id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(item)))
-
-            if not os.path.isfile(item):
-                continue
-
-            parser = ConfigParser(allow_no_value=True)  # accept options without any value,
-
-            try:
-                parser.read([item])
-
-                if not parser.has_option("general", "name") and not parser.has_option("general", "weight"):
-                    continue
-
-                settings = []
-                for section in parser.sections():
-                    if section == 'general':
-                        continue
-
-                    settings.append(section)
-                    for option in parser[section].keys():
-                        settings.append(option)
-
-                items.append({
-                    "id": id,
-                    "name": parser["general"]["name"],
-                    "weight": parser["general"]["weight"],
-                    "settings": settings
-                })
-
-            except Exception as e:
-                Logger.log("e", "Failed to load setting preset %s: %s", file_path, str(e))
-
-
-        items.sort(key = lambda k: (k["weight"], k["id"]))
-        self.setItems(items)
-
-    @pyqtSlot(str)
-    def setActivePreset(self, preset_id):
-        if preset_id != "custom" and self.find("id", preset_id) == -1:
-            Logger.log("w", "Tried to set active preset to unknown id %s", preset_id)
-            return
-
-        if preset_id == "custom" and self._active_preset == "custom":
-            # Copy current visibility set to custom visibility set preference so it can be restored later
-            visibility_string = self._preferences.getValue("general/visible_settings")
-            self._preferences.setValue("cura/custom_visible_settings", visibility_string)
-
-        self._preferences.setValue("cura/active_setting_visibility_preset", preset_id)
-
-        self._active_preset = preset_id
-        self.activePresetChanged.emit()
-
-    activePresetChanged = pyqtSignal()
-
-    @pyqtProperty(str, notify = activePresetChanged)
-    def activePreset(self):
-        return self._active_preset
-
-    def _onPreferencesChanged(self, name):
-        if name != "general/visible_settings":
-            return
-
-        if self._active_preset != "custom":
-            return
-
-        # Copy current visibility set to custom visibility set preference so it can be restored later
-        visibility_string = self._preferences.getValue("general/visible_settings")
-        self._preferences.setValue("cura/custom_visible_settings", visibility_string)
-
-
-    # Factory function, used by QML
-    @staticmethod
-    def createSettingVisibilityPresetsModel(engine, js_engine):
-        return SettingVisibilityPresetsModel.getInstance()
-
-    ##  Get the singleton instance for this class.
-    @classmethod
-    def getInstance(cls) -> "SettingVisibilityPresetsModel":
-        # Note: Explicit use of class name to prevent issues with inheritance.
-        if not SettingVisibilityPresetsModel.__instance:
-            SettingVisibilityPresetsModel.__instance = cls()
-        return SettingVisibilityPresetsModel.__instance
-
-    __instance = None   # type: "SettingVisibilityPresetsModel"

+ 3 - 0
plugins/UM3NetworkPrinting/UM3OutputDevicePlugin.py

@@ -82,6 +82,9 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
             self._zero_conf_browser.cancel()
             self._zero_conf_browser = None  # Force the old ServiceBrowser to be destroyed.
 
+        for instance_name in list(self._discovered_devices):
+            self._onRemoveDevice(instance_name)
+
         self._zero_conf = Zeroconf()
         self._zero_conf_browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.',
                                                  [self._appendServiceChangedRequest])

+ 2 - 7
plugins/XmlMaterialProfile/XmlMaterialProfile.py

@@ -208,14 +208,9 @@ class XmlMaterialProfile(InstanceContainer):
         machine_variant_map = {}
 
         variant_manager = CuraApplication.getInstance().getVariantManager()
-        material_manager = CuraApplication.getInstance().getMaterialManager()
 
         root_material_id = self.getMetaDataEntry("base_file")  # if basefile is self.getId, this is a basefile.
-        material_group = material_manager.getMaterialGroup(root_material_id)
-
-        all_containers = []
-        for node in [material_group.root_material_node] + material_group.derived_material_node_list:
-            all_containers.append(node.getContainer())
+        all_containers = registry.findInstanceContainers(base_file = root_material_id)
 
         for container in all_containers:
             definition_id = container.getMetaDataEntry("definition")
@@ -242,7 +237,7 @@ class XmlMaterialProfile(InstanceContainer):
 
         for definition_id, container in machine_container_map.items():
             definition_id = container.getMetaDataEntry("definition")
-            definition_metadata = ContainerRegistry.getInstance().findDefinitionContainersMetadata(id = definition_id)[0]
+            definition_metadata = registry.findDefinitionContainersMetadata(id = definition_id)[0]
 
             product = definition_id
             for product_name, product_id_list in product_id_map.items():

+ 6 - 24
resources/qml/Menus/SettingVisibilityPresetsMenu.qml

@@ -1,8 +1,8 @@
 // Copyright (c) 2018 Ultimaker B.V.
 // Cura is released under the terms of the LGPLv3 or higher.
 
-import QtQuick 2.2
-import QtQuick.Controls 1.1
+import QtQuick 2.7
+import QtQuick.Controls 1.4
 
 import UM 1.2 as UM
 import Cura 1.0 as Cura
@@ -12,44 +12,26 @@ Menu
     id: menu
     title: catalog.i18nc("@action:inmenu", "Visible Settings")
 
+    property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
     property bool showingSearchResults
     property bool showingAllSettings
 
     signal showAllSettings()
     signal showSettingVisibilityProfile()
 
-    MenuItem
-    {
-        text: catalog.i18nc("@action:inmenu", "Custom selection")
-        checkable: true
-        checked: !showingSearchResults && !showingAllSettings && Cura.SettingVisibilityPresetsModel.activePreset == "custom"
-        exclusiveGroup: group
-        onTriggered:
-        {
-            Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
-            // Restore custom set from preference
-            UM.Preferences.setValue("general/visible_settings", UM.Preferences.getValue("cura/custom_visible_settings"));
-            showSettingVisibilityProfile();
-        }
-    }
-    MenuSeparator { }
-
     Instantiator
     {
-        model: Cura.SettingVisibilityPresetsModel
+        model: settingVisibilityPresetsModel
 
         MenuItem
         {
             text: model.name
             checkable: true
-            checked: model.id == Cura.SettingVisibilityPresetsModel.activePreset
+            checked: model.id == settingVisibilityPresetsModel.activePreset
             exclusiveGroup: group
             onTriggered:
             {
-                Cura.SettingVisibilityPresetsModel.setActivePreset(model.id);
-
-                UM.Preferences.setValue("general/visible_settings", model.settings.join(";"));
-
+                settingVisibilityPresetsModel.setActivePreset(model.id);
                 showSettingVisibilityProfile();
             }
         }

+ 12 - 53
resources/qml/Preferences/SettingVisibilityPage.qml

@@ -13,6 +13,8 @@ UM.PreferencesPage
 {
     title: catalog.i18nc("@title:tab", "Setting Visibility");
 
+    property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
+
     property int scrollToIndex: 0
 
     signal scrollToSection( string key )
@@ -27,8 +29,7 @@ UM.PreferencesPage
 
         // After calling this function update Setting visibility preset combobox.
         // Reset should set default setting preset ("Basic")
-        visibilityPreset.setDefaultPreset()
-
+        visibilityPreset.currentIndex = 1
     }
     resetEnabled: true;
 
@@ -37,8 +38,6 @@ UM.PreferencesPage
         id: base;
         anchors.fill: parent;
 
-        property bool inhibitSwitchToCustom: false
-
         CheckBox
         {
             id: toggleVisibleSettings
@@ -112,11 +111,6 @@ UM.PreferencesPage
 
         ComboBox
         {
-            function setDefaultPreset()
-            {
-                visibilityPreset.currentIndex = 0
-            }
-
             id: visibilityPreset
             width: 150 * screenScaleFactor
             anchors
@@ -125,51 +119,25 @@ UM.PreferencesPage
                 right: parent.right
             }
 
-            model: ListModel
-            {
-                id: visibilityPresetsModel
-                Component.onCompleted:
-                {
-                    visibilityPresetsModel.append({text: catalog.i18nc("@action:inmenu", "Custom selection"), id: "custom"});
-
-                    var presets = Cura.SettingVisibilityPresetsModel;
-                    for(var i = 0; i < presets.rowCount(); i++)
-                    {
-                        visibilityPresetsModel.append({text: presets.getItem(i)["name"], id: presets.getItem(i)["id"]});
-                    }
-                }
-            }
+            model: settingVisibilityPresetsModel
+            textRole: "name"
 
             currentIndex:
             {
                 // Load previously selected preset.
-                var index = Cura.SettingVisibilityPresetsModel.find("id", Cura.SettingVisibilityPresetsModel.activePreset);
-                if(index == -1)
+                var index = settingVisibilityPresetsModel.find("id", settingVisibilityPresetsModel.activePreset)
+                if (index == -1)
                 {
-                    return 0;
+                    return 0
                 }
 
-                return index + 1; // "Custom selection" entry is added in front, so index is off by 1
+                return index
             }
 
             onActivated:
             {
-                base.inhibitSwitchToCustom = true;
-                var preset_id = visibilityPresetsModel.get(index).id;
-                Cura.SettingVisibilityPresetsModel.setActivePreset(preset_id);
-
-                UM.Preferences.setValue("cura/active_setting_visibility_preset", preset_id);
-                if (preset_id != "custom")
-                {
-                    UM.Preferences.setValue("general/visible_settings", Cura.SettingVisibilityPresetsModel.getItem(index - 1).settings.join(";"));
-                    // "Custom selection" entry is added in front, so index is off by 1
-                }
-                else
-                {
-                    // Restore custom set from preference
-                    UM.Preferences.setValue("general/visible_settings", UM.Preferences.getValue("cura/custom_visible_settings"));
-                }
-                base.inhibitSwitchToCustom = false;
+                var preset_id = settingVisibilityPresetsModel.getItem(index).id;
+                settingVisibilityPresetsModel.setActivePreset(preset_id);
             }
         }
 
@@ -199,16 +167,7 @@ UM.PreferencesPage
                     exclude: ["machine_settings", "command_line_settings"]
                     showAncestors: true
                     expanded: ["*"]
-                    visibilityHandler: UM.SettingPreferenceVisibilityHandler
-                    {
-                        onVisibilityChanged:
-                        {
-                            if(Cura.SettingVisibilityPresetsModel.activePreset != "" && !base.inhibitSwitchToCustom)
-                            {
-                                Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
-                            }
-                        }
-                    }
+                    visibilityHandler: UM.SettingPreferenceVisibilityHandler {}
                 }
 
                 delegate: Loader

+ 6 - 5
resources/qml/Settings/SettingView.qml

@@ -15,6 +15,7 @@ Item
 {
     id: base;
 
+    property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
     property Action configureSettings
     property bool findingSettings
     property bool showingAllSettings
@@ -562,9 +563,9 @@ Item
                     {
                         definitionsModel.hide(contextMenu.key);
                         // visible settings have changed, so we're no longer showing a preset
-                        if (Cura.SettingVisibilityPresetsModel.activePreset != "" && !showingAllSettings)
+                        if (settingVisibilityPresetsModel.activePreset != "" && !showingAllSettings)
                         {
-                            Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
+                            settingVisibilityPresetsModel.setActivePreset("custom");
                         }
                     }
                 }
@@ -594,16 +595,16 @@ Item
                             definitionsModel.show(contextMenu.key);
                         }
                         // visible settings have changed, so we're no longer showing a preset
-                        if (Cura.SettingVisibilityPresetsModel.activePreset != "" && !showingAllSettings)
+                        if (settingVisibilityPresetsModel.activePreset != "" && !showingAllSettings)
                         {
-                            Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
+                            settingVisibilityPresetsModel.setActivePreset("custom");
                         }
                     }
                 }
                 MenuItem
                 {
                     //: Settings context menu action
-                    text: catalog.i18nc("@action:menu", "Configure setting visiblity...");
+                    text: catalog.i18nc("@action:menu", "Configure setting visibility...");
 
                     onTriggered: Cura.Actions.configureSettingVisibility.trigger(contextMenu);
                 }