MaterialsDetailsPanel.qml 4.4 KB

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