1/************************************************************************ 2 * This file has been generated automatically from * 3 * * 4 * src/core/qgsfields.h * 5 * * 6 * Do not edit manually ! Edit header and run scripts/sipify.pl again * 7 ************************************************************************/ 8 9 10 11 12 13class QgsFields 14{ 15%Docstring 16Container of fields for a vector layer. 17 18In addition to storing a list of QgsField instances, it also: 19 20- allows quick lookups of field names to index in the list 21- keeps track of where the field definition comes from (vector data provider, joined layer or newly added from an editing operation) 22 23.. note:: 24 25 QgsFields objects are implicitly shared. 26%End 27 28%TypeHeaderCode 29#include "qgsfields.h" 30%End 31 public: 32 33 enum FieldOrigin 34 { 35 OriginUnknown, 36 OriginProvider, 37 OriginJoin, 38 OriginEdit, 39 OriginExpression 40 }; 41 42 43 QgsFields(); 44%Docstring 45Constructor for an empty field container 46%End 47 48 QgsFields( const QgsFields &other ); 49%Docstring 50Copy constructor 51%End 52 53 54 virtual ~QgsFields(); 55 56 void clear(); 57%Docstring 58Removes all fields 59%End 60 61 bool append( const QgsField &field, FieldOrigin origin = OriginProvider, int originIndex = -1 ); 62%Docstring 63Appends a field. The field must have unique name, otherwise it is rejected (returns ``False``) 64%End 65 66 bool rename( int fieldIdx, const QString &name ); 67%Docstring 68Renames a name of field. The field must have unique name, otherwise change is rejected (returns ``False``) 69 70.. versionadded:: 3.6 71%End 72 73 bool appendExpressionField( const QgsField &field, int originIndex ); 74%Docstring 75Appends an expression field. The field must have unique name, otherwise it is rejected (returns ``False``) 76%End 77 78 void remove( int fieldIdx ); 79%Docstring 80Removes a field with the given index 81%End 82%MethodCode 83 if ( a0 < 0 || a0 >= sipCpp->count() ) 84 { 85 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); 86 sipIsErr = 1; 87 } 88 else 89 { 90 sipCpp->remove( a0 ); 91 } 92%End 93 94 void extend( const QgsFields &other ); 95%Docstring 96Extends with fields from another QgsFields container 97%End 98 99 bool isEmpty() const; 100%Docstring 101Checks whether the container is empty 102%End 103 104 int count() const; 105%Docstring 106Returns number of items 107%End 108 109 int __len__() const; 110%MethodCode 111 sipRes = sipCpp->count(); 112%End 113 114 //! Ensures that bool(obj) returns ``True`` (otherwise __len__() would be used) 115 int __bool__() const; 116%MethodCode 117 sipRes = true; 118%End 119 120 int size() const; 121%Docstring 122Returns number of items 123%End 124 125 QStringList names() const; 126%Docstring 127Returns a list with field names 128 129.. versionadded:: 3.0 130%End 131 132 bool exists( int i ) const; 133%Docstring 134Returns if a field index is valid 135 136:param i: Index of the field which needs to be checked 137 138:return: ``True`` if the field exists 139%End 140 141 142 QgsField &operator[]( int i ) /Factory/; 143%MethodCode 144 SIP_SSIZE_T idx = sipConvertFromSequenceIndex( a0, sipCpp->count() ); 145 if ( idx < 0 ) 146 sipIsErr = 1; 147 else 148 sipRes = new QgsField( sipCpp->operator[]( idx ) ); 149%End 150 151 QgsField at( int i ) const /Factory/; 152%Docstring 153Gets field at particular index (must be in range 0..N-1) 154%End 155%MethodCode 156 if ( a0 < 0 || a0 >= sipCpp->count() ) 157 { 158 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); 159 sipIsErr = 1; 160 } 161 else 162 { 163 sipRes = new QgsField( sipCpp->at( a0 ) ); 164 } 165%End 166 167 QgsField field( int fieldIdx ) const /Factory/; 168%Docstring 169Gets field at particular index (must be in range 0..N-1) 170%End 171%MethodCode 172 if ( a0 < 0 || a0 >= sipCpp->count() ) 173 { 174 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); 175 sipIsErr = 1; 176 } 177 else 178 { 179 sipRes = new QgsField( sipCpp->field( a0 ) ); 180 } 181%End 182 183 QgsField field( const QString &name ) const /Factory/; 184%Docstring 185Gets field with matching name 186%End 187%MethodCode 188 int fieldIdx = sipCpp->indexFromName( *a0 ); 189 if ( fieldIdx == -1 ) 190 { 191 PyErr_SetString( PyExc_KeyError, a0->toLatin1() ); 192 sipIsErr = 1; 193 } 194 else 195 { 196 sipRes = new QgsField( sipCpp->field( *a0 ) ); 197 } 198%End 199 200 FieldOrigin fieldOrigin( int fieldIdx ) const; 201%Docstring 202Gets field's origin (value from an enumeration) 203%End 204%MethodCode 205 if ( a0 < 0 || a0 >= sipCpp->count() ) 206 { 207 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); 208 sipIsErr = 1; 209 } 210 else 211 { 212 sipRes = sipCpp->fieldOrigin( a0 ); 213 } 214%End 215 216 int fieldOriginIndex( int fieldIdx ) const; 217%Docstring 218Gets field's origin index (its meaning is specific to each type of origin) 219%End 220%MethodCode 221 if ( a0 < 0 || a0 >= sipCpp->count() ) 222 { 223 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); 224 sipIsErr = 1; 225 } 226 else 227 { 228 sipRes = sipCpp->fieldOriginIndex( a0 ); 229 } 230%End 231 232 int indexFromName( const QString &fieldName ) const; 233%Docstring 234Gets the field index from the field name. 235This method is case sensitive and only matches the data source 236name of the field. 237Alias for indexOf 238 239:param fieldName: The name of the field. 240 241:return: The field index if found or -1 in case it cannot be found. 242 243.. seealso:: :py:func:`lookupField` 244%End 245 246 int indexOf( const QString &fieldName ) const; 247%Docstring 248Gets the field index from the field name. 249This method is case sensitive and only matches the data source 250name of the field. 251 252:param fieldName: The name of the field. 253 254:return: The field index if found or -1 in case it cannot be found. 255 256.. seealso:: :py:func:`lookupField` 257 258.. versionadded:: 3.0 259%End 260 261 int lookupField( const QString &fieldName ) const; 262%Docstring 263Looks up field's index from the field name. 264This method matches in the following order: 265 2661. The exact field name taking case sensitivity into account 2672. Looks for the field name by case insensitive comparison 2683. The field alias (case insensitive) 269 270:param fieldName: The name to look for. 271 272:return: The field index if found or -1 in case it cannot be found. 273 274.. seealso:: :py:func:`indexFromName` 275 276.. versionadded:: 2.4 277%End 278 279 QgsAttributeList allAttributesList() const; 280%Docstring 281Utility function to get list of attribute indexes 282 283.. versionadded:: 2.4 284%End 285 286 QList<QgsField> toList() const; 287%Docstring 288Utility function to return a list of QgsField instances 289%End 290 291 bool operator==( const QgsFields &other ) const; 292 bool operator!=( const QgsFields &other ) const; 293 294 QIcon iconForField( int fieldIdx, bool considerOrigin = false ) const /Factory/; 295%Docstring 296Returns an icon corresponding to a field index, based on the field's type and source 297 298:param fieldIdx: the field index 299:param considerOrigin: if ``True`` the icon will the origin of the field 300 301.. versionadded:: 2.14 302%End 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 sipRes = new QIcon( sipCpp->iconForField( a0 ) ); 312 } 313%End 314 315 316 static QIcon iconForFieldType( const QVariant::Type &type ) /Factory/; 317%Docstring 318Returns an icon corresponding to a field ``type`` 319 320.. versionadded:: 3.16 321%End 322 323 operator QVariant() const; 324 325 326 void __setitem__( int key, const QgsField &field ); 327%MethodCode 328 int idx = ( int )sipConvertFromSequenceIndex( a0, sipCpp->count() ); 329 if ( idx < 0 ) 330 sipIsErr = 1; 331 else 332 ( *sipCpp )[idx] = *a1; 333%End 334 335 336 337}; 338 339 340 341/************************************************************************ 342 * This file has been generated automatically from * 343 * * 344 * src/core/qgsfields.h * 345 * * 346 * Do not edit manually ! Edit header and run scripts/sipify.pl again * 347 ************************************************************************/ 348