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 );
359 void __setitem__(
int key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
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 );
558 QVariantMap attributeMap()
const;
574 const
int fieldSize = sipCpp->fields().size();
575 const
int attributeSize = sipCpp->attributeCount();
576 if ( fieldSize == 0 && attributeSize != 0 )
578 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Field definition has not been set for feature" ).toUtf8().constData() );
581 else if ( fieldSize != attributeSize )
583 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Feature attribute size (%1) does not match number of fields (%2)" ).arg( attributeSize ).arg( fieldSize ).toUtf8().constData() );
588 QVariantMap *v =
new QVariantMap( sipCpp->attributeMap() );
589 const sipTypeDef *qvariantmap_type = sipFindType(
"QMap<QString,QVariant>" );
590 sipRes = sipConvertFromNewType( v, qvariantmap_type, Py_None );
631 Q_INVOKABLE
bool setAttribute(
int field,
const QVariant &attr );
658 bool setAttribute(
int field, SIP_PYOBJECT attr
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
664 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
666 else if ( PyBool_Check( a1 ) )
668 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
670 else if ( PyLong_Check( a1 ) )
672 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
674 else if ( PyFloat_Check( a1 ) )
676 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
678 else if ( PyUnicode_Check( a1 ) )
680 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
682 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
685 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
692 rv = sipCpp->setAttribute( a0, *qvariant );
694 sipReleaseType( qvariant, sipType_QVariant, state );
703 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
735 void resizeAttributes(
int fieldCount )
SIP_HOLDGIL;
754 void deleteAttribute(
int field );
783 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
784 sipCpp->deleteAttribute( a0 );
787 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
868 void setGeometry( std::unique_ptr< QgsAbstractGeometry > geometry );
872 sipCpp->setGeometry( std::unique_ptr< QgsAbstractGeometry>( a0 ) );
913 Q_INVOKABLE
bool setAttribute(
const QString &name,
const QVariant &value );
942 void setAttribute(
const QString &name, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
944 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
945 if ( fieldIdx == -1 )
947 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
954 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
956 else if ( PyBool_Check( a1 ) )
958 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
960 else if ( PyLong_Check( a1 ) )
962 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
964 else if ( PyFloat_Check( a1 ) )
966 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
968 else if ( PyUnicode_Check( a1 ) )
970 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
972 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
975 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
978 sipCpp->setAttribute( fieldIdx, *qvariant );
980 sipReleaseType( qvariant, sipType_QVariant, state );
1001 bool deleteAttribute(
const QString &name );
1033 bool deleteAttribute(
const QString &name )
SIP_HOLDGIL;
1035 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1036 if ( fieldIdx == -1 )
1038 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1044 sipCpp->deleteAttribute( fieldIdx );
1061 Q_INVOKABLE QVariant attribute(
const QString &name )
const;
1089 Q_INVOKABLE SIP_PYOBJECT attribute(
const QString &name )
const SIP_HOLDGIL;
1091 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1092 if ( fieldIdx == -1 )
1094 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1099 QVariant *v =
new QVariant( sipCpp->attribute( fieldIdx ) );
1100 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1114 QVariant attribute(
int fieldIdx )
const;
1141 SIP_PYOBJECT attribute(
int fieldIdx )
const SIP_HOLDGIL;
1144 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1146 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1151 QVariant *v =
new QVariant( sipCpp->attribute( a0 ) );
1152 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1167 bool isUnsetValue(
int fieldIdx )
const;
1177 bool isUnsetValue(
int fieldIdx )
const SIP_HOLDGIL;
1180 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1182 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1187 sipRes = sipCpp->isUnsetValue( a0 );
1218 int fieldNameIndex( const QString &fieldName ) const
SIP_HOLDGIL;
1229 int approximateMemoryUsage() const;
1232 operator QVariant()
const
1234 return QVariant::fromValue( *
this );
1239 QExplicitlySharedDataPointer<QgsFeaturePrivate> d;