mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Default to current layer when appropriate
This commit is contained in:
parent
d40990e155
commit
ef4344b674
@ -160,6 +160,24 @@ Sets the child algorithm ``id`` within the model which the parameter widget is a
|
||||
.. seealso:: :py:func:`modelChildAlgorithmId`
|
||||
|
||||
.. seealso:: :py:func:`setModel`
|
||||
%End
|
||||
|
||||
QgsMapLayer *activeLayer() const;
|
||||
%Docstring
|
||||
Returns the current active layer.
|
||||
|
||||
.. seealso:: :py:func:`setActiveLayer`
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
void setActiveLayer( QgsMapLayer *layer );
|
||||
%Docstring
|
||||
Sets the current active ``layer``.
|
||||
|
||||
.. seealso:: :py:func:`activeLayer`
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
};
|
||||
|
@ -626,6 +626,7 @@ class BatchPanel(QgsPanelWidget, WIDGET):
|
||||
widget_context = QgsProcessingParameterWidgetContext()
|
||||
widget_context.setProject(QgsProject.instance())
|
||||
if iface is not None:
|
||||
widget_context.setActiveLayer(iface.activeLayer())
|
||||
widget_context.setMapCanvas(iface.mapCanvas())
|
||||
|
||||
widget_context.setMessageBar(self.parent.messageBar())
|
||||
|
@ -98,6 +98,8 @@ class ParametersPanel(QgsProcessingParametersWidget):
|
||||
if iface is not None:
|
||||
widget_context.setMapCanvas(iface.mapCanvas())
|
||||
widget_context.setBrowserModel(iface.browserModel())
|
||||
widget_context.setActiveLayer(iface.activeLayer())
|
||||
|
||||
widget_context.setMessageBar(self.parent().messageBar())
|
||||
if isinstance(self.algorithm(), QgsProcessingModelAlgorithm):
|
||||
widget_context.setModel(self.algorithm())
|
||||
|
@ -953,7 +953,7 @@ class MapLayerWidgetWrapper(WidgetWrapper):
|
||||
self.combo.setValue(self.parameterDefinition().defaultValue(), self.context)
|
||||
else:
|
||||
if self.parameterDefinition().defaultValue():
|
||||
self.combo.setvalue(self.parameterDefinition().defaultValue(), self.context)
|
||||
self.combo.setValue(self.parameterDefinition().defaultValue(), self.context)
|
||||
else:
|
||||
self.combo.setLayer(iface.activeLayer())
|
||||
except:
|
||||
|
@ -214,6 +214,7 @@ class ModelerDialog(QgsModelDesignerDialog):
|
||||
widget_context.setProject(QgsProject.instance())
|
||||
if iface is not None:
|
||||
widget_context.setMapCanvas(iface.mapCanvas())
|
||||
widget_context.setActiveLayer(iface.activeLayer())
|
||||
widget_context.setModel(self.model())
|
||||
return widget_context
|
||||
|
||||
|
@ -55,6 +55,8 @@ class ModelerInputGraphicItem(QgsModelParameterGraphicItem):
|
||||
widget_context.setProject(QgsProject.instance())
|
||||
if iface is not None:
|
||||
widget_context.setMapCanvas(iface.mapCanvas())
|
||||
widget_context.setActiveLayer(iface.activeLayer())
|
||||
|
||||
widget_context.setModel(self.model())
|
||||
return widget_context
|
||||
|
||||
|
@ -151,6 +151,8 @@ class ModelerParametersDialog(QDialog):
|
||||
widget_context.setProject(QgsProject.instance())
|
||||
if iface is not None:
|
||||
widget_context.setMapCanvas(iface.mapCanvas())
|
||||
widget_context.setActiveLayer(iface.activeLayer())
|
||||
|
||||
widget_context.setModel(self.model)
|
||||
widget_context.setModelChildAlgorithmId(self.childId)
|
||||
|
||||
|
@ -81,6 +81,16 @@ void QgsProcessingParameterWidgetContext::setModelChildAlgorithmId( const QStrin
|
||||
mModelChildAlgorithmId = modelChildAlgorithmId;
|
||||
}
|
||||
|
||||
QgsMapLayer *QgsProcessingParameterWidgetContext::activeLayer() const
|
||||
{
|
||||
return mActiveLayer;
|
||||
}
|
||||
|
||||
void QgsProcessingParameterWidgetContext::setActiveLayer( QgsMapLayer *activeLayer )
|
||||
{
|
||||
mActiveLayer = activeLayer;
|
||||
}
|
||||
|
||||
QgsProcessingModelAlgorithm *QgsProcessingParameterWidgetContext::model() const
|
||||
{
|
||||
return mModel;
|
||||
|
@ -172,6 +172,22 @@ class GUI_EXPORT QgsProcessingParameterWidgetContext
|
||||
*/
|
||||
void setModelChildAlgorithmId( const QString &id );
|
||||
|
||||
/**
|
||||
* Returns the current active layer.
|
||||
*
|
||||
* \see setActiveLayer()
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
QgsMapLayer *activeLayer() const;
|
||||
|
||||
/**
|
||||
* Sets the current active \a layer.
|
||||
*
|
||||
* \see activeLayer()
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
void setActiveLayer( QgsMapLayer *layer );
|
||||
|
||||
private:
|
||||
|
||||
QgsProcessingModelAlgorithm *mModel = nullptr;
|
||||
@ -186,6 +202,8 @@ class GUI_EXPORT QgsProcessingParameterWidgetContext
|
||||
|
||||
QgsBrowserGuiModel *mBrowserModel = nullptr;
|
||||
|
||||
QgsMapLayer *mActiveLayer = nullptr;
|
||||
|
||||
};
|
||||
|
||||
#ifndef SIP_RUN
|
||||
|
@ -4902,6 +4902,8 @@ QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
|
||||
|
||||
emit widgetValueHasChanged( this );
|
||||
} );
|
||||
|
||||
setWidgetContext( widgetContext() );
|
||||
return mComboBox;
|
||||
}
|
||||
|
||||
@ -4909,7 +4911,16 @@ void QgsProcessingMapLayerWidgetWrapper::setWidgetContext( const QgsProcessingPa
|
||||
{
|
||||
QgsAbstractProcessingParameterWidgetWrapper::setWidgetContext( context );
|
||||
if ( mComboBox )
|
||||
{
|
||||
mComboBox->setWidgetContext( context );
|
||||
|
||||
if ( !( parameterDefinition()->flags() & QgsProcessingParameterDefinition::FlagOptional ) )
|
||||
{
|
||||
// non optional parameter -- if no default value set, default to active layer
|
||||
if ( !parameterDefinition()->defaultValue().isValid() )
|
||||
mComboBox->setLayer( context.activeLayer() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsProcessingMapLayerWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
|
||||
|
Loading…
x
Reference in New Issue
Block a user