Skip to content

Commit

Permalink
[processing] Wrappers built off old API can still take advantage of t…
Browse files Browse the repository at this point in the history
…he full widget context
  • Loading branch information
nyalldawson committed Feb 19, 2019
1 parent f620adc commit 521ebdc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions python/plugins/processing/gui/BatchPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/ParametersPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/ModelerParametersDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 521ebdc

Please sign in to comment.