19 #include "qgis_core.h"
22 #include <QExplicitlySharedDataPointer>
35 class QgsFeaturePrivate;
58 #if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01)
59 #define sipType_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
65 Q_PROPERTY(
QgsAttributes attributes READ attributes WRITE setAttributes )
66 Q_PROPERTY(
QgsFields fields READ fields WRITE setFields )
67 Q_PROPERTY(
QgsGeometry geometry READ geometry WRITE setGeometry )
72 SIP_PYOBJECT __iter__();
75 PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None );
76 sipRes = PyObject_GetIter( attrs );
79 SIP_PYOBJECT __getitem__(
int key );
82 if ( a0 < 0 || a0 >= attrs.count() )
84 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
89 QVariant *v =
new QVariant( attrs.at( a0 ) );
90 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
94 SIP_PYOBJECT __getitem__(
const QString &name );
96 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
99 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
104 QVariant *v =
new QVariant( sipCpp->attribute( fieldIdx ) );
105 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
109 void __setitem__(
int key, QVariant value / GetWrapper / );
113 if ( a1Wrapper == Py_None )
115 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
119 rv = sipCpp->setAttribute( a0, *a1 );
124 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
129 void __setitem__(
const QString &key, QVariant value / GetWrapper / );
131 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
132 if ( fieldIdx == -1 )
134 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
139 if ( a1Wrapper == Py_None )
141 sipCpp->setAttribute( *a0, QVariant( QVariant::Int ) );
145 sipCpp->setAttribute( fieldIdx, *a1 );
150 void __delitem__(
int key );
152 if ( a0 >= 0 && a0 < sipCpp->attributes().count() )
153 sipCpp->deleteAttribute( a0 );
156 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
161 void __delitem__(
const QString &name );
163 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
164 if ( fieldIdx == -1 )
166 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
170 sipCpp->deleteAttribute( fieldIdx );
263 QVariantMap attributeMap()
const;
277 SIP_PYOBJECT attributeMap() const
SIP_TYPEHINT( Dict[
str, Optional[
object]] );
279 const
int fieldSize = sipCpp->fields().size();
280 const
int attributeSize = sipCpp->attributes().size();
281 if ( fieldSize == 0 && attributeSize != 0 )
283 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Field definition has not been set for feature" ).toUtf8().constData() );
286 else if ( fieldSize != attributeSize )
288 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Feature attribute size (%1) does not match number of fields (%2)" ).arg( attributeSize ).arg( fieldSize ).toUtf8().constData() );
293 QVariantMap *v =
new QVariantMap( sipCpp->attributeMap() );
294 sipRes = sipConvertFromNewType( v, sipType_QVariantMap, Py_None );
303 int attributeCount()
const;
335 bool setAttribute(
int field,
const QVariant &attr );
362 bool setAttribute(
int field,
const QVariant &attr / GetWrapper / );
366 if ( a1Wrapper == Py_None )
368 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
372 rv = sipCpp->setAttribute( a0, *a1 );
377 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
394 void initAttributes(
int fieldCount );
409 void resizeAttributes(
int fieldCount );
417 void padAttributes(
int count );
428 void deleteAttribute(
int field );
455 void deleteAttribute(
int field );
457 if ( a0 >= 0 && a0 < sipCpp->attributes().count() )
458 sipCpp->deleteAttribute( a0 );
461 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
475 bool isValid()
const;
484 void setValid(
bool validity );
491 bool hasGeometry()
const;
543 void setGeometry( std::unique_ptr< QgsAbstractGeometry > geometry );
547 sipCpp->setGeometry( std::unique_ptr< QgsAbstractGeometry>( a0 ) );
557 void clearGeometry();
590 bool setAttribute(
const QString &name,
const QVariant &value );
621 void setAttribute(
const QString &name,
const QVariant &value / GetWrapper / );
623 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
624 if ( fieldIdx == -1 )
626 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
631 if ( a1Wrapper == Py_None )
633 sipCpp->setAttribute( *a0, QVariant( QVariant::Int ) );
637 sipCpp->setAttribute( fieldIdx, *a1 );
654 bool deleteAttribute(
const QString &name );
686 bool deleteAttribute(
const QString &name );
688 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
689 if ( fieldIdx == -1 )
691 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
697 sipCpp->deleteAttribute( fieldIdx );
714 QVariant attribute(
const QString &name )
const;
742 SIP_PYOBJECT attribute(
const QString &name )
const;
744 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
745 if ( fieldIdx == -1 )
747 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
752 QVariant *v =
new QVariant( sipCpp->attribute( fieldIdx ) );
753 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
767 QVariant attribute(
int fieldIdx )
const;
794 SIP_PYOBJECT attribute(
int fieldIdx )
const;
797 if ( a0 < 0 || a0 >= sipCpp->attributes().count() )
799 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
804 QVariant *v =
new QVariant( sipCpp->attribute( a0 ) );
805 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
836 int fieldNameIndex(
const QString &fieldName )
const;
847 int approximateMemoryUsage()
const;
850 operator QVariant()
const
852 return QVariant::fromValue( *
this );
857 QExplicitlySharedDataPointer<QgsFeaturePrivate> d;