User can now select what strategy to use per conflict

CURA-1263
This commit is contained in:
Jaime van Kessel 2016-11-15 15:10:10 +01:00
parent 47d0e95e53
commit f0eb5e0da3
3 changed files with 154 additions and 33 deletions

View file

@ -82,17 +82,23 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
if machine_conflict or quality_changes_conflict: if machine_conflict or quality_changes_conflict:
# There is a conflict; User should choose to either update the existing data, add everything as new data or abort # There is a conflict; User should choose to either update the existing data, add everything as new data or abort
self._resolve_strategies = {} self._dialog.setMachineConflict(machine_conflict)
self._dialog.setQualityChangesConflict(quality_changes_conflict)
self._dialog.show() self._dialog.show()
self._dialog.waitForClose() self._dialog.waitForClose()
if self._dialog.getResult() == "cancel": if self._dialog.getResult() == {}:
return WorkspaceReader.PreReadResult.cancelled return WorkspaceReader.PreReadResult.cancelled
result = self._dialog.getResult() result = self._dialog.getResult()
# If there is no conflict, ignore the data.
print("beep", result)
if not machine_conflict:
result["machine"] = None
if not quality_changes_conflict:
result["quality_changes"] = None
if machine_conflict:
self._resolve_strategies["machine"] = result self._resolve_strategies = result
if quality_changes_conflict: print("STRATEGY WAS", self._resolve_strategies)
self._resolve_strategies["quality_changes"] = result
return WorkspaceReader.PreReadResult.accepted return WorkspaceReader.PreReadResult.accepted

View file

@ -1,7 +1,8 @@
from PyQt5.QtCore import Qt, QUrl, pyqtSignal, pyqtSlot, QObject from PyQt5.QtCore import Qt, QUrl, pyqtSignal, pyqtSlot, QObject, pyqtProperty
from PyQt5.QtQml import QQmlComponent, QQmlContext from PyQt5.QtQml import QQmlComponent, QQmlContext
from UM.PluginRegistry import PluginRegistry from UM.PluginRegistry import PluginRegistry
from UM.Application import Application from UM.Application import Application
from UM.Logger import Logger
import os import os
import threading import threading
@ -16,10 +17,36 @@ class WorkspaceDialog(QObject):
self._view = None self._view = None
self._qml_url = "WorkspaceDialog.qml" self._qml_url = "WorkspaceDialog.qml"
self._lock = threading.Lock() self._lock = threading.Lock()
self._result = None # What option did the user pick? self._default_strategy = "override"
self._result = {"machine": self._default_strategy, "quality_changes": self._default_strategy}
self._visible = False self._visible = False
self.showDialogSignal.connect(self.__show) self.showDialogSignal.connect(self.__show)
self._has_quality_changes_conflict = False
self._has_machine_conflict = False
machineConflictChanged = pyqtSignal()
qualityChangesConflictChanged = pyqtSignal()
@pyqtProperty(bool, notify = machineConflictChanged)
def machineConflict(self):
return self._has_machine_conflict
@pyqtProperty(bool, notify=qualityChangesConflictChanged)
def qualityChangesConflict(self):
return self._has_quality_changes_conflict
@pyqtSlot(str, str)
def setResolveStrategy(self, key, strategy):
if key in self._result:
self._result[key] = strategy
def setMachineConflict(self, machine_conflict):
self._has_machine_conflict = machine_conflict
def setQualityChangesConflict(self, quality_changes_conflict):
self._has_quality_changes_conflict = quality_changes_conflict
def getResult(self): def getResult(self):
return self._result return self._result
@ -29,11 +56,15 @@ class WorkspaceDialog(QObject):
self._context = QQmlContext(Application.getInstance()._engine.rootContext()) self._context = QQmlContext(Application.getInstance()._engine.rootContext())
self._context.setContextProperty("manager", self) self._context.setContextProperty("manager", self)
self._view = self._component.create(self._context) self._view = self._component.create(self._context)
if self._view is None:
Logger.log("e", "QQmlComponent status %s", self._component.status())
Logger.log("e", "QQmlComponent errorString %s", self._component.errorString())
def show(self): def show(self):
# Emit signal so the right thread actually shows the view. # Emit signal so the right thread actually shows the view.
self._lock.acquire() self._lock.acquire()
self._result = None # Reset the result
self._result = {"machine": self._default_strategy, "quality_changes": self._default_strategy}
self._visible = True self._visible = True
self.showDialogSignal.emit() self.showDialogSignal.emit()
@ -41,7 +72,7 @@ class WorkspaceDialog(QObject):
## Used to notify the dialog so the lock can be released. ## Used to notify the dialog so the lock can be released.
def notifyClosed(self): def notifyClosed(self):
if self._result is None: if self._result is None:
self._result = "cancel" self._result = {}
self._lock.release() self._lock.release()
def hide(self): def hide(self):
@ -50,22 +81,15 @@ class WorkspaceDialog(QObject):
self._view.hide() self._view.hide()
@pyqtSlot() @pyqtSlot()
def onOverrideButtonClicked(self): def onOkButtonClicked(self):
self._view.hide() self._view.hide()
self.hide() self.hide()
self._result = "override"
@pyqtSlot()
def onNewButtonClicked(self):
self._view.hide()
self.hide()
self._result = "new"
@pyqtSlot() @pyqtSlot()
def onCancelButtonClicked(self): def onCancelButtonClicked(self):
self._view.hide() self._view.hide()
self.hide() self.hide()
self._result = "cancel" self._result = {}
## Block thread until the dialog is closed. ## Block thread until the dialog is closed.
def waitForClose(self): def waitForClose(self):
@ -76,4 +100,5 @@ class WorkspaceDialog(QObject):
def __show(self): def __show(self):
if self._view is None: if self._view is None:
self._createViewFromQML() self._createViewFromQML()
if self._view:
self._view.show() self._view.show()

View file

@ -10,7 +10,7 @@ import UM 1.1 as UM
UM.Dialog UM.Dialog
{ {
title: catalog.i18nc("@title:window", "Conflict") title: catalog.i18nc("@title:window", "Import workspace conflict")
width: 350 * Screen.devicePixelRatio; width: 350 * Screen.devicePixelRatio;
minimumWidth: 350 * Screen.devicePixelRatio; minimumWidth: 350 * Screen.devicePixelRatio;
@ -21,24 +21,114 @@ UM.Dialog
maximumHeight: 250 * Screen.devicePixelRatio; maximumHeight: 250 * Screen.devicePixelRatio;
onClosing: manager.notifyClosed() onClosing: manager.notifyClosed()
onVisibleChanged:
{
if(visible)
{
machineResolveComboBox.currentIndex = 0
qualityChangesResolveComboBox.currentIndex = 0
}
}
Item Item
{ {
UM.I18nCatalog { id: catalog; name: "cura"; } anchors.fill: parent
UM.I18nCatalog
{
id: catalog;
name: "cura";
}
ListModel
{
id: resolveStrategiesModel
// Instead of directly adding the list elements, we add them afterwards.
// This is because it's impossible to use setting function results to be bound to listElement properties directly.
// See http://stackoverflow.com/questions/7659442/listelement-fields-as-properties
Component.onCompleted:
{
append({"key": "override", "label": catalog.i18nc("@action:ComboBox option", "Override existing")});
append({"key": "new", "label": catalog.i18nc("@action:ComboBox option", "Create new")});
}
}
Column
{
anchors.fill: parent
Label
{
id: infoLabel
width: parent.width
text: catalog.i18nc("@action:label", "Cura detected a number of conflicts while importing the workspace. How would you like to resolve these?")
wrapMode: Text.Wrap
height: 50
}
UM.TooltipArea
{
id: machineResolveTooltip
width: parent.width
height: visible ? 25 : 0
text: catalog.i18nc("@info:tooltip", "How should the conflict in the machine be resolved?")
visible: manager.machineConflict
Row
{
width: parent.width
height: childrenRect.height
Label
{
text: catalog.i18nc("@action:label","Machine")
width: 150
}
ComboBox
{
model: resolveStrategiesModel
textRole: "label"
id: machineResolveComboBox
onActivated:
{
manager.setResolveStrategy("machine", resolveStrategiesModel.get(index).key)
}
}
}
}
UM.TooltipArea
{
id: qualityChangesResolveTooltip
width: parent.width
height: visible ? 25 : 0
text: catalog.i18nc("@info:tooltip", "How should the conflict in the profile be resolved?")
visible: manager.qualityChangesConflict
Row
{
width: parent.width
height: childrenRect.height
Label
{
text: catalog.i18nc("@action:label","Profile")
width: 150
}
ComboBox
{
model: resolveStrategiesModel
textRole: "label"
id: qualityChangesResolveComboBox
onActivated:
{
manager.setResolveStrategy("machine", resolveStrategiesModel.get(index).key)
}
}
}
}
}
} }
rightButtons: [ rightButtons: [
Button Button
{ {
id: override_button id: ok_button
text: catalog.i18nc("@action:button","Override"); text: catalog.i18nc("@action:button","OK");
onClicked: { manager.onOverrideButtonClicked() } onClicked: { manager.onOkButtonClicked() }
enabled: true
},
Button
{
id: create_new
text: catalog.i18nc("@action:button","Create new");
onClicked: { manager.onNewButtonClicked() }
enabled: true enabled: true
}, },
Button Button