DiscardOrKeepProfileChangesDialog.qml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //Copyright (c) 2022 Ultimaker B.V.
  2. //Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 2.15
  5. import UM 1.6 as UM
  6. import Cura 1.6 as Cura
  7. UM.Dialog
  8. {
  9. id: base
  10. title: catalog.i18nc("@title:window", "Discard or Keep changes")
  11. enum ButtonsType { DiscardOrKeep, SaveFromBuiltIn, SaveFromCustom}
  12. property int buttonState: DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  13. onAccepted: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep ?
  14. CuraApplication.discardOrKeepProfileChangesClosed("discard") : Cura.Actions.addProfile.trigger()
  15. onRejected: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep ?
  16. CuraApplication.discardOrKeepProfileChangesClosed("keep") : Cura.Actions.updateProfile.trigger()
  17. minimumWidth: UM.Theme.getSize("popup_dialog").width
  18. minimumHeight: UM.Theme.getSize("popup_dialog").height
  19. width: minimumWidth
  20. height: minimumHeight
  21. backgroundColor: UM.Theme.getColor("background_1")
  22. margin: UM.Theme.getSize("thick_margin").width
  23. property var changesModel: Cura.UserChangesModel { id: userChangesModel }
  24. // Hack to make sure that when the data of our model changes the tablemodel is also updated
  25. // If we directly set the rows (So without the clear being called) it doesn't seem to
  26. // get updated correctly.
  27. property var modelRows: userChangesModel.items
  28. onModelRowsChanged:
  29. {
  30. tableModel.clear()
  31. tableModel.rows = modelRows
  32. }
  33. onVisibilityChanged:
  34. {
  35. if(visible)
  36. {
  37. changesModel.forceUpdate()
  38. discardOrKeepProfileChangesDropDownButton.currentIndex = 0;
  39. for (var i = 0; i < discardOrKeepProfileChangesDropDownButton.model.count; ++i)
  40. {
  41. var code = discardOrKeepProfileChangesDropDownButton.model.get(i).code;
  42. if (code == UM.Preferences.getValue("cura/choice_on_profile_override"))
  43. {
  44. discardOrKeepProfileChangesDropDownButton.currentIndex = i;
  45. break;
  46. }
  47. }
  48. }
  49. }
  50. UM.Label
  51. {
  52. id: infoText
  53. text: catalog.i18nc("@text:window, %1 is a profile name", "You have customized some profile settings. Would you like to Keep these changed settings after switching profiles? Alternatively, you can discard the changes to load the defaults from '%1'.").arg(Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - "))
  54. anchors.left: parent.left
  55. anchors.right: parent.right
  56. wrapMode: Text.WordWrap
  57. UM.I18nCatalog
  58. {
  59. id: catalog
  60. name: "cura"
  61. }
  62. }
  63. Item
  64. {
  65. anchors.topMargin: UM.Theme.getSize("default_margin").height
  66. anchors.top: infoText.bottom
  67. anchors.bottom: parent.bottom
  68. anchors.left: parent.left
  69. anchors.right: parent.right
  70. Cura.TableView
  71. {
  72. id: tableView
  73. anchors.fill: parent
  74. columnHeaders: [
  75. catalog.i18nc("@title:column", "Profile settings"),
  76. Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - "),
  77. catalog.i18nc("@title:column", "Current changes")
  78. ]
  79. model: UM.TableModel
  80. {
  81. id: tableModel
  82. headers: ["label", "original_value", "user_value"]
  83. rows: modelRows
  84. }
  85. sectionRole: "category"
  86. }
  87. }
  88. buttonSpacing: UM.Theme.getSize("thin_margin").width
  89. leftButtons:
  90. [
  91. Cura.ComboBox
  92. {
  93. visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  94. implicitHeight: UM.Theme.getSize("combobox").height
  95. implicitWidth: UM.Theme.getSize("combobox").width
  96. id: discardOrKeepProfileChangesDropDownButton
  97. textRole: "text"
  98. model: ListModel
  99. {
  100. id: discardOrKeepProfileListModel
  101. Component.onCompleted: {
  102. append({ text: catalog.i18nc("@option:discardOrKeep", "Always ask me this"), code: "always_ask" })
  103. append({ text: catalog.i18nc("@option:discardOrKeep", "Discard and never ask again"), code: "always_discard" })
  104. append({ text: catalog.i18nc("@option:discardOrKeep", "Keep and never ask again"), code: "always_keep" })
  105. }
  106. }
  107. onActivated:
  108. {
  109. var code = model.get(index).code;
  110. UM.Preferences.setValue("cura/choice_on_profile_override", code);
  111. if (code == "always_keep") {
  112. keepButton.enabled = true;
  113. discardButton.enabled = false;
  114. }
  115. else if (code == "always_discard") {
  116. keepButton.enabled = false;
  117. discardButton.enabled = true;
  118. }
  119. else {
  120. keepButton.enabled = true;
  121. discardButton.enabled = true;
  122. }
  123. }
  124. }
  125. ]
  126. rightButtons:
  127. [
  128. Cura.PrimaryButton
  129. {
  130. id: discardButton
  131. text: catalog.i18nc("@action:button", "Discard changes")
  132. onClicked: base.accept()
  133. visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  134. },
  135. Cura.SecondaryButton
  136. {
  137. id: keepButton
  138. text: catalog.i18nc("@action:button", "Keep changes")
  139. onClicked: base.reject()
  140. visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  141. },
  142. Cura.SecondaryButton
  143. {
  144. id: overwriteButton
  145. text: catalog.i18nc("@action:button", "Save as new custom profile")
  146. visible: buttonState != DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  147. onClicked: base.accept()
  148. },
  149. Cura.PrimaryButton
  150. {
  151. id: saveButton
  152. text: catalog.i18nc("@action:button", "Save changes")
  153. visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.SaveFromCustom
  154. onClicked: base.reject()
  155. }
  156. ]
  157. }