Skip to content
Permalink
Browse files

API tweaks

(cherry picked from commit 9a75976)
  • Loading branch information
nyalldawson committed Feb 12, 2019
1 parent 72d6cbf commit fa1b5105d0d8afed9eb8f8fb6d4208bedb6fb1a9
@@ -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 fa1b510

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