Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cura
diff options
context:
space:
mode:
authorGhostkeeper <rubend@tutanota.com>2017-06-22 18:21:11 +0300
committerGhostkeeper <rubend@tutanota.com>2017-06-22 19:17:16 +0300
commitbc219a06fec6141609e6a4bd1530369aaabffbab (patch)
tree901e5cb76c561cc8488892a8c78d067f8896faa6 /cura
parent0e23930bfefd7ac4df5de6a0db917200b08816d4 (diff)
Add MaterialsModel to make material list update upon metadata change
This new model inherits from InstanceContainersModel. The only change is that it updates when the metadata of a material container changes. This is needed to make the list of materials update when the material diameter changes. Contributes to issue CURA-2822.
Diffstat (limited to 'cura')
-rwxr-xr-xcura/CuraApplication.py2
-rw-r--r--cura/Settings/MaterialsModel.py21
2 files changed, 23 insertions, 0 deletions
diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py
index 332b103502..a1f5aaa6de 100755
--- a/cura/CuraApplication.py
+++ b/cura/CuraApplication.py
@@ -48,6 +48,7 @@ from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.SettingFunction import SettingFunction
from cura.Settings.MachineNameValidator import MachineNameValidator
from cura.Settings.ProfilesModel import ProfilesModel
+from cura.Settings.MaterialsModel import MaterialsModel
from cura.Settings.QualityAndUserProfilesModel import QualityAndUserProfilesModel
from cura.Settings.SettingInheritanceManager import SettingInheritanceManager
from cura.Settings.UserProfilesModel import UserProfilesModel
@@ -717,6 +718,7 @@ class CuraApplication(QtApplication):
qmlRegisterType(ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel")
qmlRegisterSingletonType(ProfilesModel, "Cura", 1, 0, "ProfilesModel", ProfilesModel.createProfilesModel)
+ qmlRegisterType(MaterialsModel, "Cura", 1, 0, "MaterialsModel")
qmlRegisterType(QualityAndUserProfilesModel, "Cura", 1, 0, "QualityAndUserProfilesModel")
qmlRegisterType(UserProfilesModel, "Cura", 1, 0, "UserProfilesModel")
qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
diff --git a/cura/Settings/MaterialsModel.py b/cura/Settings/MaterialsModel.py
new file mode 100644
index 0000000000..75eeb6c281
--- /dev/null
+++ b/cura/Settings/MaterialsModel.py
@@ -0,0 +1,21 @@
+# Copyright (c) 2017 Ultimaker B.V.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+from UM.Settings.ContainerRegistry import ContainerRegistry #To listen for changes to the materials.
+from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel #We're extending this class.
+
+## A model that shows a list of currently valid materials.
+class MaterialsModel(InstanceContainersModel):
+ def __init__(self, parent = None):
+ super().__init__(parent)
+
+ ContainerRegistry.getInstance().containerMetaDataChanged.connect(self._onContainerMetaDataChanged)
+
+ ## Called when the metadata of the container was changed.
+ #
+ # This makes sure that we only update when it was a material that changed.
+ #
+ # \param container The container whose metadata was changed.
+ def _onContainerMetaDataChanged(self, container):
+ if container.getMetaDataEntry("type") == "material": #Only need to update if a material was changed.
+ self._update() \ No newline at end of file