From d02d845d1bc8645c9d26f003728690ff95f6b80b Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Tue, 6 Mar 2018 09:24:42 +0100 Subject: [PATCH] CURA-4870 Update the selected configuration in the UI when the configuration in the printer changes. Modify again the hash function. --- cura/PrinterOutput/ConfigurationModel.py | 8 +++++++- cura/PrinterOutputDevice.py | 1 + .../qml/Menus/ConfigurationMenu/ConfigurationItem.qml | 11 ++++------- .../Menus/ConfigurationMenu/ConfigurationListView.qml | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cura/PrinterOutput/ConfigurationModel.py b/cura/PrinterOutput/ConfigurationModel.py index 8138543d7b..230a734797 100644 --- a/cura/PrinterOutput/ConfigurationModel.py +++ b/cura/PrinterOutput/ConfigurationModel.py @@ -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) \ No newline at end of file diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index 875cc17fe8..d2916016e0 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -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): diff --git a/resources/qml/Menus/ConfigurationMenu/ConfigurationItem.qml b/resources/qml/Menus/ConfigurationMenu/ConfigurationItem.qml index b28c5b4812..ae97a82207 100644 --- a/resources/qml/Menus/ConfigurationMenu/ConfigurationItem.qml +++ b/resources/qml/Menus/ConfigurationMenu/ConfigurationItem.qml @@ -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: { - configurationItem.selected = Cura.MachineManager.matchesConfiguration(configuration) - } + Component.onCompleted: { + configurationItem.selected = Cura.MachineManager.matchesConfiguration(configuration) } } \ No newline at end of file diff --git a/resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml b/resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml index bc257c8a61..2effa5177f 100644 --- a/resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml +++ b/resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml @@ -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)) }