Skip to content
Permalink
Browse files

API tweaks

  • Loading branch information
nyalldawson committed Feb 11, 2019
1 parent d3bd137 commit 9a75976ca45c5a2aea9b017bded2ea481f072094
@@ -291,6 +291,17 @@ current value is associated with.
Returns the current value of the parameter.

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

virtual const QgsVectorLayer *linkedVectorLayer() const;
%Docstring
Returns the optional vector layer associated with this widget wrapper, or None if no vector
layer is applicable.

This is used to correctly generate expression contexts within the GUI, e.g. to allow expression
buttons and property override buttons to correctly show the appropriate vector layer fields.

.. versionadded:: 3.6
%End

protected:
@@ -187,6 +187,13 @@ QLabel *QgsAbstractProcessingParameterWidgetWrapper::createLabel()
return nullptr;
}

const QgsVectorLayer *QgsAbstractProcessingParameterWidgetWrapper::linkedVectorLayer() const
{
if ( mPropertyButton )
return mPropertyButton->vectorLayer();
return nullptr;
}

void QgsAbstractProcessingParameterWidgetWrapper::postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
{
switch ( mType )
@@ -230,8 +237,8 @@ QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressi

QgsExpressionContext c = context->expressionContext();

if ( mPropertyButton->vectorLayer() )
c << QgsExpressionContextUtils::layerScope( mPropertyButton->vectorLayer() );
if ( linkedVectorLayer() )
c << QgsExpressionContextUtils::layerScope( linkedVectorLayer() );

if ( mWidgetContext.model() )
{
@@ -320,6 +320,17 @@ class GUI_EXPORT QgsAbstractProcessingParameterWidgetWrapper : public QObject, p
*/
virtual QVariant widgetValue() const = 0;

/**
* Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector
* layer is applicable.
*
* This is used to correctly generate expression contexts within the GUI, e.g. to allow expression
* buttons and property override buttons to correctly show the appropriate vector layer fields.
*
* \since QGIS 3.6
*/
virtual const QgsVectorLayer *linkedVectorLayer() const;

protected:

QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;

0 comments on commit 9a75976

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