Skip to content

Commit

Permalink
Set widget context for QgsProcessingMapLayerComboBox
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 26, 2020
1 parent 6cf9bee commit 9d0efd3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Expand Up @@ -78,6 +78,13 @@ Sets the ``value`` shown in the widget.
Returns the current value of the widget.

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

void setWidgetContext( QgsProcessingParameterWidgetContext *context );
%Docstring
Sets the ``context`` in which the widget is shown.

.. versionadded:: 3.14
%End

signals:
Expand Down
5 changes: 5 additions & 0 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -1186,6 +1186,11 @@ def createWidget(self):
widget.setLayout(layout)
return widget

def setWidgetContext(self, context):
if isinstance(self.combo, QgsProcessingMapLayerComboBox):
self.combo.setWidgetContext(context)
super().setWidgetContext(context)

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
Expand Down
4 changes: 4 additions & 0 deletions src/gui/processing/qgsprocessingmaplayercombobox.cpp
Expand Up @@ -329,6 +329,10 @@ QVariant QgsProcessingMapLayerComboBox::value() const
return QVariant();
}

void QgsProcessingMapLayerComboBox::setWidgetContext( QgsProcessingParameterWidgetContext *context )
{
mBrowserModel = context->browserModel();
}

QgsMapLayer *QgsProcessingMapLayerComboBox::compatibleMapLayerFromMimeData( const QMimeData *data, bool &incompatibleLayerSelected ) const
{
Expand Down
11 changes: 11 additions & 0 deletions src/gui/processing/qgsprocessingmaplayercombobox.h
Expand Up @@ -29,6 +29,8 @@ class QgsMapLayerComboBox;
class QToolButton;
class QCheckBox;
class QgsProcessingParameterDefinition;
class QgsBrowserGuiModel;
class QgsProcessingParameterWidgetContext;

///@cond PRIVATE

Expand Down Expand Up @@ -92,6 +94,12 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
*/
QVariant value() const;

/**
* Sets the \a context in which the widget is shown.
* \since QGIS 3.14
*/
void setWidgetContext( QgsProcessingParameterWidgetContext *context );

signals:

/**
Expand Down Expand Up @@ -130,6 +138,9 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
QgsFeatureRequest::InvalidGeometryCheck mGeometryCheck = QgsFeatureRequest::GeometryAbortOnInvalid;
QPointer< QgsMapLayer> mPrevLayer;
int mBlockChangedSignal = 0;

QgsBrowserGuiModel *mBrowserModel = nullptr;

QgsMapLayer *compatibleMapLayerFromMimeData( const QMimeData *data, bool &incompatibleLayerSelected ) const;
QString compatibleUriFromMimeData( const QMimeData *data ) const;
};
Expand Down

0 comments on commit 9d0efd3

Please sign in to comment.