Skip to content

Commit c65afbd

Browse files
committedJul 18, 2018
[processing] Correctly handle layer type parameter values when
creating an algorithm dialog using processing.execAlgorithmDialog()
1 parent 7973408 commit c65afbd

File tree

1 file changed

+54
-21
lines changed

1 file changed

+54
-21
lines changed
 

‎python/plugins/processing/gui/wrappers.py

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -908,13 +908,24 @@ def setValue(self, value):
908908
return
909909

910910
if self.dialogType == DIALOG_STANDARD:
911-
if self.combo.findText(value) >= 0:
912-
self.combo.setCurrentIndex(self.combo.findText(value))
913-
else:
914-
items = self.combo.additionalItems()
915-
items.append(value)
916-
self.combo.setAdditionalItems(items)
917-
self.combo.setCurrentIndex(self.combo.findText(value))
911+
if isinstance(value, str):
912+
layer = QgsProject.instance().mapLayer(value)
913+
if layer is not None:
914+
value = layer
915+
916+
found = False
917+
if isinstance(value, QgsMapLayer):
918+
self.combo.setLayer(value)
919+
found = self.combo.currentIndex() != -1
920+
921+
if not found:
922+
if self.combo.findText(value) >= 0:
923+
self.combo.setCurrentIndex(self.combo.findText(value))
924+
else:
925+
items = self.combo.additionalItems()
926+
items.append(value)
927+
self.combo.setAdditionalItems(items)
928+
self.combo.setCurrentIndex(self.combo.findText(value))
918929
elif self.dialogType == DIALOG_BATCH:
919930
self.widget.setValue(value)
920931
else:
@@ -1146,13 +1157,24 @@ def setValue(self, value):
11461157
return
11471158

11481159
if self.dialogType == DIALOG_STANDARD:
1149-
if self.combo.findText(value) >= 0:
1150-
self.combo.setCurrentIndex(self.combo.findText(value))
1151-
else:
1152-
items = self.combo.additionalItems()
1153-
items.append(value)
1154-
self.combo.setAdditionalItems(items)
1155-
self.combo.setCurrentIndex(self.combo.findText(value))
1160+
if isinstance(value, str):
1161+
layer = QgsProject.instance().mapLayer(value)
1162+
if layer is not None:
1163+
value = layer
1164+
1165+
found = False
1166+
if isinstance(value, QgsMapLayer):
1167+
self.combo.setLayer(value)
1168+
found = self.combo.currentIndex() != -1
1169+
1170+
if not found:
1171+
if self.combo.findText(value) >= 0:
1172+
self.combo.setCurrentIndex(self.combo.findText(value))
1173+
else:
1174+
items = self.combo.additionalItems()
1175+
items.append(value)
1176+
self.combo.setAdditionalItems(items)
1177+
self.combo.setCurrentIndex(self.combo.findText(value))
11561178
elif self.dialogType == DIALOG_BATCH:
11571179
self.widget.setValue(value)
11581180
else:
@@ -1448,13 +1470,24 @@ def setValue(self, value):
14481470
return
14491471

14501472
if self.dialogType == DIALOG_STANDARD:
1451-
if self.combo.findText(value) >= 0:
1452-
self.combo.setCurrentIndex(self.combo.findText(value))
1453-
else:
1454-
items = self.combo.additionalItems()
1455-
items.append(value)
1456-
self.combo.setAdditionalItems(items)
1457-
self.combo.setCurrentIndex(self.combo.findText(value))
1473+
if isinstance(value, str):
1474+
layer = QgsProject.instance().mapLayer(value)
1475+
if layer is not None:
1476+
value = layer
1477+
1478+
found = False
1479+
if isinstance(value, QgsMapLayer):
1480+
self.combo.setLayer(value)
1481+
found = self.combo.currentIndex() != -1
1482+
1483+
if not found:
1484+
if self.combo.findText(value) >= 0:
1485+
self.combo.setCurrentIndex(self.combo.findText(value))
1486+
else:
1487+
items = self.combo.additionalItems()
1488+
items.append(value)
1489+
self.combo.setAdditionalItems(items)
1490+
self.combo.setCurrentIndex(self.combo.findText(value))
14581491
elif self.dialogType == DIALOG_BATCH:
14591492
return self.widget.setValue(value)
14601493
else:

0 commit comments

Comments
 (0)
Please sign in to comment.