62#if ( SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01 )
63#define sipType_QVariant ( ( sipWrapperType * ) sipTypeAsPyTypeObject( sipType_QVariant ) )
80 PyObject *attrs = sipConvertFromType( &
attributes, sipType_QgsAttributes, Py_None );
81 sipRes = PyObject_GetIter( attrs );
93 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
95 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
100 const QVariant v = sipCpp->attribute( a0 );
103 Py_INCREF( Py_None );
109 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
110 PyObject *args = PyTuple_Pack( 1, vartype );
111 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
112 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
114 Py_DECREF( vartype );
118 switch ( v.userType() )
120 case QMetaType::Type::Int:
121 sipRes = PyLong_FromLong( v.toInt() );
124 case QMetaType::Type::UInt:
125 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
128 case QMetaType::Type::Long:
129 case QMetaType::Type::LongLong:
130 sipRes = PyLong_FromLongLong( v.toLongLong() );
133 case QMetaType::Type::ULong:
134 case QMetaType::Type::ULongLong:
135 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
138 case QMetaType::Type::Bool:
139 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
142 case QMetaType::Type::Float:
143 case QMetaType::Type::Double:
144 sipRes = PyFloat_FromDouble( v.toDouble() );
147 case QMetaType::Type::QString:
148 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
153 QVariant *newV =
new QVariant( v );
154 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
162 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
164 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
165 if ( fieldIdx == -1 )
167 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
172 const QVariant v = sipCpp->attribute( fieldIdx );
175 Py_INCREF( Py_None );
181 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
182 PyObject *args = PyTuple_Pack( 1, vartype );
183 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
184 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
186 Py_DECREF( vartype );
190 switch ( v.userType() )
192 case QMetaType::Type::Int:
193 sipRes = PyLong_FromLong( v.toInt() );
196 case QMetaType::Type::UInt:
197 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
200 case QMetaType::Type::Long:
201 case QMetaType::Type::LongLong:
202 sipRes = PyLong_FromLongLong( v.toLongLong() );
205 case QMetaType::Type::ULong:
206 case QMetaType::Type::ULongLong:
207 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
210 case QMetaType::Type::Bool:
211 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
214 case QMetaType::Type::Float:
215 case QMetaType::Type::Double:
216 sipRes = PyFloat_FromDouble( v.toDouble() );
219 case QMetaType::Type::QString:
220 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
225 QVariant *newV =
new QVariant( v );
226 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
242 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
244 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
249 const QVariant v = sipCpp->attribute( a0 );
253 Py_INCREF( Py_None );
258 switch ( v.userType() )
260 case QMetaType::Type::Int:
261 sipRes = PyLong_FromLong( v.toInt() );
264 case QMetaType::Type::UInt:
265 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
268 case QMetaType::Type::Long:
269 case QMetaType::Type::LongLong:
270 sipRes = PyLong_FromLongLong( v.toLongLong() );
273 case QMetaType::Type::ULong:
274 case QMetaType::Type::ULongLong:
275 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
278 case QMetaType::Type::Bool:
279 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
282 case QMetaType::Type::Float:
283 case QMetaType::Type::Double:
284 sipRes = PyFloat_FromDouble( v.toDouble() );
287 case QMetaType::Type::QString:
288 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
293 QVariant *newV =
new QVariant( v );
294 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
302 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
304 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
305 if ( fieldIdx == -1 )
307 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
312 const QVariant v = sipCpp->attribute( fieldIdx );
316 Py_INCREF( Py_None );
321 switch ( v.userType() )
323 case QMetaType::Type::Int:
324 sipRes = PyLong_FromLong( v.toInt() );
327 case QMetaType::Type::UInt:
328 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
331 case QMetaType::Type::Long:
332 case QMetaType::Type::LongLong:
333 sipRes = PyLong_FromLongLong( v.toLongLong() );
336 case QMetaType::Type::ULong:
337 case QMetaType::Type::ULongLong:
338 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
341 case QMetaType::Type::Bool:
342 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
345 case QMetaType::Type::Float:
346 case QMetaType::Type::Double:
347 sipRes = PyFloat_FromDouble( v.toDouble() );
350 case QMetaType::Type::QString:
351 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
356 QVariant *newV =
new QVariant( v );
357 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
370 void __setitem__(
int key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
376 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
378 else if ( PyBool_Check( a1 ) )
380 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
382 else if ( PyLong_Check( a1 ) )
384 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
386 else if ( PyFloat_Check( a1 ) )
388 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
390 else if ( PyUnicode_Check( a1 ) )
392 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
394 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
397 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
404 rv = sipCpp->setAttribute( a0, *qvariant );
406 sipReleaseType( qvariant, sipType_QVariant, state );
415 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
420 void __setitem__(
const QString &key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
422 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
423 if ( fieldIdx == -1 )
425 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
432 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
434 else if ( PyBool_Check( a1 ) )
436 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
438 else if ( PyLong_Check( a1 ) )
440 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
442 else if ( PyFloat_Check( a1 ) )
444 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
446 else if ( PyUnicode_Check( a1 ) )
448 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
450 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
453 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
456 sipCpp->setAttribute( fieldIdx, *qvariant );
458 sipReleaseType( qvariant, sipType_QVariant, state );
469 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
470 sipCpp->deleteAttribute( a0 );
473 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
478 void __delitem__(
const QString &name )
SIP_HOLDGIL;
480 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
481 if ( fieldIdx == -1 )
483 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
487 sipCpp->deleteAttribute( fieldIdx );
492 sipRes =
qHash( *sipCpp );
519 QgsFeature &operator=(
const QgsFeature &rhs )
SIP_HOLDGIL;
523 virtual ~QgsFeature();
570 QVariantMap attributeMap()
const;
587 const
int fieldSize = sipCpp->fields().size();
588 const
int attributeSize = sipCpp->attributeCount();
589 if ( fieldSize == 0 && attributeSize != 0 )
591 PyErr_SetString( PyExc_ValueError, u
"Field definition has not been set for feature"_s.toUtf8().constData() );
594 else if ( fieldSize != attributeSize )
596 PyErr_SetString( PyExc_ValueError, u
"Feature attribute size (%1) does not match number of fields (%2)"_s.arg( attributeSize ).arg( fieldSize ).toUtf8().constData() );
601 QVariantMap *v =
new QVariantMap( sipCpp->attributeMap() );
602 const sipTypeDef *qvariantmap_type = sipFindType(
"QMap<QString,QVariant>" );
603 sipRes = sipConvertFromNewType( v, qvariantmap_type, Py_None );
631 void setAttributes( const QgsAttributes &attrs )
SIP_HOLDGIL;
645 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 ) );
751 void resizeAttributes(
int fieldCount )
SIP_HOLDGIL;
770 void deleteAttribute(
int field );
800 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
801 sipCpp->deleteAttribute( a0 );
804 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
853 void setGeometry( const QgsGeometry &geometry )
SIP_HOLDGIL;
886 void setGeometry( std::unique_ptr< QgsAbstractGeometry > geometry );
891 sipCpp->setGeometry( std::unique_ptr< QgsAbstractGeometry>( a0 ) );
933 Q_INVOKABLE
bool setAttribute(
const QString &name,
const QVariant &value );
963 void setAttribute(
const QString &name, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
965 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
966 if ( fieldIdx == -1 )
968 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
975 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
977 else if ( PyBool_Check( a1 ) )
979 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
981 else if ( PyLong_Check( a1 ) )
983 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
985 else if ( PyFloat_Check( a1 ) )
987 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
989 else if ( PyUnicode_Check( a1 ) )
991 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
993 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
996 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
999 sipCpp->setAttribute( fieldIdx, *qvariant );
1001 sipReleaseType( qvariant, sipType_QVariant, state );
1023 bool deleteAttribute(
const QString &name );
1056 bool deleteAttribute(
const QString &name )
SIP_HOLDGIL;
1058 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1059 if ( fieldIdx == -1 )
1061 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1067 sipCpp->deleteAttribute( fieldIdx );
1085 Q_INVOKABLE QVariant attribute(
const QString &name )
const;
1114 Q_INVOKABLE SIP_PYOBJECT attribute(
const QString &name )
const SIP_HOLDGIL;
1116 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1117 if ( fieldIdx == -1 )
1119 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1124 QVariant *v =
new QVariant( sipCpp->attribute( fieldIdx ) );
1125 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1140 QVariant attribute(
int fieldIdx )
const;
1168 SIP_PYOBJECT attribute(
int fieldIdx )
const SIP_HOLDGIL;
1171 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1173 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1178 QVariant *v =
new QVariant( sipCpp->attribute( a0 ) );
1179 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1195 bool isUnsetValue(
int fieldIdx )
const;
1206 bool isUnsetValue(
int fieldIdx )
const SIP_HOLDGIL;
1209 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1211 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1216 sipRes = sipCpp->isUnsetValue( a0 );
1228 const QgsSymbol *embeddedSymbol() const
SIP_HOLDGIL;
1248 int fieldNameIndex( const QString &fieldName ) const
SIP_HOLDGIL;
1259 int approximateMemoryUsage() const;
1262 operator QVariant()
const
1264 return QVariant::fromValue( *
this );
1269 QExplicitlySharedDataPointer<QgsFeaturePrivate> d;