Appease reviewers.

- Ditch state in favour of enum.
- Comment explaining 'extraInfo'.

part of CURA-9347
This commit is contained in:
Remco Burema 2022-12-02 19:52:37 +01:00
parent 9fe261ff58
commit c74e7be602
5 changed files with 27 additions and 26 deletions

View file

@ -709,7 +709,7 @@ class CuraApplication(QtApplication):
self.showMessageBox.emit(title, text, informativeText, detailedText, buttons, icon) self.showMessageBox.emit(title, text, informativeText, detailedText, buttons, icon)
showDiscardOrKeepProfileChanges = pyqtSignal() showDiscardOrKeepProfileChanges = pyqtSignal()
showCompareAndSaveProfileChanges = pyqtSignal(str) showCompareAndSaveProfileChanges = pyqtSignal(int)
def discardOrKeepProfileChanges(self) -> bool: def discardOrKeepProfileChanges(self) -> bool:
has_user_interaction = False has_user_interaction = False

View file

@ -804,10 +804,13 @@ UM.MainWindow
function onShowCompareAndSaveProfileChanges(profileState) function onShowCompareAndSaveProfileChanges(profileState)
{ {
discardOrKeepProfileChangesDialogLoader.sourceComponent = discardOrKeepProfileChangesDialogComponent discardOrKeepProfileChangesDialogLoader.sourceComponent = discardOrKeepProfileChangesDialogComponent
discardOrKeepProfileChangesDialogLoader.item.state = profileState discardOrKeepProfileChangesDialogLoader.item.buttonState = profileState
discardOrKeepProfileChangesDialogLoader.item.show() discardOrKeepProfileChangesDialogLoader.item.show()
} }
function onShowDiscardOrKeepProfileChanges() { onShowCompareAndSaveProfileChanges("") } function onShowDiscardOrKeepProfileChanges()
{
onShowCompareAndSaveProfileChanges(DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep)
}
} }
Cura.WizardDialog Cura.WizardDialog

View file

@ -12,10 +12,13 @@ UM.Dialog
id: base id: base
title: catalog.i18nc("@title:window", "Discard or Keep changes") title: catalog.i18nc("@title:window", "Discard or Keep changes")
property alias state: alternateStates.state enum ButtonsType { DiscardOrKeep, SaveFromBuiltIn, SaveFromCustom}
property int buttonState: DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
onAccepted: alternateStates.state == "" ? CuraApplication.discardOrKeepProfileChangesClosed("discard") : Cura.Actions.addProfile.trigger() onAccepted: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep ?
onRejected: alternateStates.state == "" ? CuraApplication.discardOrKeepProfileChangesClosed("keep") : Cura.Actions.updateProfile.trigger() CuraApplication.discardOrKeepProfileChangesClosed("discard") : Cura.Actions.addProfile.trigger()
onRejected: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep ?
CuraApplication.discardOrKeepProfileChangesClosed("keep") : Cura.Actions.updateProfile.trigger()
minimumWidth: UM.Theme.getSize("popup_dialog").width minimumWidth: UM.Theme.getSize("popup_dialog").width
minimumHeight: UM.Theme.getSize("popup_dialog").height minimumHeight: UM.Theme.getSize("popup_dialog").height
@ -100,25 +103,11 @@ UM.Dialog
buttonSpacing: UM.Theme.getSize("thin_margin").width buttonSpacing: UM.Theme.getSize("thin_margin").width
Rectangle
{
// Use a rectangle to get access to states. For some reason top-levels like Dialog/Window ect. don't have them.
// NOTE: The default state is 'switch profiles', alternate states are used for 'save from [built-in|custom]'.
id: alternateStates
width: 0
height: 0
states:
[
State { name: "saveFromBuiltIn" },
State { name: "saveFromCustom" }
]
}
leftButtons: leftButtons:
[ [
Cura.ComboBox Cura.ComboBox
{ {
visible: alternateStates.state == "" visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
implicitHeight: UM.Theme.getSize("combobox").height implicitHeight: UM.Theme.getSize("combobox").height
implicitWidth: UM.Theme.getSize("combobox").width implicitWidth: UM.Theme.getSize("combobox").width
@ -165,27 +154,27 @@ UM.Dialog
id: discardButton id: discardButton
text: catalog.i18nc("@action:button", "Discard changes") text: catalog.i18nc("@action:button", "Discard changes")
onClicked: base.accept() onClicked: base.accept()
visible: alternateStates.state == "" visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
}, },
Cura.SecondaryButton Cura.SecondaryButton
{ {
id: keepButton id: keepButton
text: catalog.i18nc("@action:button", "Keep changes") text: catalog.i18nc("@action:button", "Keep changes")
onClicked: base.reject() onClicked: base.reject()
visible: alternateStates.state == "" visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
}, },
Cura.SecondaryButton Cura.SecondaryButton
{ {
id: overwriteButton id: overwriteButton
text: catalog.i18nc("@action:button", "Save as new custom profile") text: catalog.i18nc("@action:button", "Save as new custom profile")
visible: alternateStates.state != "" visible: buttonState != DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
onClicked: base.accept() onClicked: base.accept()
}, },
Cura.PrimaryButton Cura.PrimaryButton
{ {
id: saveButton id: saveButton
text: catalog.i18nc("@action:button", "Save changes") text: catalog.i18nc("@action:button", "Save changes")
visible: alternateStates.state == "saveFromCustom" visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.SaveFromCustom
onClicked: base.reject() onClicked: base.reject()
} }
] ]

View file

@ -24,6 +24,8 @@ UM.Dialog
property string explanation: catalog.i18nc("@info", "Please provide a new name.") property string explanation: catalog.i18nc("@info", "Please provide a new name.")
property string okButtonText: catalog.i18nc("@action:button", "OK") property string okButtonText: catalog.i18nc("@action:button", "OK")
// Extra Information for the user about the current rename can go here, can be left alone if not needed.
// For example; An icon and a text-field and a tertiary button providing a link.
property list<Item> extraInfo property list<Item> extraInfo
title: dialogTitle title: dialogTitle

View file

@ -6,6 +6,8 @@ import QtQuick 2.10
import UM 1.6 as UM import UM 1.6 as UM
import Cura 1.6 as Cura import Cura 1.6 as Cura
import "../Dialogs"
Item Item
{ {
property bool fullWarning: true // <- Can you see the warning icon and the text, or is it just the buttons? property bool fullWarning: true // <- Can you see the warning icon and the text, or is it just the buttons?
@ -144,7 +146,12 @@ Item
hoverColor: UM.Theme.getColor("primary_hover") hoverColor: UM.Theme.getColor("primary_hover")
enabled: Cura.SimpleModeSettingsManager.isProfileCustomized enabled: Cura.SimpleModeSettingsManager.isProfileCustomized
onClicked: CuraApplication.showCompareAndSaveProfileChanges(Cura.MachineManager.hasCustomQuality ? "saveFromCustom" : "saveFromBuiltIn") onClicked: CuraApplication.showCompareAndSaveProfileChanges
(
Cura.MachineManager.hasCustomQuality ?
DiscardOrKeepProfileChangesDialog.ButtonsType.SaveFromCustom :
DiscardOrKeepProfileChangesDialog.ButtonsType.SaveFromBuiltIn
)
UM.ToolTip UM.ToolTip
{ {