60#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01)
61#define sipType_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
67 Q_PROPERTY(
QgsAttributes attributes READ attributes WRITE setAttributes )
68 Q_PROPERTY(
QgsFields fields READ fields WRITE setFields )
69 Q_PROPERTY(
QgsGeometry geometry READ geometry WRITE setGeometry )
77 PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None );
78 sipRes = PyObject_GetIter( attrs );
89 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
91 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
96 const QVariant v = sipCpp->attribute( a0 );
105 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
106 PyObject *args = PyTuple_Pack( 1, vartype );
107 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
108 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
110 Py_DECREF( vartype );
114 switch ( v.userType() )
116 case QMetaType::Type::Int:
117 sipRes = PyLong_FromLong( v.toInt() );
120 case QMetaType::Type::UInt:
121 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
124 case QMetaType::Type::Long:
125 case QMetaType::Type::LongLong:
126 sipRes = PyLong_FromLongLong( v.toLongLong() );
129 case QMetaType::Type::ULong:
130 case QMetaType::Type::ULongLong:
131 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
134 case QMetaType::Type::Bool:
135 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
138 case QMetaType::Type::Float:
139 case QMetaType::Type::Double:
140 sipRes = PyFloat_FromDouble( v.toDouble() );
143 case QMetaType::Type::QString:
144 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
149 QVariant *newV =
new QVariant( v );
150 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
158 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
160 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
161 if ( fieldIdx == -1 )
163 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
168 const QVariant v = sipCpp->attribute( fieldIdx );
171 Py_INCREF( Py_None );
177 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
178 PyObject *args = PyTuple_Pack( 1, vartype );
179 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
180 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
182 Py_DECREF( vartype );
186 switch ( v.userType() )
188 case QMetaType::Type::Int:
189 sipRes = PyLong_FromLong( v.toInt() );
192 case QMetaType::Type::UInt:
193 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
196 case QMetaType::Type::Long:
197 case QMetaType::Type::LongLong:
198 sipRes = PyLong_FromLongLong( v.toLongLong() );
201 case QMetaType::Type::ULong:
202 case QMetaType::Type::ULongLong:
203 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
206 case QMetaType::Type::Bool:
207 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
210 case QMetaType::Type::Float:
211 case QMetaType::Type::Double:
212 sipRes = PyFloat_FromDouble( v.toDouble() );
215 case QMetaType::Type::QString:
216 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
221 QVariant *newV =
new QVariant( v );
222 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
236 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
238 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
243 const QVariant v = sipCpp->attribute( a0 );
247 Py_INCREF( Py_None );
252 switch ( v.userType() )
254 case QMetaType::Type::Int:
255 sipRes = PyLong_FromLong( v.toInt() );
258 case QMetaType::Type::UInt:
259 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
262 case QMetaType::Type::Long:
263 case QMetaType::Type::LongLong:
264 sipRes = PyLong_FromLongLong( v.toLongLong() );
267 case QMetaType::Type::ULong:
268 case QMetaType::Type::ULongLong:
269 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
272 case QMetaType::Type::Bool:
273 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
276 case QMetaType::Type::Float:
277 case QMetaType::Type::Double:
278 sipRes = PyFloat_FromDouble( v.toDouble() );
281 case QMetaType::Type::QString:
282 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
287 QVariant *newV =
new QVariant( v );
288 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
296 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
298 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
299 if ( fieldIdx == -1 )
301 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
306 const QVariant v = sipCpp->attribute( fieldIdx );
310 Py_INCREF( Py_None );
315 switch ( v.userType() )
317 case QMetaType::Type::Int:
318 sipRes = PyLong_FromLong( v.toInt() );
321 case QMetaType::Type::UInt:
322 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
325 case QMetaType::Type::Long:
326 case QMetaType::Type::LongLong:
327 sipRes = PyLong_FromLongLong( v.toLongLong() );
330 case QMetaType::Type::ULong:
331 case QMetaType::Type::ULongLong:
332 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
335 case QMetaType::Type::Bool:
336 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
339 case QMetaType::Type::Float:
340 case QMetaType::Type::Double:
341 sipRes = PyFloat_FromDouble( v.toDouble() );
344 case QMetaType::Type::QString:
345 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
350 QVariant *newV =
new QVariant( v );
351 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
362 void __setitem__(
int key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
368 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
370 else if ( PyBool_Check( a1 ) )
372 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
374 else if ( PyLong_Check( a1 ) )
376 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
378 else if ( PyFloat_Check( a1 ) )
380 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
382 else if ( PyUnicode_Check( a1 ) )
384 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
386 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
389 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
396 rv = sipCpp->setAttribute( a0, *qvariant );
398 sipReleaseType( qvariant, sipType_QVariant, state );
407 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
412 void __setitem__(
const QString &key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
414 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
415 if ( fieldIdx == -1 )
417 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
424 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
426 else if ( PyBool_Check( a1 ) )
428 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
430 else if ( PyLong_Check( a1 ) )
432 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
434 else if ( PyFloat_Check( a1 ) )
436 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
438 else if ( PyUnicode_Check( a1 ) )
440 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
442 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
445 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
448 sipCpp->setAttribute( fieldIdx, *qvariant );
450 sipReleaseType( qvariant, sipType_QVariant, state );
461 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
462 sipCpp->deleteAttribute( a0 );
465 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
470 void __delitem__(
const QString &name )
SIP_HOLDGIL;
472 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
473 if ( fieldIdx == -1 )
475 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
479 sipCpp->deleteAttribute( fieldIdx );
484 sipRes =
qHash( *sipCpp );
561 QVariantMap attributeMap()
const;
577 const
int fieldSize = sipCpp->fields().size();
578 const
int attributeSize = sipCpp->attributeCount();
579 if ( fieldSize == 0 && attributeSize != 0 )
581 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Field definition has not been set for feature" ).toUtf8().constData() );
584 else if ( fieldSize != attributeSize )
586 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Feature attribute size (%1) does not match number of fields (%2)" ).arg( attributeSize ).arg( fieldSize ).toUtf8().constData() );
591 QVariantMap *v =
new QVariantMap( sipCpp->attributeMap() );
592 const sipTypeDef *qvariantmap_type = sipFindType(
"QMap<QString,QVariant>" );
593 sipRes = sipConvertFromNewType( v, qvariantmap_type, Py_None );
634 Q_INVOKABLE
bool setAttribute(
int field,
const QVariant &attr );
661 bool setAttribute(
int field, SIP_PYOBJECT attr
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
667 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
669 else if ( PyBool_Check( a1 ) )
671 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
673 else if ( PyLong_Check( a1 ) )
675 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
677 else if ( PyFloat_Check( a1 ) )
679 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
681 else if ( PyUnicode_Check( a1 ) )
683 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
685 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
688 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
695 rv = sipCpp->setAttribute( a0, *qvariant );
697 sipReleaseType( qvariant, sipType_QVariant, state );
706 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
738 void resizeAttributes(
int fieldCount )
SIP_HOLDGIL;
757 void deleteAttribute(
int field );
786 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
787 sipCpp->deleteAttribute( a0 );
790 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
871 void setGeometry( std::unique_ptr< QgsAbstractGeometry > geometry );
875 sipCpp->setGeometry( std::unique_ptr< QgsAbstractGeometry>( a0 ) );
916 Q_INVOKABLE
bool setAttribute(
const QString &name,
const QVariant &value );
945 void setAttribute(
const QString &name, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
947 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
948 if ( fieldIdx == -1 )
950 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
957 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
959 else if ( PyBool_Check( a1 ) )
961 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
963 else if ( PyLong_Check( a1 ) )
965 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
967 else if ( PyFloat_Check( a1 ) )
969 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
971 else if ( PyUnicode_Check( a1 ) )
973 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
975 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
978 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
981 sipCpp->setAttribute( fieldIdx, *qvariant );
983 sipReleaseType( qvariant, sipType_QVariant, state );
1004 bool deleteAttribute(
const QString &name );
1036 bool deleteAttribute(
const QString &name )
SIP_HOLDGIL;
1038 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1039 if ( fieldIdx == -1 )
1041 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1047 sipCpp->deleteAttribute( fieldIdx );
1064 Q_INVOKABLE QVariant attribute(
const QString &name )
const;
1092 Q_INVOKABLE SIP_PYOBJECT attribute(
const QString &name )
const SIP_HOLDGIL;
1094 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1095 if ( fieldIdx == -1 )
1097 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1102 QVariant *v =
new QVariant( sipCpp->attribute( fieldIdx ) );
1103 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1117 QVariant attribute(
int fieldIdx )
const;
1144 SIP_PYOBJECT attribute(
int fieldIdx )
const SIP_HOLDGIL;
1147 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1149 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1154 QVariant *v =
new QVariant( sipCpp->attribute( a0 ) );
1155 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1170 bool isUnsetValue(
int fieldIdx )
const;
1180 bool isUnsetValue(
int fieldIdx )
const SIP_HOLDGIL;
1183 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1185 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1190 sipRes = sipCpp->isUnsetValue( a0 );
1221 int fieldNameIndex( const QString &fieldName ) const
SIP_HOLDGIL;
1232 int approximateMemoryUsage() const;
1235 operator QVariant()
const
1237 return QVariant::fromValue( *
this );
1242 QExplicitlySharedDataPointer<QgsFeaturePrivate> d;