Skip to content

Commit

Permalink
[feature][processing] Port Feature Source, Raster, Vector and Mesh La…
Browse files Browse the repository at this point in the history
…yer parameters to new API
  • Loading branch information
nyalldawson committed Mar 28, 2020
1 parent d070427 commit d40990e
Show file tree
Hide file tree
Showing 11 changed files with 960 additions and 219 deletions.
Expand Up @@ -10,7 +10,6 @@




class QgsProcessingMapLayerComboBox : QWidget
{
%Docstring
Expand All @@ -28,7 +27,7 @@ Processing map layer combo box.
%End
public:

QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QWidget *parent = 0 );
QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QWidget *parent = 0 );
%Docstring
Constructor for QgsProcessingMapLayerComboBox, with the specified ``parameter`` definition.
%End
Expand Down Expand Up @@ -80,7 +79,7 @@ Returns the current value of the widget.
.. seealso:: :py:func:`setValue`
%End

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

Expand Down Expand Up @@ -110,12 +109,6 @@ Returns whether the combo box value can be freely edited.
void valueChanged();
%Docstring
Emitted whenever the value is changed in the widget.
%End

void triggerFileSelection();
%Docstring
Emitted when the widget has triggered a file selection operation (to be
handled in Python for now).
%End

protected:
Expand Down
Expand Up @@ -495,10 +495,10 @@ values which can be used as values for the parameter.
.. seealso:: :py:func:`compatibleDataTypes`
%End

virtual QList< int > compatibleDataTypes() const = 0;
virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
%Docstring
Returns a list of compatible Processing data types for inputs
for this parameter.
for this widget for the specified ``parameter``.

In order to determine the available sources for the parameter in a model
the types returned by this method are checked. The returned list corresponds
Expand Down
58 changes: 57 additions & 1 deletion python/plugins/processing/gui/wrappers.py
Expand Up @@ -408,7 +408,7 @@ class ExtentWidgetWrapper(WidgetWrapper):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
"""
.. deprecated:: 3.4
.. deprecated:: 3.14
Do not use, will be removed in QGIS 4.0
"""

Expand Down Expand Up @@ -932,6 +932,17 @@ def value(self):
class MapLayerWidgetWrapper(WidgetWrapper):
NOT_SELECTED = '[Not selected]'

def __init__(self, param, dialog, row=0, col=0, **kwargs):
"""
.. deprecated:: 3.14
Do not use, will be removed in QGIS 4.0
"""

from warnings import warn
warn("MapLayerWidgetWrapper is deprecated and will be removed in QGIS 4.0", DeprecationWarning)

super().__init__(param, dialog, row, col, **kwargs)

def createWidget(self):
if self.dialogType == DIALOG_STANDARD:
self.combo = QgsProcessingMapLayerComboBox(self.parameterDefinition())
Expand Down Expand Up @@ -1030,6 +1041,17 @@ def validator(v):

class RasterWidgetWrapper(MapLayerWidgetWrapper):

def __init__(self, param, dialog, row=0, col=0, **kwargs):
"""
.. deprecated:: 3.14
Do not use, will be removed in QGIS 4.0
"""

from warnings import warn
warn("RasterWidgetWrapper is deprecated and will be removed in QGIS 4.0", DeprecationWarning)

super().__init__(param, dialog, row, col, **kwargs)

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType((QgsProcessingParameterRasterLayer, QgsProcessingParameterString),
(QgsProcessingOutputRasterLayer, QgsProcessingOutputFile, QgsProcessingOutputString))
Expand All @@ -1052,6 +1074,17 @@ def selectFile(self):

class MeshWidgetWrapper(MapLayerWidgetWrapper):

def __init__(self, param, dialog, row=0, col=0, **kwargs):
"""
.. deprecated:: 3.14
Do not use, will be removed in QGIS 4.0
"""

from warnings import warn
warn("MeshWidgetWrapper is deprecated and will be removed in QGIS 4.0", DeprecationWarning)

super().__init__(param, dialog, row, col, **kwargs)

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType((QgsProcessingParameterMeshLayer, QgsProcessingParameterString),
())
Expand Down Expand Up @@ -1142,6 +1175,13 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
NOT_SELECTED = '[Not selected]'

def __init__(self, *args, **kwargs):
"""
.. deprecated:: 3.4
Do not use, will be removed in QGIS 4.0
"""

from warnings import warn
warn("FeatureSourceWidgetWrapper is deprecated and will be removed in QGIS 4.0", DeprecationWarning)
self.map_layer_combo = None
super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -1424,6 +1464,17 @@ def validator(v):
class VectorLayerWidgetWrapper(WidgetWrapper):
NOT_SELECTED = '[Not selected]'

def __init__(self, param, dialog, row=0, col=0, **kwargs):
"""
.. deprecated:: 3.14
Do not use, will be removed in QGIS 4.0
"""

from warnings import warn
warn("VectorLayerWidgetWrapper is deprecated and will be removed in QGIS 4.0", DeprecationWarning)

super().__init__(param, dialog, row, col, **kwargs)

def createWidget(self):
if self.dialogType == DIALOG_STANDARD:
self.combo = QgsProcessingMapLayerComboBox(self.parameterDefinition())
Expand Down Expand Up @@ -1853,6 +1904,7 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
# deprecated, moved to c++
wrapper = DistanceWidgetWrapper
elif param.type() == 'raster':
# deprecated, moved to c++
wrapper = RasterWidgetWrapper
elif param.type() == 'enum':
# deprecated, moved to c++
Expand All @@ -1864,15 +1916,18 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
# deprecated, moved to c++
wrapper = ExpressionWidgetWrapper
elif param.type() == 'vector':
# deprecated, moved to c++
wrapper = VectorLayerWidgetWrapper
elif param.type() == 'field':
# deprecated, moved to c++
wrapper = TableFieldWidgetWrapper
elif param.type() == 'source':
# deprecated, moved to c++
wrapper = FeatureSourceWidgetWrapper
elif param.type() == 'band':
wrapper = BandWidgetWrapper
elif param.type() == 'layer':
# deprecated, moved to c++
wrapper = MapLayerWidgetWrapper
elif param.type() == 'range':
# deprecated, moved to c++
Expand All @@ -1881,6 +1936,7 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
# deprecated, moved to c++
wrapper = FixedTableWidgetWrapper
elif param.type() == 'mesh':
# deprecated, moved to c++
wrapper = MeshWidgetWrapper
else:
assert False, param.type()
Expand Down
4 changes: 4 additions & 0 deletions src/gui/processing/qgsprocessingguiregistry.cpp
Expand Up @@ -52,6 +52,10 @@ QgsProcessingGuiRegistry::QgsProcessingGuiRegistry()
addParameterWidgetFactory( new QgsProcessingDatabaseTableWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingExtentWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingMapLayerWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingVectorLayerWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingFeatureSourceWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingRasterLayerWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingMeshLayerWidgetWrapper() );
}

QgsProcessingGuiRegistry::~QgsProcessingGuiRegistry()
Expand Down
17 changes: 8 additions & 9 deletions src/gui/processing/qgsprocessingmaplayercombobox.cpp
Expand Up @@ -37,7 +37,7 @@

///@cond PRIVATE

QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QWidget *parent )
QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
: QWidget( parent )
, mParameter( parameter->clone() )
{
Expand All @@ -55,7 +55,7 @@ QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( const QgsProcessin
mSelectButton->setToolTip( tr( "Select input" ) );
layout->addWidget( mSelectButton );
layout->setAlignment( mSelectButton, Qt::AlignTop );
if ( mParameter->type() == QgsProcessingParameterFeatureSource::typeName() )
if ( mParameter->type() == QgsProcessingParameterFeatureSource::typeName() && type == QgsProcessingGui::Standard )
{
mIterateButton = new QToolButton();
mIterateButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mIconIterate.svg" ) ) );
Expand Down Expand Up @@ -98,8 +98,7 @@ QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( const QgsProcessin
}
else
{
// file selection not handled here, needs handling in Python at the moment...
connect( mSelectButton, &QToolButton::clicked, this, &QgsProcessingMapLayerComboBox::triggerFileSelection );
connect( mSelectButton, &QToolButton::clicked, this, &QgsProcessingMapLayerComboBox::selectFromFile );
}

QVBoxLayout *vl = new QVBoxLayout();
Expand All @@ -110,7 +109,7 @@ QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( const QgsProcessin

QgsMapLayerProxyModel::Filters filters = nullptr;

if ( mParameter->type() == QgsProcessingParameterFeatureSource::typeName() )
if ( mParameter->type() == QgsProcessingParameterFeatureSource::typeName() && type == QgsProcessingGui::Standard )
{
mUseSelectionCheckBox = new QCheckBox( tr( "Selected features only" ) );
mUseSelectionCheckBox->setChecked( false );
Expand Down Expand Up @@ -357,9 +356,9 @@ QVariant QgsProcessingMapLayerComboBox::value() const
return QVariant();
}

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

void QgsProcessingMapLayerComboBox::setEditable( bool editable )
Expand Down Expand Up @@ -571,7 +570,7 @@ void QgsProcessingMapLayerComboBox::dropEvent( QDropEvent *event )

void QgsProcessingMapLayerComboBox::onLayerChanged( QgsMapLayer *layer )
{
if ( mParameter->type() == QgsProcessingParameterFeatureSource::typeName() )
if ( mUseSelectionCheckBox && mParameter->type() == QgsProcessingParameterFeatureSource::typeName() )
{
if ( QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( layer ) )
{
Expand Down Expand Up @@ -635,7 +634,7 @@ void QgsProcessingMapLayerComboBox::selectFromFile()

if ( QFileInfo( initialValue ).isDir() && QFileInfo::exists( initialValue ) )
path = initialValue;
else if ( QFileInfo::exists( QFileInfo( initialValue ).path() ) )
else if ( QFileInfo::exists( QFileInfo( initialValue ).path() ) && QFileInfo( initialValue ).path() != '.' )
path = QFileInfo( initialValue ).path();
else if ( settings.contains( QStringLiteral( "/Processing/LastInputPath" ) ) )
path = settings.value( QStringLiteral( "/Processing/LastInputPath" ) ).toString();
Expand Down
12 changes: 3 additions & 9 deletions src/gui/processing/qgsprocessingmaplayercombobox.h
Expand Up @@ -23,7 +23,7 @@
#include "qgsfeatureid.h"
#include "qgsmimedatautils.h"
#include "qgsprocessingcontext.h"

#include "qgsprocessinggui.h"

class QgsMapLayerComboBox;
class QToolButton;
Expand All @@ -49,7 +49,7 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
/**
* Constructor for QgsProcessingMapLayerComboBox, with the specified \a parameter definition.
*/
QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QWidget *parent = nullptr );
QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QWidget *parent = nullptr );

~QgsProcessingMapLayerComboBox() override;

Expand Down Expand Up @@ -98,7 +98,7 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
* Sets the \a context in which the widget is shown.
* \since QGIS 3.14
*/
void setWidgetContext( QgsProcessingParameterWidgetContext *context );
void setWidgetContext( const QgsProcessingParameterWidgetContext &context );

/**
* Sets whether the combo box value can be freely edited.
Expand All @@ -123,12 +123,6 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
*/
void valueChanged();

/**
* Emitted when the widget has triggered a file selection operation (to be
* handled in Python for now).
*/
void triggerFileSelection();

protected:

void dragEnterEvent( QDragEnterEvent *event ) override;
Expand Down
7 changes: 6 additions & 1 deletion src/gui/processing/qgsprocessingwidgetwrapper.cpp
Expand Up @@ -330,7 +330,7 @@ void QgsAbstractProcessingParameterWidgetWrapper::setDynamicParentLayerParameter
QgsProcessingModelerParameterWidget *QgsProcessingParameterWidgetFactoryInterface::createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context )
{
std::unique_ptr< QgsProcessingModelerParameterWidget > widget = qgis::make_unique< QgsProcessingModelerParameterWidget >( model, childId, parameter, context );
widget->populateSources( compatibleParameterTypes(), compatibleOutputTypes(), compatibleDataTypes() );
widget->populateSources( compatibleParameterTypes(), compatibleOutputTypes(), compatibleDataTypes( parameter ) );
widget->setExpressionHelpText( modelerExpressionFormatString() );
return widget.release();
}
Expand All @@ -342,6 +342,11 @@ QgsProcessingAbstractParameterDefinitionWidget *QgsProcessingParameterWidgetFact
return nullptr;
}

QList<int> QgsProcessingParameterWidgetFactoryInterface::compatibleDataTypes( const QgsProcessingParameterDefinition * ) const
{
return QList< int >();
}

QString QgsProcessingParameterWidgetFactoryInterface::modelerExpressionFormatString() const
{
return QString();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/processing/qgsprocessingwidgetwrapper.h
Expand Up @@ -555,7 +555,7 @@ class GUI_EXPORT QgsProcessingParameterWidgetFactoryInterface

/**
* Returns a list of compatible Processing data types for inputs
* for this parameter.
* for this widget for the specified \a parameter.
*
* In order to determine the available sources for the parameter in a model
* the types returned by this method are checked. The returned list corresponds
Expand All @@ -567,7 +567,7 @@ class GUI_EXPORT QgsProcessingParameterWidgetFactoryInterface
* \see compatibleParameterTypes()
* \see compatibleOutputTypes()
*/
virtual QList< int > compatibleDataTypes() const = 0;
virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;

/**
* Returns the expected expression format string for expression results for the parameter
Expand Down

0 comments on commit d40990e

Please sign in to comment.