SpecificSettingsModel.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.Logger import Logger
  5. from UM.Settings.SettingDefinition import SettingDefinition
  6. from UM.Qt.ListModel import ListModel
  7. class SpecificSettingsModel(ListModel):
  8. CategoryRole = Qt.ItemDataRole.UserRole + 1
  9. LabelRole = Qt.ItemDataRole.UserRole + 2
  10. ValueRole = Qt.ItemDataRole.UserRole + 3
  11. def __init__(self, parent = None):
  12. super().__init__(parent = parent)
  13. self.addRoleName(self.CategoryRole, "category")
  14. self.addRoleName(self.LabelRole, "label")
  15. self.addRoleName(self.ValueRole, "value")
  16. self._i18n_catalog = None
  17. self._update()
  18. def addSettingsFromStack(self, stack, category, settings):
  19. for setting, value in settings.items():
  20. unit = stack.getProperty(setting, "unit")
  21. setting_type = stack.getProperty(setting, "type")
  22. if setting_type is not None:
  23. # This is not very good looking, but will do for now
  24. value = str(SettingDefinition.settingValueToString(setting_type, value)) + " " + str(unit)
  25. else:
  26. value = str(value)
  27. self.appendItem({
  28. "category": category,
  29. "label": stack.getProperty(setting, "label"),
  30. "value": value
  31. })
  32. def _update(self):
  33. Logger.debug(f"Updating {self.__class__.__name__}")
  34. self.setItems([])
  35. return