Skip to content
Permalink
Browse files

[processing] Wrappers built off old API can still take advantage of t…

…he full widget context
  • Loading branch information
nyalldawson committed Feb 19, 2019
1 parent f620adc commit 521ebdc9737997e374c1ac2509de97c0bddbd303
@@ -265,21 +265,21 @@ def save(self):
def setCellWrapper(self, row, column, wrapper, context):
self.wrappers[row][column] = wrapper

widget_context = QgsProcessingParameterWidgetContext()
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())
if isinstance(self.alg, QgsProcessingModelAlgorithm):
widget_context.setModel(self.alg)
wrapper.setWidgetContext(widget_context)
wrapper.registerProcessingContextGenerator(self.context_generator)

# For compatibility with 3.x API, we need to check whether the wrapper is
# the deprecated WidgetWrapper class. If not, it's the newer
# QgsAbstractProcessingParameterWidgetWrapper class
# TODO QGIS 4.0 - remove
is_cpp_wrapper = not issubclass(wrapper.__class__, WidgetWrapper)
if is_cpp_wrapper:
widget_context = QgsProcessingParameterWidgetContext()
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())
if isinstance(self.alg, QgsProcessingModelAlgorithm):
widget_context.setModel(self.alg)

wrapper.setWidgetContext(widget_context)
widget = wrapper.createWrappedWidget(context)
wrapper.registerProcessingContextGenerator(self.context_generator)
else:
widget = wrapper.widget

@@ -141,6 +141,8 @@ def initWidgets(self):
continue
else:
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent)
wrapper.setWidgetContext(widget_context)
wrapper.registerProcessingContextGenerator(self.context_generator)
self.wrappers[param.name()] = wrapper

# For compatibility with 3.x API, we need to check whether the wrapper is
@@ -149,9 +151,7 @@ def initWidgets(self):
# TODO QGIS 4.0 - remove
is_python_wrapper = issubclass(wrapper.__class__, WidgetWrapper)
if not is_python_wrapper:
wrapper.setWidgetContext(widget_context)
widget = wrapper.createWrappedWidget(self.processing_context)
wrapper.registerProcessingContextGenerator(self.context_generator)
else:
widget = wrapper.widget

@@ -173,9 +173,9 @@ def setupUi(self):
wrapper = WidgetWrapperFactory.create_wrapper(param, self)
self.wrappers[param.name()] = wrapper

wrapper.setWidgetContext(widget_context)
wrapper.registerProcessingContextGenerator(self.context_generator)
if issubclass(wrapper.__class__, QgsProcessingModelerParameterWidget):
wrapper.setWidgetContext(widget_context)
wrapper.registerProcessingContextGenerator(self.context_generator)
widget = wrapper
else:
widget = wrapper.widget

0 comments on commit 521ebdc

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