Skip to content

Commit 4a7a8ff

Browse files
committed
Update python code
1 parent b6779f6 commit 4a7a8ff

33 files changed

+95
-62
lines changed

python/core/qgsfields.sip

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ class QgsFields
157157
%End
158158

159159
/**
160-
* Look up field's index from the field name.
160+
* Get the field index from the field name.
161161
* This method takes is case sensitive and only matches the data source
162162
* name of the field.
163+
* Alias for indexOf
163164
*
164165
* @param fieldName The name of the field.
165166
*
@@ -168,6 +169,19 @@ class QgsFields
168169
*/
169170
int indexFromName( const QString& fieldName ) const;
170171

172+
/**
173+
* Get the field index from the field name.
174+
* This method takes is case sensitive and only matches the data source
175+
* name of the field.
176+
*
177+
* @param fieldName The name of the field.
178+
*
179+
* @return The field index if found or -1 in case it cannot be found.
180+
* @see lookupField For a more tolerant alternative.
181+
* @note Added in QGIS 3.0
182+
*/
183+
int indexOf( const QString& fieldName ) const;
184+
171185
/**
172186
* Look up field's index from the field name.
173187
* This method matches in the following order:

python/plugins/processing/algs/qgis/BasicStatisticsStrings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def processAlgorithm(self, progress):
8686

8787
outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
8888

89-
index = layer.fieldNameIndex(fieldName)
89+
index = layer.fields().lookupField(fieldName)
9090

9191
sumValue = 0
9292
minValue = 0

python/plugins/processing/algs/qgis/Buffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve,
3535
segments, endCapStyle=1, joinStyle=1, mitreLimit=2):
3636

3737
if useField:
38-
field = layer.fieldNameIndex(field)
38+
field = layer.fields().lookupField(field)
3939

4040
outFeat = QgsFeature()
4141

python/plugins/processing/algs/qgis/ConvexHull.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def processAlgorithm(self, progress):
7878

7979
f = QgsField('value', QVariant.String, '', 255)
8080
if useField:
81-
index = layer.fieldNameIndex(fieldName)
81+
index = layer.fields().lookupField(fieldName)
8282
fType = layer.fields()[index].type()
8383
if fType in [QVariant.Int, QVariant.UInt, QVariant.LongLong, QVariant.ULongLong]:
8484
f.setType(fType)

python/plugins/processing/algs/qgis/DeleteColumn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def defineCharacteristics(self):
5252
def processAlgorithm(self, progress):
5353
layer = dataobjects.getObjectFromUri(
5454
self.getParameterValue(self.INPUT))
55-
idx = layer.fieldNameIndex(self.getParameterValue(self.COLUMN))
55+
idx = layer.fields().lookupField(self.getParameterValue(self.COLUMN))
5656

5757
fields = layer.fields()
5858
fields.remove(idx)

python/plugins/processing/algs/qgis/Dissolve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def processAlgorithm(self, progress):
127127
outFeat.setAttributes(attrs)
128128
writer.addFeature(outFeat)
129129
else:
130-
field_indexes = [vlayerA.fieldNameIndex(f) for f in field_names.split(';')]
130+
field_indexes = [vlayerA.fields().lookupField(f) for f in field_names.split(';')]
131131

132132
attribute_dict = {}
133133
geometry_dict = defaultdict(lambda: [])

python/plugins/processing/algs/qgis/EquivalentNumField.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def processAlgorithm(self, progress):
5454
output = self.getOutputFromName(self.OUTPUT)
5555
vlayer = dataobjects.getObjectFromUri(
5656
self.getParameterValue(self.INPUT))
57-
fieldindex = vlayer.fieldNameIndex(fieldname)
57+
fieldindex = vlayer.fields().lookupField(fieldname)
5858
fields = vlayer.fields()
5959
fields.append(QgsField('NUM_FIELD', QVariant.Int))
6060
writer = output.getVectorWriter(fields, vlayer.wkbType(),

python/plugins/processing/algs/qgis/ExtractByAttribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def processAlgorithm(self, progress):
8787
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
8888
layer.wkbType(), layer.crs())
8989

90-
idx = layer.fieldNameIndex(fieldName)
90+
idx = layer.fields().lookupField(fieldName)
9191
fieldType = fields[idx].type()
9292

9393
if fieldType != QVariant.String and operator in self.OPERATORS[-2:]:

python/plugins/processing/algs/qgis/JoinAttributes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def processAlgorithm(self, progress):
7070
field2 = self.getParameterValue(self.TABLE_FIELD_2)
7171

7272
layer = dataobjects.getObjectFromUri(input)
73-
joinField1Index = layer.fieldNameIndex(field)
73+
joinField1Index = layer.fields().lookupField(field)
7474

7575
layer2 = dataobjects.getObjectFromUri(input2)
76-
joinField2Index = layer2.fieldNameIndex(field2)
76+
joinField2Index = layer2.fields().lookupField(field2)
7777

7878
outFields = vector.combineVectorFields(layer, layer2)
7979
writer = output.getVectorWriter(outFields, layer.wkbType(),

python/plugins/processing/algs/qgis/LinesIntersection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def processAlgorithm(self, progress):
7979
fieldA = self.getParameterValue(self.FIELD_A)
8080
fieldB = self.getParameterValue(self.FIELD_B)
8181

82-
idxA = layerA.fieldNameIndex(fieldA)
83-
idxB = layerB.fieldNameIndex(fieldB)
82+
idxA = layerA.fields().lookupField(fieldA)
83+
idxB = layerB.fields().lookupField(fieldB)
8484

8585
fieldList = [layerA.fields()[idxA],
8686
layerB.fields()[idxB]]

0 commit comments

Comments
 (0)