Skip to content
Permalink
Browse files

Rename QgsProcessingParameterVectorLayer to QgsProcessingParameterFea…

…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 770c45da1269728ebf36982bf35e0c95e8b45238
@@ -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
@@ -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

@@ -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;
@@ -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

@@ -31,7 +31,7 @@
QgsWkbTypes,
QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterOutputVectorLayer,
QgsProcessingOutputVectorLayer)

@@ -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")))

@@ -34,7 +34,7 @@
from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingParameterExtent,
QgsProcessingParameterPoint,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingOutputVectorLayer,
QgsProcessingParameterOutputVectorLayer)
from qgis.PyQt import uic
@@ -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)
@@ -59,7 +59,7 @@
QgsProcessingParameterExpression,
QgsProcessingParameterTable,
QgsProcessingParameterTableField,
QgsProcessingParameterVectorLayer)
QgsProcessingParameterFeatureSource)

from qgis.PyQt.QtWidgets import (
QCheckBox,
@@ -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()
@@ -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 ) );
}
@@ -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 ) );

@@ -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;
@@ -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;
}
@@ -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
@@ -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 );
@@ -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 ) );
@@ -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 ) );

0 comments on commit 770c45d

Please sign in to comment.
You can’t perform that action at this time.