mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-10-31 00:06:02 -04:00 
			
		
		
		
	- Construct QgsFields from a list of QgsField - Append a list of QgsField - Append another QgsFields
		
			
				
	
	
		
			422 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			422 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| /************************************************************************
 | |
|  * This file has been generated automatically from                      *
 | |
|  *                                                                      *
 | |
|  * src/core/qgsfields.h                                                 *
 | |
|  *                                                                      *
 | |
|  * Do not edit manually ! Edit header and run scripts/sipify.pl again   *
 | |
|  ************************************************************************/
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| class QgsFields
 | |
| {
 | |
| %Docstring(signature="appended")
 | |
| Container of fields for a vector layer.
 | |
| 
 | |
| In addition to storing a list of :py:class:`QgsField` instances, it also:
 | |
| 
 | |
| - allows quick lookups of field names to index in the list
 | |
| - keeps track of where the field definition comes from (vector data provider, joined layer or newly added from an editing operation)
 | |
| 
 | |
| .. note::
 | |
| 
 | |
|    :py:class:`QgsFields` objects are implicitly shared.
 | |
| %End
 | |
| 
 | |
| %TypeHeaderCode
 | |
| #include "qgsfields.h"
 | |
| %End
 | |
|   public:
 | |
|     static const QMetaObject staticMetaObject;
 | |
| 
 | |
|   public:
 | |
| 
 | |
| 
 | |
|     QgsFields() /HoldGIL/;
 | |
| %Docstring
 | |
| Constructor for an empty field container
 | |
| %End
 | |
| 
 | |
|     QgsFields( const QgsFields &other ) /HoldGIL/;
 | |
| %Docstring
 | |
| Copy constructor
 | |
| %End
 | |
| 
 | |
| 
 | |
|     QgsFields( const QList< QgsField > &fields ) /HoldGIL/;
 | |
| %Docstring
 | |
| Construct QgsFields from a list of ``fields``.
 | |
| 
 | |
| .. versionadded:: 3.40
 | |
| %End
 | |
| 
 | |
|     virtual ~QgsFields();
 | |
| 
 | |
|     void clear() /HoldGIL/;
 | |
| %Docstring
 | |
| Removes all fields
 | |
| %End
 | |
| 
 | |
|     bool append( const QgsField &field, Qgis::FieldOrigin origin = Qgis::FieldOrigin::Provider, int originIndex = -1 ) /HoldGIL/;
 | |
| %Docstring
 | |
| Appends a ``field``.
 | |
| 
 | |
| The field must have a unique name, otherwise it is rejected (returns ``False``).
 | |
| 
 | |
| The ``originIndex`` argument must be set to a value corresponding to the ``origin`` type:
 | |
| 
 | |
| - :py:class:`Qgis`.FieldOrigin.Provider: The field's originIndex is the index in provider's fields.
 | |
| - :py:class:`Qgis`.FieldOrigin.Join: The field's originIndex / 1000 = index of the join, originIndex % 1000 = index within the join
 | |
| - :py:class:`Qgis`.FieldOrigin.Edit: The originIndex is the index in the list of added attributes
 | |
| %End
 | |
| 
 | |
|     bool append( const QList< QgsField > &fields, Qgis::FieldOrigin origin = Qgis::FieldOrigin::Provider ) /HoldGIL/;
 | |
| %Docstring
 | |
| Appends a list of ``fields``.
 | |
| 
 | |
| The fields must have unique names, otherwise it is rejected (returns ``False``).
 | |
| 
 | |
| .. versionadded:: 3.40
 | |
| %End
 | |
| 
 | |
|     bool append( const QgsFields &fields ) /HoldGIL/;
 | |
| %Docstring
 | |
| Appends another set of ``fields`` to these fields.
 | |
| 
 | |
| The fields must have unique names, otherwise it is rejected (returns ``False``).
 | |
| 
 | |
| .. versionadded:: 3.40
 | |
| %End
 | |
| 
 | |
|     bool rename( int fieldIdx, const QString &name ) /HoldGIL/;
 | |
| %Docstring
 | |
| Renames a name of field. The field must have unique name, otherwise change is rejected (returns ``False``)
 | |
| 
 | |
| .. versionadded:: 3.6
 | |
| %End
 | |
| 
 | |
|     bool appendExpressionField( const QgsField &field, int originIndex ) /HoldGIL/;
 | |
| %Docstring
 | |
| Appends an expression field. The field must have unique name, otherwise it is rejected (returns ``False``)
 | |
| %End
 | |
| 
 | |
| 
 | |
|     void remove( int fieldIdx ) /HoldGIL/;
 | |
| %Docstring
 | |
| Removes the field with the given index.
 | |
| 
 | |
| :raises KeyError: if no field with the specified index exists
 | |
| %End
 | |
| %MethodCode
 | |
|     if ( a0 < 0 || a0 >= sipCpp->count() )
 | |
|     {
 | |
|       PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
 | |
|       sipIsErr = 1;
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       sipCpp->remove( a0 );
 | |
|     }
 | |
| %End
 | |
| 
 | |
|     void extend( const QgsFields &other ) /HoldGIL/;
 | |
| %Docstring
 | |
| Extends with fields from another QgsFields container
 | |
| %End
 | |
| 
 | |
|     bool isEmpty() const /HoldGIL/;
 | |
| %Docstring
 | |
| Checks whether the container is empty
 | |
| %End
 | |
| 
 | |
|     int count() const /HoldGIL/;
 | |
| %Docstring
 | |
| Returns number of items
 | |
| %End
 | |
| 
 | |
|     Py_ssize_t __len__() const /HoldGIL/;
 | |
| %MethodCode
 | |
|     sipRes = sipCpp->count();
 | |
| %End
 | |
| 
 | |
|     //! Ensures that bool(obj) returns ``True`` (otherwise __len__() would be used)
 | |
|     int __bool__() const /HoldGIL/;
 | |
| %MethodCode
 | |
|     sipRes = true;
 | |
| %End
 | |
| 
 | |
|     int size() const /HoldGIL/;
 | |
| %Docstring
 | |
| Returns number of items
 | |
| %End
 | |
| 
 | |
|     QStringList names() const /HoldGIL/;
 | |
| %Docstring
 | |
| Returns a list with field names
 | |
| %End
 | |
| 
 | |
|     bool exists( int i ) const /HoldGIL/;
 | |
| %Docstring
 | |
| Returns if a field index is valid
 | |
| 
 | |
| :param i: Index of the field which needs to be checked
 | |
| 
 | |
| :return: ``True`` if the field exists
 | |
| %End
 | |
| 
 | |
| 
 | |
|     QgsField &operator[]( int i ) /HoldGIL,Factory/;
 | |
| %MethodCode
 | |
|     Py_ssize_t idx = sipConvertFromSequenceIndex( a0, sipCpp->count() );
 | |
|     if ( idx < 0 )
 | |
|       sipIsErr = 1;
 | |
|     else
 | |
|       sipRes = new QgsField( sipCpp->operator[]( idx ) );
 | |
| %End
 | |
| 
 | |
|     SIP_PYOBJECT __getitem__( const QString &name ) const /HoldGIL,TypeHint="QgsField"/;
 | |
| %MethodCode
 | |
|     const int fieldIdx = sipCpp->lookupField( *a0 );
 | |
|     if ( fieldIdx == -1 )
 | |
|     {
 | |
|       PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
 | |
|       sipIsErr = 1;
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       sipRes = sipConvertFromType( new QgsField( sipCpp->at( fieldIdx ) ), sipType_QgsField, Py_None );
 | |
|     }
 | |
| %End
 | |
| 
 | |
| 
 | |
|     QgsField at( int i ) const /HoldGIL,Factory/;
 | |
| %Docstring
 | |
| Returns the field at particular index (must be in range 0..N-1).
 | |
| 
 | |
| :raises KeyError: if no field exists at the specified index
 | |
| %End
 | |
| %MethodCode
 | |
|     if ( a0 < 0 || a0 >= sipCpp->count() )
 | |
|     {
 | |
|       PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
 | |
|       sipIsErr = 1;
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       sipRes = new QgsField( sipCpp->at( a0 ) );
 | |
|     }
 | |
| %End
 | |
| 
 | |
| 
 | |
|     QgsField field( int fieldIdx ) const /HoldGIL,Factory/;
 | |
| %Docstring
 | |
| Returns the field at particular index (must be in range 0..N-1).
 | |
| 
 | |
| :raises KeyError: if no field exists at the specified index
 | |
| %End
 | |
| %MethodCode
 | |
|     if ( a0 < 0 || a0 >= sipCpp->count() )
 | |
|     {
 | |
|       PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
 | |
|       sipIsErr = 1;
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       sipRes = new QgsField( sipCpp->field( a0 ) );
 | |
|     }
 | |
| %End
 | |
| 
 | |
| 
 | |
|     QgsField field( const QString &name ) const /HoldGIL,Factory/;
 | |
| %Docstring
 | |
| Returns the field with matching name.
 | |
| 
 | |
| :raises KeyError: if no matching field was found.
 | |
| %End
 | |
| %MethodCode
 | |
|     int fieldIdx = sipCpp->indexFromName( *a0 );
 | |
|     if ( fieldIdx == -1 )
 | |
|     {
 | |
|       PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
 | |
|       sipIsErr = 1;
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       sipRes = new QgsField( sipCpp->field( *a0 ) );
 | |
|     }
 | |
| %End
 | |
| 
 | |
| 
 | |
|     Qgis::FieldOrigin fieldOrigin( int fieldIdx ) const /HoldGIL/;
 | |
| %Docstring
 | |
| Returns the field's origin (value from an enumeration).
 | |
| 
 | |
| :raises KeyError: if no field exists at the specified index
 | |
| %End
 | |
| %MethodCode
 | |
|     if ( a0 < 0 || a0 >= sipCpp->count() )
 | |
|     {
 | |
|       PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
 | |
|       sipIsErr = 1;
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       sipRes = sipCpp->fieldOrigin( a0 );
 | |
|     }
 | |
| %End
 | |
| 
 | |
| 
 | |
|     int fieldOriginIndex( int fieldIdx ) const /HoldGIL/;
 | |
| %Docstring
 | |
| Returns the field's origin index (its meaning is specific to each type of origin).
 | |
| 
 | |
| - :py:class:`Qgis`.FieldOrigin.Provider: The field's originIndex is the index in provider's fields.
 | |
| - :py:class:`Qgis`.FieldOrigin.Join: The field's originIndex / 1000 = index of the join, originIndex % 1000 = index within the join
 | |
| - :py:class:`Qgis`.FieldOrigin.Edit: The originIndex is the index in the list of added attributes
 | |
| 
 | |
| :raises KeyError: if no field exists at the specified index
 | |
| %End
 | |
| %MethodCode
 | |
|     if ( a0 < 0 || a0 >= sipCpp->count() )
 | |
|     {
 | |
|       PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
 | |
|       sipIsErr = 1;
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       sipRes = sipCpp->fieldOriginIndex( a0 );
 | |
|     }
 | |
| %End
 | |
| 
 | |
|     int indexFromName( const QString &fieldName ) const /HoldGIL/;
 | |
| %Docstring
 | |
| Gets the field index from the field name.
 | |
| 
 | |
| This method is case sensitive and only matches the data source
 | |
| name of the field.
 | |
| 
 | |
| Alias for indexOf
 | |
| 
 | |
| :param fieldName: The name of the field.
 | |
| 
 | |
| :return: The field index if found or -1 in case it cannot be found.
 | |
| 
 | |
| .. seealso:: :py:func:`lookupField`
 | |
| %End
 | |
| 
 | |
|     int indexOf( const QString &fieldName ) const /HoldGIL/;
 | |
| %Docstring
 | |
| Gets the field index from the field name.
 | |
| 
 | |
| This method is case sensitive and only matches the data source
 | |
| name of the field.
 | |
| 
 | |
| :param fieldName: The name of the field.
 | |
| 
 | |
| :return: The field index if found or -1 in case it cannot be found.
 | |
| 
 | |
| .. seealso:: :py:func:`lookupField`
 | |
| %End
 | |
| 
 | |
|      int lookupField( const QString &fieldName ) const /HoldGIL/;
 | |
| %Docstring
 | |
| Looks up field's index from the field name.
 | |
| This method matches in the following order:
 | |
| 
 | |
| 1. The exact field name taking case sensitivity into account
 | |
| 2. Looks for the field name by case insensitive comparison
 | |
| 3. The field alias (case insensitive)
 | |
| 
 | |
| :param fieldName: The name to look for.
 | |
| 
 | |
| :return: The field index if found or -1 in case it cannot be found.
 | |
| 
 | |
| .. seealso:: :py:func:`indexFromName`
 | |
| %End
 | |
| 
 | |
|     QgsAttributeList allAttributesList() const /HoldGIL/;
 | |
| %Docstring
 | |
| Utility function to get list of attribute indexes
 | |
| %End
 | |
| 
 | |
|     QList<QgsField> toList() const /HoldGIL/;
 | |
| %Docstring
 | |
| Utility function to return a list of :py:class:`QgsField` instances
 | |
| %End
 | |
| 
 | |
|     bool operator==( const QgsFields &other ) const /HoldGIL/;
 | |
|     bool operator!=( const QgsFields &other ) const  /HoldGIL/;
 | |
| 
 | |
| 
 | |
|     QIcon iconForField( int fieldIdx, bool considerOrigin = false ) const /Factory/;
 | |
| %Docstring
 | |
| Returns an icon corresponding to a field index, based on the field's type and source
 | |
| 
 | |
| :param fieldIdx: the field index
 | |
| :param considerOrigin: if ``True`` the icon will the origin of the field
 | |
| 
 | |
| :raises KeyError: if no field exists at the specified index
 | |
| %End
 | |
| %MethodCode
 | |
|     if ( a0 < 0 || a0 >= sipCpp->count() )
 | |
|     {
 | |
|       PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
 | |
|       sipIsErr = 1;
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       sipRes = new QIcon( sipCpp->iconForField( a0 ) );
 | |
|     }
 | |
| %End
 | |
| 
 | |
|     static QIcon iconForFieldType( QMetaType::Type type, QMetaType::Type subType = QMetaType::Type::UnknownType, const QString &typeString = QString() );
 | |
| %Docstring
 | |
| Returns an icon corresponding to a field ``type``
 | |
| 
 | |
| Since QGIS 3.24, the optional ``subType`` argument can be used to specify the type of variant list or map values.
 | |
| Since QGIS 3.30, the optional ``typeString`` argument can be used to specify field type strings for handling user field types.
 | |
| 
 | |
| .. versionadded:: 3.16
 | |
| %End
 | |
| 
 | |
|  static QIcon iconForFieldType( QVariant::Type type, QVariant::Type subType, const QString &typeString = QString() ) /Deprecated/;
 | |
| %Docstring
 | |
| Returns an icon corresponding to a field ``type``
 | |
| 
 | |
| Since QGIS 3.24, the optional ``subType`` argument can be used to specify the type of variant list or map values.
 | |
| Since QGIS 3.30, the optional ``typeString`` argument can be used to specify field type strings for handling user field types.
 | |
| 
 | |
| .. versionadded:: 3.16
 | |
| 
 | |
| .. deprecated:: QGIS 3.38
 | |
|   use the method with a QMetaType.Type argument instead
 | |
| %End
 | |
| 
 | |
|     operator QVariant() const;
 | |
| 
 | |
| 
 | |
|     void __setitem__( int key, const QgsField &field ) /HoldGIL/;
 | |
| %MethodCode
 | |
|     int idx = ( int )sipConvertFromSequenceIndex( a0, sipCpp->count() );
 | |
|     if ( idx < 0 )
 | |
|       sipIsErr = 1;
 | |
|     else
 | |
|       ( *sipCpp )[idx] = *a1;
 | |
| %End
 | |
| 
 | |
| 
 | |
| 
 | |
| };
 | |
| 
 | |
| 
 | |
| 
 | |
| /************************************************************************
 | |
|  * This file has been generated automatically from                      *
 | |
|  *                                                                      *
 | |
|  * src/core/qgsfields.h                                                 *
 | |
|  *                                                                      *
 | |
|  * Do not edit manually ! Edit header and run scripts/sipify.pl again   *
 | |
|  ************************************************************************/
 |