Skip to content

Commit

Permalink
Rename QgsProcessingParameterVectorLayer to QgsProcessingParameterFea…
Browse files Browse the repository at this point in the history
…tureSource

Helps abstract away sources to allow non vector layer sources in future
  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent ffce9c9 commit 770c45d
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 36 deletions.
20 changes: 10 additions & 10 deletions python/core/processing/qgsprocessingparameters.sip
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class QgsProcessingParameterDefinition
sipType = sipType_QgsProcessingParameterTable;
else if ( sipCpp->type() == "field" )
sipType = sipType_QgsProcessingParameterTableField;
else if ( sipCpp->type() == "vector" )
sipType = sipType_QgsProcessingParameterVectorLayer;
else if ( sipCpp->type() == "source" )
sipType = sipType_QgsProcessingParameterFeatureSource;
else if ( sipCpp->type() == "vectorOut" )
sipType = sipType_QgsProcessingParameterOutputVectorLayer;
%End
Expand Down Expand Up @@ -1019,10 +1019,10 @@ class QgsProcessingParameterTableField : QgsProcessingParameterDefinition

};

class QgsProcessingParameterVectorLayer : QgsProcessingParameterDefinition
class QgsProcessingParameterFeatureSource : QgsProcessingParameterDefinition
{
%Docstring
A vector layer parameter for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
.. versionadded:: 3.0
%End

Expand All @@ -1031,11 +1031,11 @@ class QgsProcessingParameterVectorLayer : QgsProcessingParameterDefinition
%End
public:

QgsProcessingParameterVectorLayer( const QString &name, const QString &description = QString(),
const QList< int > &types = QList< int >(),
const QVariant &defaultValue = QVariant(), bool optional = false );
QgsProcessingParameterFeatureSource( const QString &name, const QString &description = QString(),
const QList< int > &types = QList< int >(),
const QVariant &defaultValue = QVariant(), bool optional = false );
%Docstring
Constructor for QgsProcessingParameterVectorLayer.
Constructor for QgsProcessingParameterFeatureSource.
%End

virtual QString type() const;
Expand All @@ -1044,14 +1044,14 @@ class QgsProcessingParameterVectorLayer : QgsProcessingParameterDefinition

QList< int > dataTypes() const;
%Docstring
Returns the layer types for layers acceptable by the parameter.
Returns the geometry types for sources acceptable by the parameter.
.. seealso:: setDataTypes()
:rtype: list of int
%End

void setDataTypes( const QList< int > &types );
%Docstring
Sets the layer ``types`` for layers acceptable by the parameter.
Sets the geometry ``types`` for sources acceptable by the parameter.
.. seealso:: dataTypes()
%End

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/Boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
QgsWkbTypes,
QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterOutputVectorLayer,
QgsProcessingOutputVectorLayer)

Expand All @@ -53,7 +53,7 @@ class Boundary(QgisAlgorithm):

def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT_LAYER, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterOutputVectorLayer(self.OUTPUT_LAYER, self.tr('Boundary')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr("Boundaries")))

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/ParametersPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingParameterExtent,
QgsProcessingParameterPoint,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingOutputVectorLayer,
QgsProcessingParameterOutputVectorLayer)
from qgis.PyQt import uic
Expand Down Expand Up @@ -110,7 +110,7 @@ def initWidgets(self):
widget = wrapper.widget

if widget is not None:
if isinstance(param, QgsProcessingParameterVectorLayer):
if isinstance(param, QgsProcessingParameterFeatureSource):
layout = QHBoxLayout()
layout.setSpacing(2)
layout.setMargin(0)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
QgsProcessingParameterExpression,
QgsProcessingParameterTable,
QgsProcessingParameterTableField,
QgsProcessingParameterVectorLayer)
QgsProcessingParameterFeatureSource)

from qgis.PyQt.QtWidgets import (
QCheckBox,
Expand Down Expand Up @@ -1256,7 +1256,7 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
wrapper = TableWidgetWrapper
elif param.type() == 'field':
wrapper = TableFieldWidgetWrapper
elif param.type() == 'vector':
elif param.type() == 'source':
wrapper = VectorWidgetWrapper
else:
assert False, param.type()
Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/qgsnativealgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void QgsNativeAlgorithms::loadAlgorithms()

QgsCentroidAlgorithm::QgsCentroidAlgorithm()
{
addParameter( new QgsProcessingParameterVectorLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterOutputVectorLayer( QStringLiteral( "OUTPUT_LAYER" ), QObject::tr( "Centroids" ), QgsProcessingParameterDefinition::TypeVectorPoint ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT_LAYER" ), QObject::tr( "Centroids" ), QgsProcessingParameterDefinition::TypeVectorPoint ) );
}
Expand Down Expand Up @@ -127,7 +127,7 @@ QVariantMap QgsCentroidAlgorithm::processAlgorithm( const QVariantMap &parameter

QgsBufferAlgorithm::QgsBufferAlgorithm()
{
addParameter( new QgsProcessingParameterVectorLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "DISTANCE" ), QObject::tr( "Distance" ), QgsProcessingParameterNumber::Double, 10 ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "SEGMENTS" ), QObject::tr( "Segments" ), QgsProcessingParameterNumber::Integer, 5, false, 1 ) );

Expand Down
8 changes: 4 additions & 4 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,14 +1176,14 @@ void QgsProcessingParameterTableField::setAllowMultiple( bool allowMultiple )
mAllowMultiple = allowMultiple;
}

QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
, mDataTypes( types )
{

}

bool QgsProcessingParameterVectorLayer::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context ) const
bool QgsProcessingParameterFeatureSource::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context ) const
{
if ( !input.isValid() )
return mFlags & FlagOptional;
Expand All @@ -1209,12 +1209,12 @@ bool QgsProcessingParameterVectorLayer::checkValueIsAcceptable( const QVariant &
return false;
}

QList< int > QgsProcessingParameterVectorLayer::dataTypes() const
QList< int > QgsProcessingParameterFeatureSource::dataTypes() const
{
return mDataTypes;
}

void QgsProcessingParameterVectorLayer::setDataTypes( const QList<int> &types )
void QgsProcessingParameterFeatureSource::setDataTypes( const QList<int> &types )
{
mDataTypes = types;
}
Expand Down
24 changes: 12 additions & 12 deletions src/core/processing/qgsprocessingparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class CORE_EXPORT QgsProcessingParameterDefinition
sipType = sipType_QgsProcessingParameterTable;
else if ( sipCpp->type() == "field" )
sipType = sipType_QgsProcessingParameterTableField;
else if ( sipCpp->type() == "vector" )
sipType = sipType_QgsProcessingParameterVectorLayer;
else if ( sipCpp->type() == "source" )
sipType = sipType_QgsProcessingParameterFeatureSource;
else if ( sipCpp->type() == "vectorOut" )
sipType = sipType_QgsProcessingParameterOutputVectorLayer;
SIP_END
Expand Down Expand Up @@ -1008,33 +1008,33 @@ class CORE_EXPORT QgsProcessingParameterTableField : public QgsProcessingParamet
};

/**
* \class QgsProcessingParameterVectorLayer
* \class QgsProcessingParameterFeatureSource
* \ingroup core
* A vector layer parameter for processing algorithms.
* An input feature source (such as vector layers) parameter for processing algorithms.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameterVectorLayer : public QgsProcessingParameterDefinition
class CORE_EXPORT QgsProcessingParameterFeatureSource : public QgsProcessingParameterDefinition
{
public:

/**
* Constructor for QgsProcessingParameterVectorLayer.
* Constructor for QgsProcessingParameterFeatureSource.
*/
QgsProcessingParameterVectorLayer( const QString &name, const QString &description = QString(),
const QList< int > &types = QList< int >(),
const QVariant &defaultValue = QVariant(), bool optional = false );
QgsProcessingParameterFeatureSource( const QString &name, const QString &description = QString(),
const QList< int > &types = QList< int >(),
const QVariant &defaultValue = QVariant(), bool optional = false );

QString type() const override { return QStringLiteral( "vector" ); }
QString type() const override { return QStringLiteral( "source" ); }
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;

/**
* Returns the layer types for layers acceptable by the parameter.
* Returns the geometry types for sources acceptable by the parameter.
* \see setDataTypes()
*/
QList< int > dataTypes() const;

/**
* Sets the layer \a types for layers acceptable by the parameter.
* Sets the geometry \a types for sources acceptable by the parameter.
* \see dataTypes()
*/
void setDataTypes( const QList< int > &types );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ void TestQgsProcessing::parameterVectorLayer()
context.setProject( &p );

// not optional!
std::unique_ptr< QgsProcessingParameterVectorLayer > def( new QgsProcessingParameterVectorLayer( "non_optional", QString(), QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny, QString( "EPSG:3113" ), false ) );
std::unique_ptr< QgsProcessingParameterFeatureSource > def( new QgsProcessingParameterFeatureSource( "non_optional", QString(), QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny, QString( "EPSG:3113" ), false ) );
QVERIFY( !def->checkValueIsAcceptable( false ) );
QVERIFY( !def->checkValueIsAcceptable( true ) );
QVERIFY( !def->checkValueIsAcceptable( 5 ) );
Expand Down Expand Up @@ -2164,7 +2164,7 @@ void TestQgsProcessing::parameterVectorLayer()
QVERIFY( !QgsProcessingParameters::parameterAsVectorLayer( def.get(), params, context ) );

// optional
def.reset( new QgsProcessingParameterVectorLayer( "optional", QString(), QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny, v1->id(), true ) );
def.reset( new QgsProcessingParameterFeatureSource( "optional", QString(), QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny, v1->id(), true ) );
params.insert( "optional", QVariant() );
QCOMPARE( QgsProcessingParameters::parameterAsVectorLayer( def.get(), params, context )->id(), v1->id() );
QVERIFY( def->checkValueIsAcceptable( false ) );
Expand Down

0 comments on commit 770c45d

Please sign in to comment.