Skip to content
Permalink
Browse files

[processing] Add project to QgsProcessingParameterWidgetContext

  • Loading branch information
nyalldawson committed Mar 11, 2019
1 parent 8d77a6b commit 5ec43cfdc1a9f3700f1a01b078b1d0f613320d28
@@ -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;
@@ -36,6 +36,7 @@
QgsApplication,
QgsSettings,
QgsProperty,
QgsProject,
QgsProcessingFeatureSourceDefinition,
QgsCoordinateReferenceSystem,
QgsProcessingParameterDefinition,
@@ -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):
@@ -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):
@@ -36,6 +36,7 @@
QHBoxLayout, QWidget)

from qgis.core import (Qgis,
QgsProject,
QgsProcessingParameterDefinition,
QgsProcessingParameterPoint,
QgsProcessingParameterExtent,
@@ -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)
@@ -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;
@@ -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.
*
@@ -133,6 +147,8 @@ class GUI_EXPORT QgsProcessingParameterWidgetContext

QgsMapCanvas *mMapCanvas = nullptr;

QgsProject *mProject = nullptr;

};

#ifndef SIP_RUN
@@ -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() );

0 comments on commit 5ec43cf

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