DiscardOrKeepProfileChangesDialog.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. onAccepted: CuraApplication.discardOrKeepProfileChangesClosed("discard")
  12. onRejected: CuraApplication.discardOrKeepProfileChangesClosed("keep")
  13. minimumWidth: UM.Theme.getSize("popup_dialog").width
  14. minimumHeight: UM.Theme.getSize("popup_dialog").height
  15. width: minimumWidth
  16. height: minimumHeight
  17. backgroundColor: UM.Theme.getColor("background_1")
  18. margin: UM.Theme.getSize("thick_margin").width
  19. property var changesModel: Cura.UserChangesModel { id: userChangesModel }
  20. // Hack to make sure that when the data of our model changes the tablemodel is also updated
  21. // If we directly set the rows (So without the clear being called) it doesn't seem to
  22. // get updated correctly.
  23. property var modelRows: userChangesModel.items
  24. onModelRowsChanged:
  25. {
  26. tableModel.clear()
  27. tableModel.rows = modelRows
  28. }
  29. onVisibilityChanged:
  30. {
  31. if(visible)
  32. {
  33. changesModel.forceUpdate()
  34. discardOrKeepProfileChangesDropDownButton.currentIndex = 0;
  35. for (var i = 0; i < discardOrKeepProfileChangesDropDownButton.model.count; ++i)
  36. {
  37. var code = discardOrKeepProfileChangesDropDownButton.model.get(i).code;
  38. if (code == UM.Preferences.getValue("cura/choice_on_profile_override"))
  39. {
  40. discardOrKeepProfileChangesDropDownButton.currentIndex = i;
  41. break;
  42. }
  43. }
  44. }
  45. }
  46. UM.Label
  47. {
  48. id: infoText
  49. 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.activeQualityDisplayNameMap["main"])
  50. anchors.left: parent.left
  51. anchors.right: parent.right
  52. wrapMode: Text.WordWrap
  53. UM.I18nCatalog
  54. {
  55. id: catalog
  56. name: "cura"
  57. }
  58. }
  59. Item
  60. {
  61. anchors.topMargin: UM.Theme.getSize("default_margin").height
  62. anchors.top: infoText.bottom
  63. anchors.bottom: parent.bottom
  64. anchors.left: parent.left
  65. anchors.right: parent.right
  66. Cura.TableView
  67. {
  68. id: tableView
  69. anchors.fill: parent
  70. columnHeaders: [
  71. catalog.i18nc("@title:column", "Profile settings"),
  72. Cura.MachineManager.activeQualityDisplayNameMap["main"],
  73. catalog.i18nc("@title:column", "Current changes")
  74. ]
  75. model: UM.TableModel
  76. {
  77. id: tableModel
  78. headers: ["label", "original_value", "user_value"]
  79. rows: modelRows
  80. }
  81. sectionRole: "category"
  82. }
  83. }
  84. buttonSpacing: UM.Theme.getSize("thin_margin").width
  85. leftButtons: [
  86. Cura.ComboBox
  87. {
  88. implicitHeight: UM.Theme.getSize("combobox").height
  89. implicitWidth: UM.Theme.getSize("combobox").width
  90. id: discardOrKeepProfileChangesDropDownButton
  91. textRole: "text"
  92. model: ListModel
  93. {
  94. id: discardOrKeepProfileListModel
  95. Component.onCompleted: {
  96. append({ text: catalog.i18nc("@option:discardOrKeep", "Always ask me this"), code: "always_ask" })
  97. append({ text: catalog.i18nc("@option:discardOrKeep", "Discard and never ask again"), code: "always_discard" })
  98. append({ text: catalog.i18nc("@option:discardOrKeep", "Keep and never ask again"), code: "always_keep" })
  99. }
  100. }
  101. onActivated:
  102. {
  103. var code = model.get(index).code;
  104. UM.Preferences.setValue("cura/choice_on_profile_override", code);
  105. if (code == "always_keep") {
  106. keepButton.enabled = true;
  107. discardButton.enabled = false;
  108. }
  109. else if (code == "always_discard") {
  110. keepButton.enabled = false;
  111. discardButton.enabled = true;
  112. }
  113. else {
  114. keepButton.enabled = true;
  115. discardButton.enabled = true;
  116. }
  117. }
  118. }
  119. ]
  120. rightButtons:
  121. [
  122. Cura.PrimaryButton
  123. {
  124. id: discardButton
  125. text: catalog.i18nc("@action:button", "Discard changes")
  126. onClicked: base.accept()
  127. },
  128. Cura.SecondaryButton
  129. {
  130. id: keepButton
  131. text: catalog.i18nc("@action:button", "Keep changes")
  132. onClicked: base.reject()
  133. }
  134. ]
  135. }