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 );
86 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
88 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
93 const QVariant v = sipCpp->attribute( a0 );
102 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
103 PyObject *args = PyTuple_Pack( 1, vartype );
104 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
105 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
107 Py_DECREF( vartype );
111 switch ( v.userType() )
113 case QMetaType::Type::Int:
114 sipRes = PyLong_FromLong( v.toInt() );
117 case QMetaType::Type::UInt:
118 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
121 case QMetaType::Type::Long:
122 case QMetaType::Type::LongLong:
123 sipRes = PyLong_FromLongLong( v.toLongLong() );
126 case QMetaType::Type::ULong:
127 case QMetaType::Type::ULongLong:
128 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
131 case QMetaType::Type::Bool:
132 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
135 case QMetaType::Type::Float:
136 case QMetaType::Type::Double:
137 sipRes = PyFloat_FromDouble( v.toDouble() );
140 case QMetaType::Type::QString:
141 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
146 QVariant *newV =
new QVariant( v );
147 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
155 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
157 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
158 if ( fieldIdx == -1 )
160 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
165 const QVariant v = sipCpp->attribute( fieldIdx );
168 Py_INCREF( Py_None );
174 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
175 PyObject *args = PyTuple_Pack( 1, vartype );
176 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
177 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
179 Py_DECREF( vartype );
183 switch ( v.userType() )
185 case QMetaType::Type::Int:
186 sipRes = PyLong_FromLong( v.toInt() );
189 case QMetaType::Type::UInt:
190 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
193 case QMetaType::Type::Long:
194 case QMetaType::Type::LongLong:
195 sipRes = PyLong_FromLongLong( v.toLongLong() );
198 case QMetaType::Type::ULong:
199 case QMetaType::Type::ULongLong:
200 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
203 case QMetaType::Type::Bool:
204 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
207 case QMetaType::Type::Float:
208 case QMetaType::Type::Double:
209 sipRes = PyFloat_FromDouble( v.toDouble() );
212 case QMetaType::Type::QString:
213 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
218 QVariant *newV =
new QVariant( v );
219 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
233 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
235 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
240 const QVariant v = sipCpp->attribute( a0 );
244 Py_INCREF( Py_None );
249 switch ( v.userType() )
251 case QMetaType::Type::Int:
252 sipRes = PyLong_FromLong( v.toInt() );
255 case QMetaType::Type::UInt:
256 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
259 case QMetaType::Type::Long:
260 case QMetaType::Type::LongLong:
261 sipRes = PyLong_FromLongLong( v.toLongLong() );
264 case QMetaType::Type::ULong:
265 case QMetaType::Type::ULongLong:
266 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
269 case QMetaType::Type::Bool:
270 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
273 case QMetaType::Type::Float:
274 case QMetaType::Type::Double:
275 sipRes = PyFloat_FromDouble( v.toDouble() );
278 case QMetaType::Type::QString:
279 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
284 QVariant *newV =
new QVariant( v );
285 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
293 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
295 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
296 if ( fieldIdx == -1 )
298 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
303 const QVariant v = sipCpp->attribute( fieldIdx );
307 Py_INCREF( Py_None );
312 switch ( v.userType() )
314 case QMetaType::Type::Int:
315 sipRes = PyLong_FromLong( v.toInt() );
318 case QMetaType::Type::UInt:
319 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
322 case QMetaType::Type::Long:
323 case QMetaType::Type::LongLong:
324 sipRes = PyLong_FromLongLong( v.toLongLong() );
327 case QMetaType::Type::ULong:
328 case QMetaType::Type::ULongLong:
329 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
332 case QMetaType::Type::Bool:
333 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
336 case QMetaType::Type::Float:
337 case QMetaType::Type::Double:
338 sipRes = PyFloat_FromDouble( v.toDouble() );
341 case QMetaType::Type::QString:
342 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
347 QVariant *newV =
new QVariant( v );
348 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
365 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
367 else if ( PyBool_Check( a1 ) )
369 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
371 else if ( PyLong_Check( a1 ) )
373 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
375 else if ( PyFloat_Check( a1 ) )
377 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
379 else if ( PyUnicode_Check( a1 ) )
381 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
383 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
386 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
393 rv = sipCpp->setAttribute( a0, *qvariant );
395 sipReleaseType( qvariant, sipType_QVariant, state );
404 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
409 void __setitem__(
const QString &key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float,
str, QVariant]] ) )
SIP_HOLDGIL;
411 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
412 if ( fieldIdx == -1 )
414 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
421 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
423 else if ( PyBool_Check( a1 ) )
425 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
427 else if ( PyLong_Check( a1 ) )
429 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
431 else if ( PyFloat_Check( a1 ) )
433 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
435 else if ( PyUnicode_Check( a1 ) )
437 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
439 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
442 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
445 sipCpp->setAttribute( fieldIdx, *qvariant );
447 sipReleaseType( qvariant, sipType_QVariant, state );
458 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
459 sipCpp->deleteAttribute( a0 );
462 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
467 void __delitem__(
const QString &name )
SIP_HOLDGIL;
469 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
470 if ( fieldIdx == -1 )
472 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
476 sipCpp->deleteAttribute( fieldIdx );
481 sipRes =
qHash( *sipCpp );
573 QVariantMap attributeMap()
const;
589 const
int fieldSize = sipCpp->fields().size();
590 const
int attributeSize = sipCpp->attributeCount();
591 if ( fieldSize == 0 && attributeSize != 0 )
593 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Field definition has not been set for feature" ).toUtf8().constData() );
596 else if ( fieldSize != attributeSize )
598 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Feature attribute size (%1) does not match number of fields (%2)" ).arg( attributeSize ).arg( fieldSize ).toUtf8().constData() );
603 QVariantMap *v =
new QVariantMap( sipCpp->attributeMap() );
604 const sipTypeDef *qvariantmap_type = sipFindType(
"QMap<QString,QVariant>" );
605 sipRes = sipConvertFromNewType( v, qvariantmap_type, Py_None );
646 Q_INVOKABLE
bool setAttribute(
int field,
const QVariant &attr );
673 bool setAttribute(
int field, SIP_PYOBJECT attr
SIP_TYPEHINT( Optional[Union[
bool,
int,
float,
str, QVariant]] ) )
SIP_HOLDGIL;
679 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
681 else if ( PyBool_Check( a1 ) )
683 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
685 else if ( PyLong_Check( a1 ) )
687 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
689 else if ( PyFloat_Check( a1 ) )
691 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
693 else if ( PyUnicode_Check( a1 ) )
695 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
697 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
700 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
707 rv = sipCpp->setAttribute( a0, *qvariant );
709 sipReleaseType( qvariant, sipType_QVariant, state );
718 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
750 void resizeAttributes(
int fieldCount )
SIP_HOLDGIL;
769 void deleteAttribute(
int field );
798 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
799 sipCpp->deleteAttribute( a0 );
802 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
883 void setGeometry( std::unique_ptr< QgsAbstractGeometry > geometry );
887 sipCpp->setGeometry( std::unique_ptr< QgsAbstractGeometry>( a0 ) );
928 Q_INVOKABLE
bool setAttribute(
const QString &name,
const QVariant &value );
957 void setAttribute(
const QString &name, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float,
str, QVariant]] ) )
SIP_HOLDGIL;
959 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
960 if ( fieldIdx == -1 )
962 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
969 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
971 else if ( PyBool_Check( a1 ) )
973 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
975 else if ( PyLong_Check( a1 ) )
977 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
979 else if ( PyFloat_Check( a1 ) )
981 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
983 else if ( PyUnicode_Check( a1 ) )
985 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
987 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
990 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
993 sipCpp->setAttribute( fieldIdx, *qvariant );
995 sipReleaseType( qvariant, sipType_QVariant, state );
1016 bool deleteAttribute(
const QString &name );
1048 bool deleteAttribute(
const QString &name )
SIP_HOLDGIL;
1050 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1051 if ( fieldIdx == -1 )
1053 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1059 sipCpp->deleteAttribute( fieldIdx );
1076 Q_INVOKABLE QVariant attribute(
const QString &name )
const;
1104 Q_INVOKABLE SIP_PYOBJECT attribute(
const QString &name )
const SIP_HOLDGIL;
1106 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1107 if ( fieldIdx == -1 )
1109 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1114 QVariant *v =
new QVariant( sipCpp->attribute( fieldIdx ) );
1115 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1129 QVariant attribute(
int fieldIdx )
const;
1156 SIP_PYOBJECT attribute(
int fieldIdx )
const SIP_HOLDGIL;
1159 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1161 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1166 QVariant *v =
new QVariant( sipCpp->attribute( a0 ) );
1167 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1182 bool isUnsetValue(
int fieldIdx )
const;
1192 bool isUnsetValue(
int fieldIdx )
const SIP_HOLDGIL;
1195 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1197 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1202 sipRes = sipCpp->isUnsetValue( a0 );
1233 int fieldNameIndex( const QString &fieldName ) const
SIP_HOLDGIL;
1244 int approximateMemoryUsage() const;
1247 operator QVariant()
const
1249 return QVariant::fromValue( *
this );
1254 QExplicitlySharedDataPointer<QgsFeaturePrivate> d;