Skip to content

Commit

Permalink
[processing] Add project to QgsProcessingParameterWidgetContext
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 11, 2019
1 parent 8d77a6b commit 5ec43cf
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
Expand Up @@ -69,6 +69,23 @@ map scale and other properties from the canvas.
Returns the map canvas associated with the widget.

.. seealso:: :py:func:`setMapCanvas`
%End

void setProject( QgsProject *project );
%Docstring
Sets the ``project`` associated with the widget. This allows the widget to retrieve the map layers
and other properties from the correct project.

.. seealso:: :py:func:`project`

.. versionadded:: 3.8
%End

QgsProject *project() const;
%Docstring
Returns the project associated with the widget.

.. seealso:: :py:func:`setProject`
%End

QgsProcessingModelAlgorithm *model() const;
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/gui/BatchPanel.py
Expand Up @@ -36,6 +36,7 @@
QgsApplication,
QgsSettings,
QgsProperty,
QgsProject,
QgsProcessingFeatureSourceDefinition,
QgsCoordinateReferenceSystem,
QgsProcessingParameterDefinition,
Expand Down Expand Up @@ -269,6 +270,7 @@ def setCellWrapper(self, row, column, wrapper, context):
self.wrappers[row][column] = wrapper

widget_context = QgsProcessingParameterWidgetContext()
widget_context.setProject(QgsProject.instance())
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())
if isinstance(self.alg, QgsProcessingModelAlgorithm):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -127,6 +127,7 @@ def initWidgets(self):
break

widget_context = QgsProcessingParameterWidgetContext()
widget_context.setProject(QgsProject.instance())
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())
if isinstance(self.alg, QgsProcessingModelAlgorithm):
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/modeler/ModelerParametersDialog.py
Expand Up @@ -36,6 +36,7 @@
QHBoxLayout, QWidget)

from qgis.core import (Qgis,
QgsProject,
QgsProcessingParameterDefinition,
QgsProcessingParameterPoint,
QgsProcessingParameterExtent,
Expand Down Expand Up @@ -142,6 +143,7 @@ def setupUi(self):
self.verticalLayout.addWidget(line)

widget_context = QgsProcessingParameterWidgetContext()
widget_context.setProject(QgsProject.instance())
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())
widget_context.setModel(self.model)
Expand Down
10 changes: 10 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapper.cpp
Expand Up @@ -41,6 +41,16 @@ QgsMapCanvas *QgsProcessingParameterWidgetContext::mapCanvas() const
return mMapCanvas;
}

void QgsProcessingParameterWidgetContext::setProject( QgsProject *project )
{
mProject = project;
}

QgsProject *QgsProcessingParameterWidgetContext::project() const
{
return mProject;
}

QString QgsProcessingParameterWidgetContext::modelChildAlgorithmId() const
{
return mModelChildAlgorithmId;
Expand Down
16 changes: 16 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapper.h
Expand Up @@ -93,6 +93,20 @@ class GUI_EXPORT QgsProcessingParameterWidgetContext
*/
QgsMapCanvas *mapCanvas() const;

/**
* Sets the \a project associated with the widget. This allows the widget to retrieve the map layers
* and other properties from the correct project.
* \see project()
* \since QGIS 3.8
*/
void setProject( QgsProject *project );

/**
* Returns the project associated with the widget.
* \see setProject()
*/
QgsProject *project() const;

/**
* Returns the model which the parameter widget is associated with.
*
Expand Down Expand Up @@ -133,6 +147,8 @@ class GUI_EXPORT QgsProcessingParameterWidgetContext

QgsMapCanvas *mMapCanvas = nullptr;

QgsProject *mProject = nullptr;

};

#ifndef SIP_RUN
Expand Down
3 changes: 3 additions & 0 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -390,6 +390,9 @@ void TestProcessingGui::testWrapperGeneral()
QgsProcessingParameterWidgetContext widgetContext;
widgetContext.setMapCanvas( mc.get() );
QCOMPARE( widgetContext.mapCanvas(), mc.get() );
QgsProject p;
widgetContext.setProject( &p );
QCOMPARE( widgetContext.project(), &p );
std::unique_ptr< QgsProcessingModelAlgorithm > model = qgis::make_unique< QgsProcessingModelAlgorithm >();
widgetContext.setModel( model.get() );
QCOMPARE( widgetContext.model(), model.get() );
Expand Down

0 comments on commit 5ec43cf

Please sign in to comment.