62#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01)
63#define sipType_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
79 PyObject *attrs = sipConvertFromType( &
attributes, sipType_QgsAttributes, Py_None );
80 sipRes = PyObject_GetIter( attrs );
91 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
93 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
98 const QVariant v = sipCpp->attribute( a0 );
101 Py_INCREF( Py_None );
107 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
108 PyObject *args = PyTuple_Pack( 1, vartype );
109 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
110 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
112 Py_DECREF( vartype );
116 switch ( v.userType() )
118 case QMetaType::Type::Int:
119 sipRes = PyLong_FromLong( v.toInt() );
122 case QMetaType::Type::UInt:
123 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
126 case QMetaType::Type::Long:
127 case QMetaType::Type::LongLong:
128 sipRes = PyLong_FromLongLong( v.toLongLong() );
131 case QMetaType::Type::ULong:
132 case QMetaType::Type::ULongLong:
133 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
136 case QMetaType::Type::Bool:
137 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
140 case QMetaType::Type::Float:
141 case QMetaType::Type::Double:
142 sipRes = PyFloat_FromDouble( v.toDouble() );
145 case QMetaType::Type::QString:
146 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
151 QVariant *newV =
new QVariant( v );
152 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
160 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
162 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
163 if ( fieldIdx == -1 )
165 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
170 const QVariant v = sipCpp->attribute( fieldIdx );
173 Py_INCREF( Py_None );
179 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
180 PyObject *args = PyTuple_Pack( 1, vartype );
181 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
182 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
184 Py_DECREF( vartype );
188 switch ( v.userType() )
190 case QMetaType::Type::Int:
191 sipRes = PyLong_FromLong( v.toInt() );
194 case QMetaType::Type::UInt:
195 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
198 case QMetaType::Type::Long:
199 case QMetaType::Type::LongLong:
200 sipRes = PyLong_FromLongLong( v.toLongLong() );
203 case QMetaType::Type::ULong:
204 case QMetaType::Type::ULongLong:
205 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
208 case QMetaType::Type::Bool:
209 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
212 case QMetaType::Type::Float:
213 case QMetaType::Type::Double:
214 sipRes = PyFloat_FromDouble( v.toDouble() );
217 case QMetaType::Type::QString:
218 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
223 QVariant *newV =
new QVariant( v );
224 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
238 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
240 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
245 const QVariant v = sipCpp->attribute( a0 );
249 Py_INCREF( Py_None );
254 switch ( v.userType() )
256 case QMetaType::Type::Int:
257 sipRes = PyLong_FromLong( v.toInt() );
260 case QMetaType::Type::UInt:
261 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
264 case QMetaType::Type::Long:
265 case QMetaType::Type::LongLong:
266 sipRes = PyLong_FromLongLong( v.toLongLong() );
269 case QMetaType::Type::ULong:
270 case QMetaType::Type::ULongLong:
271 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
274 case QMetaType::Type::Bool:
275 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
278 case QMetaType::Type::Float:
279 case QMetaType::Type::Double:
280 sipRes = PyFloat_FromDouble( v.toDouble() );
283 case QMetaType::Type::QString:
284 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
289 QVariant *newV =
new QVariant( v );
290 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
298 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
300 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
301 if ( fieldIdx == -1 )
303 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
308 const QVariant v = sipCpp->attribute( fieldIdx );
312 Py_INCREF( Py_None );
317 switch ( v.userType() )
319 case QMetaType::Type::Int:
320 sipRes = PyLong_FromLong( v.toInt() );
323 case QMetaType::Type::UInt:
324 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
327 case QMetaType::Type::Long:
328 case QMetaType::Type::LongLong:
329 sipRes = PyLong_FromLongLong( v.toLongLong() );
332 case QMetaType::Type::ULong:
333 case QMetaType::Type::ULongLong:
334 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
337 case QMetaType::Type::Bool:
338 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
341 case QMetaType::Type::Float:
342 case QMetaType::Type::Double:
343 sipRes = PyFloat_FromDouble( v.toDouble() );
346 case QMetaType::Type::QString:
347 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
352 QVariant *newV =
new QVariant( v );
353 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
364 void __setitem__(
int key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
370 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
372 else if ( PyBool_Check( a1 ) )
374 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
376 else if ( PyLong_Check( a1 ) )
378 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
380 else if ( PyFloat_Check( a1 ) )
382 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
384 else if ( PyUnicode_Check( a1 ) )
386 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
388 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
391 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
398 rv = sipCpp->setAttribute( a0, *qvariant );
400 sipReleaseType( qvariant, sipType_QVariant, state );
409 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
414 void __setitem__(
const QString &key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
416 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
417 if ( fieldIdx == -1 )
419 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
426 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
428 else if ( PyBool_Check( a1 ) )
430 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
432 else if ( PyLong_Check( a1 ) )
434 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
436 else if ( PyFloat_Check( a1 ) )
438 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
440 else if ( PyUnicode_Check( a1 ) )
442 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
444 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
447 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
450 sipCpp->setAttribute( fieldIdx, *qvariant );
452 sipReleaseType( qvariant, sipType_QVariant, state );
463 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
464 sipCpp->deleteAttribute( a0 );
467 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
472 void __delitem__(
const QString &name )
SIP_HOLDGIL;
474 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
475 if ( fieldIdx == -1 )
477 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
481 sipCpp->deleteAttribute( fieldIdx );
486 sipRes =
qHash( *sipCpp );
512 QgsFeature &operator=(
const QgsFeature &rhs )
SIP_HOLDGIL;
516 virtual ~QgsFeature();
563 QVariantMap attributeMap()
const;
579 const
int fieldSize = sipCpp->fields().size();
580 const
int attributeSize = sipCpp->attributeCount();
581 if ( fieldSize == 0 && attributeSize != 0 )
583 PyErr_SetString( PyExc_ValueError, u
"Field definition has not been set for feature"_s.toUtf8().constData() );
586 else if ( fieldSize != attributeSize )
588 PyErr_SetString( PyExc_ValueError, u
"Feature attribute size (%1) does not match number of fields (%2)"_s.arg( attributeSize ).arg( fieldSize ).toUtf8().constData() );
593 QVariantMap *v =
new QVariantMap( sipCpp->attributeMap() );
594 const sipTypeDef *qvariantmap_type = sipFindType(
"QMap<QString,QVariant>" );
595 sipRes = sipConvertFromNewType( v, qvariantmap_type, Py_None );
622 void setAttributes( const QgsAttributes &attrs )
SIP_HOLDGIL;
636 Q_INVOKABLE
bool setAttribute(
int field,
const QVariant &attr );
663 bool setAttribute(
int field, SIP_PYOBJECT attr
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
669 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
671 else if ( PyBool_Check( a1 ) )
673 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
675 else if ( PyLong_Check( a1 ) )
677 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
679 else if ( PyFloat_Check( a1 ) )
681 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
683 else if ( PyUnicode_Check( a1 ) )
685 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
687 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
690 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
697 rv = sipCpp->setAttribute( a0, *qvariant );
699 sipReleaseType( qvariant, sipType_QVariant, state );
708 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
740 void resizeAttributes(
int fieldCount )
SIP_HOLDGIL;
759 void deleteAttribute(
int field );
788 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
789 sipCpp->deleteAttribute( a0 );
792 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
840 void setGeometry( const QgsGeometry &geometry )
SIP_HOLDGIL;
873 void setGeometry( std::unique_ptr< QgsAbstractGeometry > geometry );
877 sipCpp->setGeometry( std::unique_ptr< QgsAbstractGeometry>( a0 ) );
918 Q_INVOKABLE
bool setAttribute(
const QString &name,
const QVariant &value );
947 void setAttribute(
const QString &name, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
949 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
950 if ( fieldIdx == -1 )
952 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
959 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
961 else if ( PyBool_Check( a1 ) )
963 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
965 else if ( PyLong_Check( a1 ) )
967 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
969 else if ( PyFloat_Check( a1 ) )
971 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
973 else if ( PyUnicode_Check( a1 ) )
975 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
977 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
980 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
983 sipCpp->setAttribute( fieldIdx, *qvariant );
985 sipReleaseType( qvariant, sipType_QVariant, state );
1006 bool deleteAttribute(
const QString &name );
1038 bool deleteAttribute(
const QString &name )
SIP_HOLDGIL;
1040 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1041 if ( fieldIdx == -1 )
1043 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1049 sipCpp->deleteAttribute( fieldIdx );
1066 Q_INVOKABLE QVariant attribute(
const QString &name )
const;
1094 Q_INVOKABLE SIP_PYOBJECT attribute(
const QString &name )
const SIP_HOLDGIL;
1096 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1097 if ( fieldIdx == -1 )
1099 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1104 QVariant *v =
new QVariant( sipCpp->attribute( fieldIdx ) );
1105 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1119 QVariant attribute(
int fieldIdx )
const;
1146 SIP_PYOBJECT attribute(
int fieldIdx )
const SIP_HOLDGIL;
1149 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1151 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1156 QVariant *v =
new QVariant( sipCpp->attribute( a0 ) );
1157 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1172 bool isUnsetValue(
int fieldIdx )
const;
1182 bool isUnsetValue(
int fieldIdx )
const SIP_HOLDGIL;
1185 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1187 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1192 sipRes = sipCpp->isUnsetValue( a0 );
1203 const QgsSymbol *embeddedSymbol() const
SIP_HOLDGIL;
1223 int fieldNameIndex( const QString &fieldName ) const
SIP_HOLDGIL;
1234 int approximateMemoryUsage() const;
1237 operator QVariant()
const
1239 return QVariant::fromValue( *
this );
1244 QExplicitlySharedDataPointer<QgsFeaturePrivate> d;