SpecificSettingsModel.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) 2024 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt6.QtCore import Qt
  4. from UM.Settings.SettingDefinition import SettingDefinition
  5. from UM.Qt.ListModel import ListModel
  6. class SpecificSettingsModel(ListModel):
  7. CategoryRole = Qt.ItemDataRole.UserRole + 1
  8. LabelRole = Qt.ItemDataRole.UserRole + 2
  9. ValueRole = Qt.ItemDataRole.UserRole + 3
  10. def __init__(self, parent = None):
  11. super().__init__(parent = parent)
  12. self.addRoleName(self.CategoryRole, "category")
  13. self.addRoleName(self.LabelRole, "label")
  14. self.addRoleName(self.ValueRole, "value")
  15. self._i18n_catalog = None
  16. def addSettingsFromStack(self, stack, category, settings):
  17. for setting, value in settings.items():
  18. unit = stack.getProperty(setting, "unit")
  19. setting_type = stack.getProperty(setting, "type")
  20. if setting_type is not None:
  21. # This is not very good looking, but will do for now
  22. value = SettingDefinition.settingValueToString(setting_type, value) + " " + unit
  23. else:
  24. value = str(value)
  25. self.appendItem({
  26. "category": category,
  27. "label": stack.getProperty(setting, "label"),
  28. "value": value
  29. })