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.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ Sets the ``value`` shown in the widget.
Returns the current value of the widget. Returns the current value of the widget.


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

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

.. versionadded:: 3.14
%End %End


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


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

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


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


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


///@cond PRIVATE ///@cond PRIVATE


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


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

signals: signals:


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

QgsBrowserGuiModel *mBrowserModel = nullptr;

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

0 comments on commit 9d0efd3

Please sign in to comment.