DiscardOrKeepProfileChangesDialog.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //Copyright (c) 2022 Ultimaker B.V.
  2. //Cura is released under the terms of the LGPLv3 or higher.
  3. import Qt.labs.qmlmodels 1.0
  4. import QtQuick 2.1
  5. import QtQuick.Controls 2.15
  6. import UM 1.5 as UM
  7. import Cura 1.6 as Cura
  8. UM.Dialog
  9. {
  10. id: base
  11. title: catalog.i18nc("@title:window", "Discard or Keep changes")
  12. onAccepted: CuraApplication.discardOrKeepProfileChangesClosed("discard")
  13. onRejected: CuraApplication.discardOrKeepProfileChangesClosed("keep")
  14. minimumWidth: UM.Theme.getSize("popup_dialog").width
  15. minimumHeight: UM.Theme.getSize("popup_dialog").height
  16. width: minimumWidth
  17. height: minimumHeight
  18. backgroundColor: UM.Theme.getColor("background_1")
  19. margin: UM.Theme.getSize("thick_margin").width
  20. property var changesModel: Cura.UserChangesModel { id: userChangesModel }
  21. onVisibilityChanged:
  22. {
  23. if(visible)
  24. {
  25. changesModel.forceUpdate()
  26. discardOrKeepProfileChangesDropDownButton.currentIndex = 0;
  27. for (var i = 0; i < discardOrKeepProfileChangesDropDownButton.model.count; ++i)
  28. {
  29. var code = discardOrKeepProfileChangesDropDownButton.model.get(i).code;
  30. if (code == UM.Preferences.getValue("cura/choice_on_profile_override"))
  31. {
  32. discardOrKeepProfileChangesDropDownButton.currentIndex = i;
  33. break;
  34. }
  35. }
  36. }
  37. }
  38. UM.Label
  39. {
  40. id: infoText
  41. 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"])
  42. anchors.left: parent.left
  43. anchors.right: parent.right
  44. wrapMode: Text.WordWrap
  45. UM.I18nCatalog
  46. {
  47. id: catalog
  48. name: "cura"
  49. }
  50. }
  51. Item
  52. {
  53. anchors.topMargin: UM.Theme.getSize("default_margin").height
  54. anchors.top: infoText.bottom
  55. anchors.bottom: parent.bottom
  56. anchors.left: parent.left
  57. anchors.right: parent.right
  58. Cura.TableView
  59. {
  60. id: tableView
  61. anchors.fill: parent
  62. columnHeaders: [
  63. catalog.i18nc("@title:column", "Profile settings"),
  64. Cura.MachineManager.activeQualityDisplayNameMap["main"],
  65. catalog.i18nc("@title:column", "Current changes")
  66. ]
  67. model: TableModel
  68. {
  69. TableModelColumn { display: "label" }
  70. TableModelColumn { display: "original_value" }
  71. TableModelColumn { display: "user_value" }
  72. rows: userChangesModel.items
  73. }
  74. sectionRole: "category"
  75. }
  76. }
  77. buttonSpacing: UM.Theme.getSize("thin_margin").width
  78. leftButtons: [
  79. Cura.ComboBox
  80. {
  81. implicitHeight: UM.Theme.getSize("combobox").height
  82. implicitWidth: UM.Theme.getSize("combobox").width
  83. id: discardOrKeepProfileChangesDropDownButton
  84. textRole: "text"
  85. model: ListModel
  86. {
  87. id: discardOrKeepProfileListModel
  88. Component.onCompleted: {
  89. append({ text: catalog.i18nc("@option:discardOrKeep", "Always ask me this"), code: "always_ask" })
  90. append({ text: catalog.i18nc("@option:discardOrKeep", "Discard and never ask again"), code: "always_discard" })
  91. append({ text: catalog.i18nc("@option:discardOrKeep", "Keep and never ask again"), code: "always_keep" })
  92. }
  93. }
  94. onActivated:
  95. {
  96. var code = model.get(index).code;
  97. UM.Preferences.setValue("cura/choice_on_profile_override", code);
  98. if (code == "always_keep") {
  99. keepButton.enabled = true;
  100. discardButton.enabled = false;
  101. }
  102. else if (code == "always_discard") {
  103. keepButton.enabled = false;
  104. discardButton.enabled = true;
  105. }
  106. else {
  107. keepButton.enabled = true;
  108. discardButton.enabled = true;
  109. }
  110. }
  111. }
  112. ]
  113. rightButtons:
  114. [
  115. Cura.PrimaryButton
  116. {
  117. id: discardButton
  118. text: catalog.i18nc("@action:button", "Discard changes")
  119. onClicked: base.accept()
  120. },
  121. Cura.SecondaryButton
  122. {
  123. id: keepButton
  124. text: catalog.i18nc("@action:button", "Keep changes")
  125. onClicked: base.reject()
  126. }
  127. ]
  128. }