Skip to content

Commit 9a75976

Browse files
committed
API tweaks
1 parent d3bd137 commit 9a75976

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

python/gui/auto_generated/processing/qgsprocessingwidgetwrapper.sip.in

+11
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,17 @@ current value is associated with.
291291
Returns the current value of the parameter.
292292

293293
.. seealso:: :py:func:`setWidgetValue`
294+
%End
295+
296+
virtual const QgsVectorLayer *linkedVectorLayer() const;
297+
%Docstring
298+
Returns the optional vector layer associated with this widget wrapper, or None if no vector
299+
layer is applicable.
300+
301+
This is used to correctly generate expression contexts within the GUI, e.g. to allow expression
302+
buttons and property override buttons to correctly show the appropriate vector layer fields.
303+
304+
.. versionadded:: 3.6
294305
%End
295306

296307
protected:

src/gui/processing/qgsprocessingwidgetwrapper.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ QLabel *QgsAbstractProcessingParameterWidgetWrapper::createLabel()
187187
return nullptr;
188188
}
189189

190+
const QgsVectorLayer *QgsAbstractProcessingParameterWidgetWrapper::linkedVectorLayer() const
191+
{
192+
if ( mPropertyButton )
193+
return mPropertyButton->vectorLayer();
194+
return nullptr;
195+
}
196+
190197
void QgsAbstractProcessingParameterWidgetWrapper::postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
191198
{
192199
switch ( mType )
@@ -230,8 +237,8 @@ QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressi
230237

231238
QgsExpressionContext c = context->expressionContext();
232239

233-
if ( mPropertyButton->vectorLayer() )
234-
c << QgsExpressionContextUtils::layerScope( mPropertyButton->vectorLayer() );
240+
if ( linkedVectorLayer() )
241+
c << QgsExpressionContextUtils::layerScope( linkedVectorLayer() );
235242

236243
if ( mWidgetContext.model() )
237244
{

src/gui/processing/qgsprocessingwidgetwrapper.h

+11
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@ class GUI_EXPORT QgsAbstractProcessingParameterWidgetWrapper : public QObject, p
320320
*/
321321
virtual QVariant widgetValue() const = 0;
322322

323+
/**
324+
* Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector
325+
* layer is applicable.
326+
*
327+
* This is used to correctly generate expression contexts within the GUI, e.g. to allow expression
328+
* buttons and property override buttons to correctly show the appropriate vector layer fields.
329+
*
330+
* \since QGIS 3.6
331+
*/
332+
virtual const QgsVectorLayer *linkedVectorLayer() const;
333+
323334
protected:
324335

325336
QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;

0 commit comments

Comments
 (0)