Profiles model is now a singleton, to prevent the agressive garbage collecting to break stuff

CURA-2826
This commit is contained in:
Jaime van Kessel 2016-10-27 14:26:43 +02:00
parent 4a5d7cbc73
commit 1aa71d6171
3 changed files with 17 additions and 2 deletions

View File

@ -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")

View File

@ -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().

View File

@ -13,7 +13,7 @@ Menu
Instantiator
{
model: Cura.ProfilesModel { }
model: Cura.ProfilesModel
MenuItem
{