QualityDatabaseHandler.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) 2021 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Settings.SQLQueryFactory import SQLQueryFactory, metadata_type
  4. from UM.Settings.DatabaseContainerMetadataController import DatabaseMetadataContainerController
  5. from UM.Settings.InstanceContainer import InstanceContainer
  6. class QualityDatabaseHandler(DatabaseMetadataContainerController):
  7. """The Database handler for Quality containers"""
  8. def __init__(self):
  9. super().__init__(SQLQueryFactory(table = "quality",
  10. fields = {
  11. "id": "text",
  12. "name": "text",
  13. "quality_type": "text",
  14. "material": "text",
  15. "variant": "text",
  16. "global_quality": "bool",
  17. "definition": "text",
  18. "version": "text",
  19. "setting_version": "text"
  20. }))
  21. self._container_type = InstanceContainer
  22. def groomMetadata(self, metadata: metadata_type) -> metadata_type:
  23. """
  24. Ensures that the metadata is in the order of the field keys and has the right size.
  25. if the metadata doesn't contains a key which is stored in the DB it will add it as
  26. an empty string. Key, value pairs that are not stored in the DB are dropped.
  27. If the `global_quality` isn't set it well default to 'False'
  28. :param metadata: The container metadata
  29. """
  30. if "global_quality" not in metadata:
  31. metadata["global_quality"] = "False"
  32. return super().groomMetadata(metadata)