diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index ec52c7aea1..3a67b9b95c 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -549,7 +549,7 @@ class CuraApplication(QtApplication): qmlRegisterType(cura.Settings.ExtrudersModel, "Cura", 1, 0, "ExtrudersModel") qmlRegisterType(cura.Settings.ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel") - qmlRegisterType(cura.Settings.ProfilesModel, "Cura", 1, 0, "ProfilesModel") + qmlRegisterSingletonType(cura.Settings.ProfilesModel, "Cura", 1, 0, "ProfilesModel", cura.Settings.ProfilesModel.createProfilesModel) qmlRegisterType(cura.Settings.QualityAndUserProfilesModel, "Cura", 1, 0, "QualityAndUserProfilesModel") qmlRegisterType(cura.Settings.UserProfilesModel, "Cura", 1, 0, "UserProfilesModel") qmlRegisterType(cura.Settings.MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler") diff --git a/cura/Settings/ProfilesModel.py b/cura/Settings/ProfilesModel.py index 2ad9813e37..c03e074053 100644 --- a/cura/Settings/ProfilesModel.py +++ b/cura/Settings/ProfilesModel.py @@ -25,6 +25,21 @@ class ProfilesModel(InstanceContainersModel): Application.getInstance().getMachineManager().activeStackChanged.connect(self._update) Application.getInstance().getMachineManager().activeMaterialChanged.connect(self._update) + # Factory function, used by QML + @staticmethod + def createProfilesModel(engine, js_engine): + return ProfilesModel.getInstance() + + ## Get the singleton instance for this class. + @classmethod + def getInstance(cls): + # Note: Explicit use of class name to prevent issues with inheritance. + if ProfilesModel.__instance is None: + ProfilesModel.__instance = cls() + return ProfilesModel.__instance + + __instance = None + ## Fetch the list of containers to display. # # See UM.Settings.Models.InstanceContainersModel._fetchInstanceContainers(). diff --git a/resources/qml/Menus/ProfileMenu.qml b/resources/qml/Menus/ProfileMenu.qml index 4fa7a0d3c5..9dea8420bb 100644 --- a/resources/qml/Menus/ProfileMenu.qml +++ b/resources/qml/Menus/ProfileMenu.qml @@ -13,7 +13,7 @@ Menu Instantiator { - model: Cura.ProfilesModel { } + model: Cura.ProfilesModel MenuItem {