MaterialsDetailsPanel.qml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.4
  5. import UM 1.5 as UM
  6. import Cura 1.5 as Cura
  7. Item
  8. {
  9. id: detailsPanel
  10. property var currentItem: null
  11. onCurrentItemChanged:
  12. {
  13. // When the current item changes, the detail view needs to be updated
  14. if (currentItem != null)
  15. {
  16. updateMaterialPropertiesObject()
  17. materialDetailsView.currentMaterialNode = currentItem.container_node
  18. }
  19. }
  20. function updateMaterialPropertiesObject()
  21. {
  22. // DRAGON WARNING!!! DO NOT TOUCH THIS IF YOU DON'T KNOW.
  23. // TL;DR: Always update "container_id" first!
  24. //
  25. // Other widgets such as MaterialsView have bindings towards "materialProperties" and its properties. Here the
  26. // properties are updated one by one, and each change can trigger a reaction on those widgets that have
  27. // connections to the property gets changed, and some reactions will use functions such as
  28. // ContainerManager.getContainerMetaDataEntry() to fetch data using the "container_id" as the reference.
  29. // We need to change "container_id" first so any underlying triggers will use the correct "container_id" to
  30. // fetch data. Or, for example, if we change GUID first, which triggered the weight widget to fetch weight
  31. // before we can update "container_id", so it will fetch weight with the wrong (old) "container_id".
  32. materialProperties.container_id = currentItem.id
  33. materialProperties.name = currentItem.name || "Unknown"
  34. materialProperties.guid = currentItem.GUID
  35. materialProperties.brand = currentItem.brand || "Unknown"
  36. materialProperties.material = currentItem.material || "Unknown"
  37. materialProperties.color_name = currentItem.color_name || "Yellow"
  38. materialProperties.color_code = currentItem.color_code || "yellow"
  39. materialProperties.description = currentItem.description || ""
  40. materialProperties.adhesion_info = currentItem.adhesion_info || ""
  41. materialProperties.density = currentItem.density || 0.0
  42. materialProperties.diameter = currentItem.diameter || 0.0
  43. materialProperties.approximate_diameter = currentItem.approximate_diameter || "0"
  44. }
  45. // Material detailed information view below the title Label
  46. MaterialsView
  47. {
  48. id: materialDetailsView
  49. anchors.fill: parent
  50. editingEnabled: currentItem != null && !currentItem.is_read_only
  51. onResetSelectedMaterial: base.resetExpandedActiveMaterial()
  52. properties: materialProperties
  53. containerId: currentItem != null ? currentItem.id : ""
  54. currentMaterialNode: currentItem != null ? currentItem.container_node: null
  55. }
  56. QtObject
  57. {
  58. id: materialProperties
  59. property string guid: "00000000-0000-0000-0000-000000000000"
  60. property string container_id: "Unknown";
  61. property string name: "Unknown";
  62. property string profile_type: "Unknown";
  63. property string brand: "Unknown";
  64. property string material: "Unknown"; // This needs to be named as "material" to be consistent with
  65. // the material container's metadata entry
  66. property string color_name: "Yellow";
  67. property color color_code: "yellow";
  68. property real density: 0.0;
  69. property real diameter: 0.0;
  70. property string approximate_diameter: "0";
  71. property real spool_cost: 0.0;
  72. property real spool_weight: 0.0;
  73. property real spool_length: 0.0;
  74. property real cost_per_meter: 0.0;
  75. property string description: "";
  76. property string adhesion_info: "";
  77. }
  78. }