Skip to content

Commit

Permalink
API tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 11, 2019
1 parent d3bd137 commit 9a75976
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Expand Up @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions src/gui/processing/qgsprocessingwidgetwrapper.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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() )
{
Expand Down
11 changes: 11 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapper.h
Expand Up @@ -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;
Expand Down

0 comments on commit 9a75976

Please sign in to comment.