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)
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:
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)

View file

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

View file

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

View file

@ -46,6 +46,7 @@ Column
target: outputDevice
onUniqueConfigurationsChanged: {
// 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 = outputDevice.uniqueConfigurations
}
@ -63,7 +64,7 @@ Column
{
width: parent.width
configuration: modelData
onConfigurationSelected:
onActivateConfiguration:
{
print("SELECCIONANDO CONFIGURACION", JSON.stringify(configuration))
}