Skip to content
Permalink
Browse files

Rename some parameter classes for consistency

  • Loading branch information
nyalldawson committed Jun 21, 2017
1 parent aa96e78 commit 0da3652257541837550ab8245b91c5734d7ff59a
@@ -163,10 +163,10 @@ class QgsProcessingParameterDefinition
sipType = sipType_QgsProcessingParameterString;
else if ( sipCpp->type() == "expression" )
sipType = sipType_QgsProcessingParameterExpression;
else if ( sipCpp->type() == "table" )
sipType = sipType_QgsProcessingParameterTable;
else if ( sipCpp->type() == "vector" )
sipType = sipType_QgsProcessingParameterVectorLayer;
else if ( sipCpp->type() == "field" )
sipType = sipType_QgsProcessingParameterTableField;
sipType = sipType_QgsProcessingParameterField;
else if ( sipCpp->type() == "source" )
sipType = sipType_QgsProcessingParameterFeatureSource;
else if ( sipCpp->type() == "sink" )
@@ -1153,10 +1153,11 @@ class QgsProcessingParameterExpression : QgsProcessingParameterDefinition

};

class QgsProcessingParameterTable : QgsProcessingParameterDefinition
class QgsProcessingParameterVectorLayer : QgsProcessingParameterDefinition
{
%Docstring
A table (i.e. vector layers with or without geometry) parameter for processing algorithms.
A vector layer (with or without geometry) parameter for processing algorithms. Consider using
the more versatile QgsProcessingParameterFeatureSource wherever possible.
.. versionadded:: 3.0
%End

@@ -1165,20 +1166,20 @@ class QgsProcessingParameterTable : QgsProcessingParameterDefinition
%End
public:

QgsProcessingParameterTable( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterVectorLayer( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterTable.
Constructor for QgsProcessingParameterVectorLayer.
%End

virtual QString type() const;

};

class QgsProcessingParameterTableField : QgsProcessingParameterDefinition
class QgsProcessingParameterField : QgsProcessingParameterDefinition
{
%Docstring
A table field parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
.. versionadded:: 3.0
%End

@@ -1195,13 +1196,13 @@ class QgsProcessingParameterTableField : QgsProcessingParameterDefinition
DateTime
};

QgsProcessingParameterTableField( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
const QString &parentLayerParameterName = QString(),
DataType type = Any,
bool allowMultiple = false,
bool optional = false );
QgsProcessingParameterField( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
const QString &parentLayerParameterName = QString(),
DataType type = Any,
bool allowMultiple = false,
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterTableField.
Constructor for QgsProcessingParameterField.
%End

virtual QString type() const;
@@ -32,7 +32,7 @@
from qgis.core import (QgsApplication,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterTableField,
QgsProcessingParameterField,
QgsProcessingParameterFileOutput,
QgsProcessingOutputHtml)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@@ -60,12 +60,12 @@ def __init__(self):

self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer')))
self.addParameter(QgsProcessingParameterTableField(self.NAME_FIELD,
self.tr('Category name field'),
None, self.INPUT, QgsProcessingParameterTableField.Any))
self.addParameter(QgsProcessingParameterTableField(self.VALUE_FIELD,
self.tr('Value field'),
None, self.INPUT, QgsProcessingParameterTableField.Numeric))
self.addParameter(QgsProcessingParameterField(self.NAME_FIELD,
self.tr('Category name field'),
None, self.INPUT, QgsProcessingParameterField.Any))
self.addParameter(QgsProcessingParameterField(self.VALUE_FIELD,
self.tr('Value field'),
None, self.INPUT, QgsProcessingParameterField.Numeric))

self.addParameter(QgsProcessingParameterFileOutput(self.OUTPUT, self.tr('Added'), self.tr('HTML files (*.html)')))

@@ -37,7 +37,7 @@
QgsFeatureRequest,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterTableField,
QgsProcessingParameterField,
QgsProcessingParameterFileOutput,
QgsProcessingOutputHtml,
QgsProcessingOutputNumber)
@@ -90,9 +90,9 @@ def __init__(self):
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER,
self.tr('Input layer')))

self.addParameter(QgsProcessingParameterTableField(self.FIELD_NAME,
self.tr('Field to calculate statistics on'),
None, self.INPUT_LAYER, QgsProcessingParameterTableField.Any))
self.addParameter(QgsProcessingParameterField(self.FIELD_NAME,
self.tr('Field to calculate statistics on'),
None, self.INPUT_LAYER, QgsProcessingParameterField.Any))

self.addParameter(QgsProcessingParameterFileOutput(self.OUTPUT_HTML_FILE, self.tr('Statistics'), self.tr('HTML files (*.html)'), None, True))
self.addOutput(QgsProcessingOutputHtml(self.OUTPUT_HTML_FILE, self.tr('Statistics')))
@@ -29,7 +29,7 @@
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterTableField,
QgsProcessingParameterField,
QgsProcessingOutputVectorLayer)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

@@ -56,9 +56,9 @@ def __init__(self):
super().__init__()

self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer')))
self.addParameter(QgsProcessingParameterTableField(self.COLUMNS,
self.tr('Fields to delete'),
None, self.INPUT, QgsProcessingParameterTableField.Any, True))
self.addParameter(QgsProcessingParameterField(self.COLUMNS,
self.tr('Fields to delete'),
None, self.INPUT, QgsProcessingParameterField.Any, True))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Output layer')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Output layer")))
@@ -40,7 +40,7 @@
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterDefinition,
QgsProcessingParameterTable,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSource)

from processing.gui.MultipleInputDialog import MultipleInputDialog
@@ -105,7 +105,7 @@ def showLayerSelectionDialog(self):
(isinstance(self.param, QgsProcessingParameterMultipleLayers) and
self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster)):
layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance())
elif isinstance(self.param, QgsProcessingParameterTable):
elif isinstance(self.param, QgsProcessingParameterVectorLayer):
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
else:
datatypes = [QgsProcessingParameterDefinition.TypeVectorAny]
@@ -36,7 +36,7 @@
QgsProcessingParameterFolderOutput,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterTable,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterBoolean,
QgsProcessingParameterEnum,
@@ -114,7 +114,7 @@ def showSelectionDialog(self):
param = self.alg.parameterDefinitions()[dlg.param_index]
if isinstance(param, (QgsProcessingParameterRasterLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterTable,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMultipleLayers)):
v = widget.value()
if isinstance(v, QgsMapLayer):
@@ -58,8 +58,8 @@
QgsProcessingParameterEnum,
QgsProcessingParameterString,
QgsProcessingParameterExpression,
QgsProcessingParameterTable,
QgsProcessingParameterTableField,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource,
QgsProcessingFeatureSourceDefinition,
QgsProcessingOutputRasterLayer,
@@ -531,7 +531,7 @@ def _getOptions(self):
elif self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)
elif self.param.layerType() == QgsProcessingParameterDefinition.TypeTable:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterTable, OutputTable)
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterVectorLayer, OutputTable)
else:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, OutputFile)
options = sorted(options, key=lambda opt: self.dialog.resolveValueDescription(opt))
@@ -907,7 +907,7 @@ def createWidget(self):
else:
# strings, numbers, files and table fields are all allowed input types
strings = self.dialog.getAvailableValuesOfType([QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterFile,
QgsProcessingParameterTableField, QgsProcessingParameterExpression], QgsProcessingOutputString)
QgsProcessingParameterField, QgsProcessingParameterExpression], QgsProcessingOutputString)
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
if self.param.multiLine():
widget = MultilineTextPanel(options)
@@ -1079,7 +1079,7 @@ def createWidget(self):
self.combo = QComboBox()
layers = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)
self.combo.setEditable(True)
tables = self.dialog.getAvailableValuesOfType(QgsProcessingParameterTable, OutputTable)
tables = self.dialog.getAvailableValuesOfType(QgsProcessingParameterVectorLayer, OutputTable)
layers = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer)
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.addItem(self.NOT_SELECTED, None)
@@ -1154,17 +1154,17 @@ def createWidget(self):
widget = QgsFieldComboBox()
widget.setAllowEmptyFieldName(self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
widget.fieldChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
if self.param.dataType() == QgsProcessingParameterTableField.Numeric:
if self.param.dataType() == QgsProcessingParameterField.Numeric:
widget.setFilters(QgsFieldProxyModel.Numeric)
elif self.param.dataType() == QgsProcessingParameterTableField.String:
elif self.param.dataType() == QgsProcessingParameterField.String:
widget.setFilters(QgsFieldProxyModel.String)
elif self.param.dataType() == QgsProcessingParameterTableField.DateTime:
elif self.param.dataType() == QgsProcessingParameterField.DateTime:
widget.setFilters(QgsFieldProxyModel.Date | QgsFieldProxyModel.Time)
return widget
else:
widget = QComboBox()
widget.setEditable(True)
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterTableField, QgsProcessingParameterString], [QgsProcessingOutputString])
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterField, QgsProcessingParameterString], [QgsProcessingOutputString])
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
widget.addItem(self.NOT_SET, None)
for f in fields:
@@ -1202,12 +1202,12 @@ def getFields(self):
if self._layer is None:
return []
fieldTypes = []
if self.param.dataType() == QgsProcessingParameterTableField.String:
if self.param.dataType() == QgsProcessingParameterField.String:
fieldTypes = [QVariant.String]
elif self.param.dataType() == QgsProcessingParameterTableField.Numeric:
elif self.param.dataType() == QgsProcessingParameterField.Numeric:
fieldTypes = [QVariant.Int, QVariant.Double, QVariant.LongLong,
QVariant.UInt, QVariant.ULongLong]
elif self.param.dataType() == QgsProcessingParameterTableField.DateTime:
elif self.param.dataType() == QgsProcessingParameterField.DateTime:
fieldTypes = [QVariant.Date, QVariant.Time, QVariant.DateTime]

fieldNames = set()
@@ -52,8 +52,8 @@
QgsProcessingParameterEnum,
QgsProcessingParameterString,
QgsProcessingParameterExpression,
QgsProcessingParameterTable,
QgsProcessingParameterTableField,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource,
QgsProcessingModelAlgorithm)
from qgis.gui import QgsMessageBar
@@ -45,8 +45,8 @@
QgsProcessingParameterEnum,
QgsProcessingParameterString,
QgsProcessingParameterExpression,
QgsProcessingParameterTable,
QgsProcessingParameterTableField,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource)
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import (QDialog,
@@ -123,13 +123,13 @@ def setupUi(self):
self.state.setChecked(bool(self.param.defaultValue()))
self.verticalLayout.addWidget(self.state)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD or \
isinstance(self.param, QgsProcessingParameterTableField):
isinstance(self.param, QgsProcessingParameterField):
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
self.parentCombo = QComboBox()
idx = 0
for param in list(self.alg.parameterComponents().values()):
definition = self.alg.parameterDefinition(param.parameterName())
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterTable)):
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer)):
self.parentCombo.addItem(definition.description(), definition.name())
if self.param is not None:
if self.param.parentLayerParameter() == definition.name():
@@ -218,7 +218,7 @@ def setupUi(self):
idx = 1
for param in list(self.alg.parameterComponents().values()):
definition = self.alg.parameterDefinition(param.parameterName())
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterTable)):
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer)):
self.parentCombo.addItem(definition.description(), definition.name())
if self.param is not None:
if self.param.parentLayerParameter() == definition.name():
@@ -301,21 +301,21 @@ def okPressed(self):
isinstance(self.param, QgsProcessingParameterBoolean)):
self.param = QgsProcessingParameterBoolean(name, description, self.state.isChecked())
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD or
isinstance(self.param, QgsProcessingParameterTableField)):
isinstance(self.param, QgsProcessingParameterField)):
if self.parentCombo.currentIndex() < 0:
QMessageBox.warning(self, self.tr('Unable to define parameter'),
self.tr('Wrong or missing parameter values'))
return
parent = self.parentCombo.currentData()
datatype = self.datatypeCombo.currentData()
self.param = QgsProcessingParameterTableField(name, description, None, parent, datatype, self.multipleCheck.isChecked())
self.param = QgsProcessingParameterField(name, description, None, parent, datatype, self.multipleCheck.isChecked())
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_RASTER or
isinstance(self.param, QgsProcessingParameterRasterLayer)):
self.param = QgsProcessingParameterRasterLayer(
name, description)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE or
isinstance(self.param, QgsProcessingParameterTable)):
self.param = QgsProcessingParameterTable(
isinstance(self.param, QgsProcessingParameterVectorLayer)):
self.param = QgsProcessingParameterVectorLayer(
name, description)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or
isinstance(self.param, QgsProcessingParameterFeatureSource)):

0 comments on commit 0da3652

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