From c65afbdd9794d732ab4abb72f74caa2890f3186c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Jul 2018 15:23:19 +1000 Subject: [PATCH] [processing] Correctly handle layer type parameter values when creating an algorithm dialog using processing.execAlgorithmDialog() --- python/plugins/processing/gui/wrappers.py | 75 ++++++++++++++++------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/python/plugins/processing/gui/wrappers.py b/python/plugins/processing/gui/wrappers.py index b7cf8af6b9e..4741da788a2 100755 --- a/python/plugins/processing/gui/wrappers.py +++ b/python/plugins/processing/gui/wrappers.py @@ -908,13 +908,24 @@ class MapLayerWidgetWrapper(WidgetWrapper): return if self.dialogType == DIALOG_STANDARD: - if self.combo.findText(value) >= 0: - self.combo.setCurrentIndex(self.combo.findText(value)) - else: - items = self.combo.additionalItems() - items.append(value) - self.combo.setAdditionalItems(items) - self.combo.setCurrentIndex(self.combo.findText(value)) + if isinstance(value, str): + layer = QgsProject.instance().mapLayer(value) + if layer is not None: + value = layer + + found = False + if isinstance(value, QgsMapLayer): + self.combo.setLayer(value) + found = self.combo.currentIndex() != -1 + + if not found: + if self.combo.findText(value) >= 0: + self.combo.setCurrentIndex(self.combo.findText(value)) + else: + items = self.combo.additionalItems() + items.append(value) + self.combo.setAdditionalItems(items) + self.combo.setCurrentIndex(self.combo.findText(value)) elif self.dialogType == DIALOG_BATCH: self.widget.setValue(value) else: @@ -1146,13 +1157,24 @@ class FeatureSourceWidgetWrapper(WidgetWrapper): return if self.dialogType == DIALOG_STANDARD: - if self.combo.findText(value) >= 0: - self.combo.setCurrentIndex(self.combo.findText(value)) - else: - items = self.combo.additionalItems() - items.append(value) - self.combo.setAdditionalItems(items) - self.combo.setCurrentIndex(self.combo.findText(value)) + if isinstance(value, str): + layer = QgsProject.instance().mapLayer(value) + if layer is not None: + value = layer + + found = False + if isinstance(value, QgsMapLayer): + self.combo.setLayer(value) + found = self.combo.currentIndex() != -1 + + if not found: + if self.combo.findText(value) >= 0: + self.combo.setCurrentIndex(self.combo.findText(value)) + else: + items = self.combo.additionalItems() + items.append(value) + self.combo.setAdditionalItems(items) + self.combo.setCurrentIndex(self.combo.findText(value)) elif self.dialogType == DIALOG_BATCH: self.widget.setValue(value) else: @@ -1448,13 +1470,24 @@ class VectorLayerWidgetWrapper(WidgetWrapper): return if self.dialogType == DIALOG_STANDARD: - if self.combo.findText(value) >= 0: - self.combo.setCurrentIndex(self.combo.findText(value)) - else: - items = self.combo.additionalItems() - items.append(value) - self.combo.setAdditionalItems(items) - self.combo.setCurrentIndex(self.combo.findText(value)) + if isinstance(value, str): + layer = QgsProject.instance().mapLayer(value) + if layer is not None: + value = layer + + found = False + if isinstance(value, QgsMapLayer): + self.combo.setLayer(value) + found = self.combo.currentIndex() != -1 + + if not found: + if self.combo.findText(value) >= 0: + self.combo.setCurrentIndex(self.combo.findText(value)) + else: + items = self.combo.additionalItems() + items.append(value) + self.combo.setAdditionalItems(items) + self.combo.setCurrentIndex(self.combo.findText(value)) elif self.dialogType == DIALOG_BATCH: return self.widget.setValue(value) else: