Skip to content

Commit b6779f6

Browse files
committed
Rename QgsFields::fieldNameIndex() to lookupField()
To have two clearly different names for tolerant/intolerant index lookup
1 parent 9a261cf commit b6779f6

File tree

177 files changed

+1324
-1217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+1324
-1217
lines changed

doc/api_break.dox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ None will need to be modified, as the method will return an empty geometry if th
746746

747747
<ul>
748748
<li>All const methods which return a field from QgsFields now return a QgsField value, not a reference.</li>
749+
<li>fieldNameIndex has been renamed to lookupField. See the API documentation for details.</li>
749750
</ul>
750751

751752
\subsection qgis_api_break_3_0_QgsFieldExpressionWidget QgsFieldExpressionWidget
@@ -1414,6 +1415,7 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.</li>
14141415
<li>Deleted attributeEditorElementFromDomElement
14151416
<li>editFormConfig() returns a copy instead of direct access (Use setEditFormConfig to update)
14161417
<li>Removed valueRelation(), replaced with QgsEditFormConfig::editorWidgetConfig
1418+
<li>Removed fieldNameIndex(), use QgsFields::lookupField() or QgsFields::indexFromName() instead
14171419
</ul>
14181420

14191421
\subsection qgis_api_break_3_0_QgsVectorLayerEditBuffer QgsVectorLayerEditBuffer

python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
%Include qgsfeaturerequest.sip
5656
%Include qgsfeedback.sip
5757
%Include qgsfield.sip
58+
%Include qgsfields.sip
5859
%Include qgsgeometrysimplifier.sip
5960
%Include qgsgeometryvalidator.sip
6061
%Include qgsgml.sip

python/core/qgsexpression.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ class QgsExpression
5353
*/
5454
QStringList referencedColumns() const;
5555

56+
/**
57+
* Return a list of field name indexes obtained from the provided fields.
58+
*
59+
* @note Added in QGIS 3.0
60+
*/
61+
QSet<int> referencedAttributeIndexes( const QgsFields& fields ) const;
62+
5663
//! Returns true if the expression uses feature geometry for some computation
5764
bool needsGeometry() const;
5865

python/core/qgsfield.sip

Lines changed: 0 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -254,224 +254,3 @@ class QgsField
254254
*/
255255
const QgsEditorWidgetSetup& editorWidgetSetup() const;
256256
}; // class QgsField
257-
258-
259-
/** \class QgsFields
260-
* \ingroup core
261-
* Container of fields for a vector layer.
262-
*
263-
* In addition to storing a list of QgsField instances, it also:
264-
* - allows quick lookups of field names to index in the list
265-
* - keeps track of where the field definition comes from (vector data provider, joined layer or newly added from an editing operation)
266-
* \note QgsFields objects are implicitly shared.
267-
*/
268-
269-
class QgsFields
270-
{
271-
%TypeHeaderCode
272-
#include <qgsfield.h>
273-
%End
274-
public:
275-
276-
enum FieldOrigin
277-
{
278-
OriginUnknown, //!< it has not been specified where the field comes from
279-
OriginProvider, //!< field comes from the underlying data provider of the vector layer (originIndex = index in provider's fields)
280-
OriginJoin, //!< field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index within the join)
281-
OriginEdit, //!< field has been temporarily added in editing mode (originIndex = index in the list of added attributes)
282-
OriginExpression //!< field is calculated from an expression
283-
};
284-
285-
/** Constructor for an empty field container
286-
*/
287-
QgsFields();
288-
289-
/** Copy constructor
290-
*/
291-
QgsFields( const QgsFields& other );
292-
293-
virtual ~QgsFields();
294-
295-
//! Remove all fields
296-
void clear();
297-
//! Append a field. The field must have unique name, otherwise it is rejected (returns false)
298-
bool append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
299-
//! Append an expression field. The field must have unique name, otherwise it is rejected (returns false)
300-
bool appendExpressionField( const QgsField& field, int originIndex );
301-
//! Remove a field with the given index
302-
void remove( int fieldIdx );
303-
%MethodCode
304-
if ( a0 < 0 || a0 >= sipCpp->count() )
305-
{
306-
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
307-
sipIsErr = 1;
308-
}
309-
else
310-
{
311-
sipCpp->remove( a0 );
312-
}
313-
%End
314-
315-
//! Extend with fields from another QgsFields container
316-
void extend( const QgsFields& other );
317-
318-
//! Check whether the container is empty
319-
bool isEmpty() const;
320-
//! Return number of items
321-
int count() const;
322-
// __len__ annotation since sip 4.10.3
323-
//int count() const /__len__/;
324-
int __len__() const;
325-
%MethodCode
326-
sipRes = sipCpp->count();
327-
%End
328-
//! Return number of items
329-
int size() const;
330-
//! Return if a field index is valid
331-
//! @param i Index of the field which needs to be checked
332-
//! @return True if the field exists
333-
bool exists( int i ) const;
334-
335-
//! Get field at particular index (must be in range 0..N-1)
336-
// const QgsField& operator[]( int i ) const;
337-
QgsField& operator[](int i) /Factory/;
338-
%MethodCode
339-
SIP_SSIZE_T idx = sipConvertFromSequenceIndex(a0, sipCpp->count());
340-
if (idx < 0)
341-
sipIsErr = 1;
342-
else
343-
sipRes = new QgsField(sipCpp->operator[](idx));
344-
%End
345-
346-
//! Get field at particular index (must be in range 0..N-1)
347-
QgsField at( int i ) const /Factory/;
348-
%MethodCode
349-
if ( a0 < 0 || a0 >= sipCpp->count() )
350-
{
351-
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
352-
sipIsErr = 1;
353-
}
354-
else
355-
{
356-
sipRes = new QgsField( sipCpp->at( a0 ) );
357-
}
358-
%End
359-
360-
//! Get field at particular index (must be in range 0..N-1)
361-
QgsField field( int fieldIdx ) const /Factory/;
362-
%MethodCode
363-
if ( a0 < 0 || a0 >= sipCpp->count() )
364-
{
365-
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
366-
sipIsErr = 1;
367-
}
368-
else
369-
{
370-
sipRes = new QgsField( sipCpp->field( a0 ) );
371-
}
372-
%End
373-
374-
//! Get field at particular index (must be in range 0..N-1)
375-
QgsField field( const QString& name ) const /Factory/;
376-
%MethodCode
377-
int fieldIdx = sipCpp->indexFromName(*a0);
378-
if (fieldIdx == -1)
379-
{
380-
PyErr_SetString(PyExc_KeyError, a0->toAscii());
381-
sipIsErr = 1;
382-
}
383-
else
384-
{
385-
sipRes = new QgsField( sipCpp->field( *a0 ) );
386-
}
387-
%End
388-
389-
//! Get field's origin (value from an enumeration)
390-
FieldOrigin fieldOrigin( int fieldIdx ) const;
391-
%MethodCode
392-
if ( a0 < 0 || a0 >= sipCpp->count() )
393-
{
394-
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
395-
sipIsErr = 1;
396-
}
397-
else
398-
{
399-
sipRes = sipCpp->fieldOrigin( a0 );
400-
}
401-
%End
402-
403-
//! Get field's origin index (its meaning is specific to each type of origin)
404-
int fieldOriginIndex( int fieldIdx ) const;
405-
%MethodCode
406-
if ( a0 < 0 || a0 >= sipCpp->count() )
407-
{
408-
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
409-
sipIsErr = 1;
410-
}
411-
else
412-
{
413-
sipRes = sipCpp->fieldOriginIndex( a0 );
414-
}
415-
%End
416-
417-
//! Look up field's index from name. Returns -1 on error
418-
int indexFromName( const QString& name ) const;
419-
420-
//! Look up field's index from name
421-
//! also looks up case-insensitive if there is no match otherwise
422-
//! @note added in 2.4
423-
int fieldNameIndex( const QString& fieldName ) const;
424-
425-
//! Utility function to get list of attribute indexes
426-
//! @note added in 2.4
427-
QgsAttributeList allAttributesList() const;
428-
429-
//! Utility function to return a list of QgsField instances
430-
QList<QgsField> toList() const;
431-
432-
//! @note added in 2.6
433-
bool operator==( const QgsFields& other ) const;
434-
//! @note added in 2.6
435-
bool operator!=( const QgsFields& other ) const;
436-
437-
/** Returns an icon corresponding to a field index, based on the field's type and source
438-
* @note added in QGIS 2.14
439-
*/
440-
QIcon iconForField( int fieldIdx ) const /Factory/;
441-
%MethodCode
442-
if ( a0 < 0 || a0 >= sipCpp->count() )
443-
{
444-
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
445-
sipIsErr = 1;
446-
}
447-
else
448-
{
449-
sipRes = new QIcon( sipCpp->iconForField( a0 ) );
450-
}
451-
%End
452-
453-
//! Allows direct construction of QVariants from fields.
454-
operator QVariant() const;
455-
456-
/* SIP_PYOBJECT __getitem__(int key);
457-
%MethodCode
458-
if (a0 = sipConvertFromSequenceIndex(a0, sipCpp->count()) < 0)
459-
sipIsErr = 1;
460-
else
461-
{
462-
qDebug("__getitem__ %d", a0);
463-
QgsField* fld = new QgsField(sipCpp->at(a0));
464-
sipRes = sipConvertFromType(fld, sipType_QgsField, Py_None);
465-
}
466-
%End*/
467-
468-
void __setitem__(int key, const QgsField& field);
469-
%MethodCode
470-
int idx = (int)sipConvertFromSequenceIndex(a0, sipCpp->count());
471-
if (idx < 0)
472-
sipIsErr = 1;
473-
else
474-
(*sipCpp)[idx] = *a1;
475-
%End
476-
477-
};

0 commit comments

Comments
 (0)