CURA-4870 Update the selected configuration in the UI when the

configuration in the printer changes.
Modify again the hash function.
This commit is contained in:
Diego Prado Gesto 2018-03-06 09:24:42 +01:00
parent d83eb383d9
commit d02d845d1b
4 changed files with 14 additions and 9 deletions

View file

@ -52,7 +52,13 @@ class ConfigurationModel(QObject):
return hash(self) == hash(other) return hash(self) == hash(other)
def __hash__(self): def __hash__(self):
extruder_hash = hash(self.extruderConfigurations[0]) # Use the hash of the first extruder as a seed extruder_hash = hash(0)
first_extruder = None
for configuration in self.extruderConfigurations: for configuration in self.extruderConfigurations:
extruder_hash ^= hash(configuration) extruder_hash ^= hash(configuration)
if configuration.position == 0:
first_extruder = configuration
if first_extruder:
extruder_hash &= hash(first_extruder)
return hash(self._printer_type) ^ extruder_hash ^ hash(self._buildplate_configuration) return hash(self._printer_type) ^ extruder_hash ^ hash(self._buildplate_configuration)

View file

@ -187,6 +187,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
def _updateUniqueConfigurations(self): def _updateUniqueConfigurations(self):
self._unique_configurations = list(set([printer.printerConfiguration for printer in self._printers])) self._unique_configurations = list(set([printer.printerConfiguration for printer in self._printers]))
self._unique_configurations.sort(key = lambda k: k.printerType)
self.uniqueConfigurationsChanged.emit() self.uniqueConfigurationsChanged.emit()
def _onPrintersChanged(self): def _onPrintersChanged(self):

View file

@ -13,7 +13,7 @@ Rectangle
property var configuration: null property var configuration: null
property var selected: false property var selected: false
signal configurationSelected() signal activateConfiguration()
height: childrenRect.height height: childrenRect.height
border.width: UM.Theme.getSize("default_lining").width border.width: UM.Theme.getSize("default_lining").width
@ -96,7 +96,7 @@ Rectangle
{ {
id: mouse id: mouse
anchors.fill: parent anchors.fill: parent
onClicked: configurationSelected() onClicked: activateConfiguration()
hoverEnabled: true hoverEnabled: true
onEntered: parent.border.color = UM.Theme.getColor("primary_hover") onEntered: parent.border.color = UM.Theme.getColor("primary_hover")
onExited: parent.border.color = "black" onExited: parent.border.color = "black"
@ -109,10 +109,7 @@ Rectangle
} }
} }
Connections { Component.onCompleted: {
target: configuration
onConfigurationChanged: {
configurationItem.selected = Cura.MachineManager.matchesConfiguration(configuration) configurationItem.selected = Cura.MachineManager.matchesConfiguration(configuration)
} }
}
} }

View file

@ -46,6 +46,7 @@ Column
target: outputDevice target: outputDevice
onUniqueConfigurationsChanged: { onUniqueConfigurationsChanged: {
// FIXME For now the model should be removed and then created again, otherwise changes in the printer don't automatically update the UI // FIXME For now the model should be removed and then created again, otherwise changes in the printer don't automatically update the UI
print("Update unique configurations")
configurationList.model = null configurationList.model = null
configurationList.model = outputDevice.uniqueConfigurations configurationList.model = outputDevice.uniqueConfigurations
} }
@ -63,7 +64,7 @@ Column
{ {
width: parent.width width: parent.width
configuration: modelData configuration: modelData
onConfigurationSelected: onActivateConfiguration:
{ {
print("SELECCIONANDO CONFIGURACION", JSON.stringify(configuration)) print("SELECCIONANDO CONFIGURACION", JSON.stringify(configuration))
} }