Skip to content

Commit

Permalink
Port create attribute index alg to new api
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 21, 2017
1 parent c685ec2 commit a9f97fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
26 changes: 12 additions & 14 deletions python/plugins/processing/algs/qgis/CreateAttributeIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
from qgis.core import (QgsVectorDataProvider,
QgsFields,
QgsApplication,
QgsProcessingUtils)
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterDefinition,
QgsProcessingOutputVectorLayer)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterTable
from processing.core.parameters import ParameterTableField
from processing.core.outputs import OutputVector


class CreateAttributeIndex(QgisAlgorithm):
Expand All @@ -53,12 +53,11 @@ def group(self):

def __init__(self):
super().__init__()
self.addParameter(ParameterTable(self.INPUT,
self.tr('Input Layer')))
self.addParameter(ParameterTableField(self.FIELD,
self.tr('Attribute to index'), self.INPUT))
self.addOutput(OutputVector(self.OUTPUT,
self.tr('Indexed layer'), True))
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
self.tr('Input Layer')))
self.addParameter(QgsProcessingParameterField(self.FIELD,
self.tr('Attribute to index'), None, self.INPUT))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Indexed layer')))

def name(self):
return 'createattributeindex'
Expand All @@ -67,9 +66,8 @@ def displayName(self):
return self.tr('Create attribute index')

def processAlgorithm(self, parameters, context, feedback):
file_name = self.getParameterValue(self.INPUT)
layer = QgsProcessingUtils.mapLayerFromString(file_name, context)
field = self.getParameterValue(self.FIELD)
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
field = self.parameterAsString(parameters, self.FIELD, context)
provider = layer.dataProvider()

field_index = layer.fields().lookupField(field)
Expand All @@ -84,4 +82,4 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.pushInfo(self.tr("Layer's data provider does not support "
"creating attribute indexes"))

self.setOutputValue(self.OUTPUT, file_name)
return {self.OUTPUT: layer.id()}
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
# from .SnapGeometries import SnapGeometriesToLayer
# from .PoleOfInaccessibility import PoleOfInaccessibility
# from .RasterCalculator import RasterCalculator
# from .CreateAttributeIndex import CreateAttributeIndex
from .CreateAttributeIndex import CreateAttributeIndex
from .DropGeometry import DropGeometry
from .BasicStatistics import BasicStatisticsForField
# from .Heatmap import Heatmap
Expand Down Expand Up @@ -249,7 +249,7 @@ def getAlgs(self):
# RemoveNullGeometry(),
# ExtendLines(), ExtractSpecificNodes(),
# GeometryByExpression(), SnapGeometriesToLayer(),
# PoleOfInaccessibility(), CreateAttributeIndex(),
# PoleOfInaccessibility(),
#
# RasterCalculator(), Heatmap(), Orthogonalize(),
# ShortestPathPointToPoint(), ShortestPathPointToLayer(),
Expand All @@ -266,6 +266,7 @@ def getAlgs(self):
BoundingBox(),
CheckValidity(),
Clip(),
CreateAttributeIndex(),
DeleteColumn(),
DeleteHoles(),
DensifyGeometries(),
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
wrapper = StringWidgetWrapper
elif param.type() == 'expression':
wrapper = ExpressionWidgetWrapper
elif param.type() == 'table':
elif param.type() == 'vector':
wrapper = TableWidgetWrapper
elif param.type() == 'field':
wrapper = TableFieldWidgetWrapper
Expand Down

0 comments on commit a9f97fc

Please sign in to comment.