Skip to content
Permalink
Browse files

[processing] Ensure feature source wrapper always returns direct

layer id/source whenever 'use selected features' is unchecked,
instead of always returning a QgsProcessingFeatureSourceDefinition
  • Loading branch information
nyalldawson committed Jul 24, 2018
1 parent 9765019 commit 6a4d9c9bd4dc5990a3e5122e9969976a4ee9bf76
Showing with 46 additions and 2 deletions.
  1. +8 −2 python/plugins/processing/gui/wrappers.py
  2. +38 −0 python/plugins/processing/tests/GuiTest.py
@@ -1187,10 +1187,16 @@ def value(self):
try:
layer = self.combo.currentLayer()
if layer is not None:
return QgsProcessingFeatureSourceDefinition(layer.id(), use_selected_features)
if use_selected_features:
return QgsProcessingFeatureSourceDefinition(layer.id(), True)
else:
return layer.id()
else:
if self.combo.currentText():
return QgsProcessingFeatureSourceDefinition(self.combo.currentText(), use_selected_features)
if use_selected_features:
return QgsProcessingFeatureSourceDefinition(self.combo.currentText(), True)
else:
return self.combo.currentText()
else:
return None
except:
@@ -119,6 +119,44 @@ def testField(self):
def testSource(self):
self.checkConstructWrapper(QgsProcessingParameterFeatureSource('test'), FeatureSourceWidgetWrapper)

# dummy layer
layer = QgsVectorLayer('Point', 'test', 'memory')
self.assertTrue(layer.isValid())
QgsProject.instance().addMapLayer(layer)

alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
dlg = AlgorithmDialog(alg)
param = QgsProcessingParameterFeatureSource('test')
wrapper = FeatureSourceWidgetWrapper(param, dlg)
widget = wrapper.createWidget()

# check layer value
widget.show()
wrapper.setValue(layer.id())
self.assertEqual(wrapper.value(), layer.id())

# check not set
wrapper.setValue('')
self.assertFalse(wrapper.value())

# check selected only - expect a QgsProcessingFeatureSourceDefinition
wrapper.setValue(layer.id())
wrapper.use_selection_checkbox.setChecked(True)
value = wrapper.value()
self.assertIsInstance(value, QgsProcessingFeatureSourceDefinition)
self.assertTrue(value.selectedFeaturesOnly)
self.assertEqual(value.source.staticValue(), layer.id())

# NOT selected only, expect a direct layer id or source value
wrapper.use_selection_checkbox.setChecked(False)
value = wrapper.value()
self.assertEqual(value, layer.id())

# with non-project layer
wrapper.setValue('/home/my_layer.shp')
value = wrapper.value()
self.assertEqual(value, '/home/my_layer.shp')

def testMapLayer(self):
self.checkConstructWrapper(QgsProcessingParameterMapLayer('test'), MapLayerWidgetWrapper)

0 comments on commit 6a4d9c9

Please sign in to comment.
You can’t perform that action at this time.