75 PyObject *attrs = sipConvertFromType( &
attributes, sipType_QgsAttributes, Py_None );
76 sipRes = PyObject_GetIter( attrs );
88 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
90 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
95 const QVariant v = sipCpp->attribute( a0 );
104 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
105 PyObject *args = PyTuple_Pack( 1, vartype );
106 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
107 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
109 Py_DECREF( vartype );
113 switch ( v.userType() )
115 case QMetaType::Type::Int:
116 sipRes = PyLong_FromLong( v.toInt() );
119 case QMetaType::Type::UInt:
120 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
123 case QMetaType::Type::Long:
124 case QMetaType::Type::LongLong:
125 sipRes = PyLong_FromLongLong( v.toLongLong() );
128 case QMetaType::Type::ULong:
129 case QMetaType::Type::ULongLong:
130 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
133 case QMetaType::Type::Bool:
134 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
137 case QMetaType::Type::Float:
138 case QMetaType::Type::Double:
139 sipRes = PyFloat_FromDouble( v.toDouble() );
142 case QMetaType::Type::QString:
143 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
148 QVariant *newV =
new QVariant( v );
149 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
157 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
159 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
160 if ( fieldIdx == -1 )
162 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
167 const QVariant v = sipCpp->attribute( fieldIdx );
170 Py_INCREF( Py_None );
176 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
177 PyObject *args = PyTuple_Pack( 1, vartype );
178 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
179 sipRes = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
181 Py_DECREF( vartype );
185 switch ( v.userType() )
187 case QMetaType::Type::Int:
188 sipRes = PyLong_FromLong( v.toInt() );
191 case QMetaType::Type::UInt:
192 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
195 case QMetaType::Type::Long:
196 case QMetaType::Type::LongLong:
197 sipRes = PyLong_FromLongLong( v.toLongLong() );
200 case QMetaType::Type::ULong:
201 case QMetaType::Type::ULongLong:
202 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
205 case QMetaType::Type::Bool:
206 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
209 case QMetaType::Type::Float:
210 case QMetaType::Type::Double:
211 sipRes = PyFloat_FromDouble( v.toDouble() );
214 case QMetaType::Type::QString:
215 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
220 QVariant *newV =
new QVariant( v );
221 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
237 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
239 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
244 const QVariant v = sipCpp->attribute( a0 );
248 Py_INCREF( Py_None );
253 switch ( v.userType() )
255 case QMetaType::Type::Int:
256 sipRes = PyLong_FromLong( v.toInt() );
259 case QMetaType::Type::UInt:
260 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
263 case QMetaType::Type::Long:
264 case QMetaType::Type::LongLong:
265 sipRes = PyLong_FromLongLong( v.toLongLong() );
268 case QMetaType::Type::ULong:
269 case QMetaType::Type::ULongLong:
270 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
273 case QMetaType::Type::Bool:
274 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
277 case QMetaType::Type::Float:
278 case QMetaType::Type::Double:
279 sipRes = PyFloat_FromDouble( v.toDouble() );
282 case QMetaType::Type::QString:
283 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
288 QVariant *newV =
new QVariant( v );
289 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
297 SIP_PYOBJECT __getitem__(
const QString &name )
SIP_HOLDGIL;
299 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
300 if ( fieldIdx == -1 )
302 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
307 const QVariant v = sipCpp->attribute( fieldIdx );
311 Py_INCREF( Py_None );
316 switch ( v.userType() )
318 case QMetaType::Type::Int:
319 sipRes = PyLong_FromLong( v.toInt() );
322 case QMetaType::Type::UInt:
323 sipRes = PyLong_FromUnsignedLong( v.toUInt() );
326 case QMetaType::Type::Long:
327 case QMetaType::Type::LongLong:
328 sipRes = PyLong_FromLongLong( v.toLongLong() );
331 case QMetaType::Type::ULong:
332 case QMetaType::Type::ULongLong:
333 sipRes = PyLong_FromUnsignedLongLong( v.toULongLong() );
336 case QMetaType::Type::Bool:
337 sipRes = PyBool_FromLong( v.toBool() ? 1 : 0 );
340 case QMetaType::Type::Float:
341 case QMetaType::Type::Double:
342 sipRes = PyFloat_FromDouble( v.toDouble() );
345 case QMetaType::Type::QString:
346 sipRes = PyUnicode_FromString( v.toString().toUtf8().constData() );
351 QVariant *newV =
new QVariant( v );
352 sipRes = sipConvertFromNewType( newV, sipType_QVariant, Py_None );
365 void __setitem__(
int key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
371 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
373 else if ( PyBool_Check( a1 ) )
375 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
377 else if ( PyLong_Check( a1 ) )
379 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
381 else if ( PyFloat_Check( a1 ) )
383 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
385 else if ( PyUnicode_Check( a1 ) )
387 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
389 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
392 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
399 rv = sipCpp->setAttribute( a0, *qvariant );
401 sipReleaseType( qvariant, sipType_QVariant, state );
410 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
415 void __setitem__(
const QString &key, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
417 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
418 if ( fieldIdx == -1 )
420 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
427 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
429 else if ( PyBool_Check( a1 ) )
431 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
433 else if ( PyLong_Check( a1 ) )
435 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
437 else if ( PyFloat_Check( a1 ) )
439 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
441 else if ( PyUnicode_Check( a1 ) )
443 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
445 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
448 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
451 sipCpp->setAttribute( fieldIdx, *qvariant );
453 sipReleaseType( qvariant, sipType_QVariant, state );
464 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
465 sipCpp->deleteAttribute( a0 );
468 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
473 void __delitem__(
const QString &name )
SIP_HOLDGIL;
475 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
476 if ( fieldIdx == -1 )
478 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
482 sipCpp->deleteAttribute( fieldIdx );
487 sipRes =
qHash( *sipCpp );
514 QgsFeature &operator=(
const QgsFeature &rhs )
SIP_HOLDGIL;
518 virtual ~QgsFeature();
565 QVariantMap attributeMap()
const;
582 const
int fieldSize = sipCpp->fields().size();
583 const
int attributeSize = sipCpp->attributeCount();
584 if ( fieldSize == 0 && attributeSize != 0 )
586 PyErr_SetString( PyExc_ValueError, u
"Field definition has not been set for feature"_s.toUtf8().constData() );
589 else if ( fieldSize != attributeSize )
591 PyErr_SetString( PyExc_ValueError, u
"Feature attribute size (%1) does not match number of fields (%2)"_s.arg( attributeSize ).arg( fieldSize ).toUtf8().constData() );
596 QVariantMap *v =
new QVariantMap( sipCpp->attributeMap() );
597 const sipTypeDef *qvariantmap_type = sipFindType(
"QMap<QString,QVariant>" );
598 sipRes = sipConvertFromNewType( v, qvariantmap_type, Py_None );
626 void setAttributes( const QgsAttributes &attrs )
SIP_HOLDGIL;
640 Q_INVOKABLE
bool setAttribute(
int field,
const QVariant &attr );
668 bool setAttribute(
int field, SIP_PYOBJECT attr
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
674 rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) );
676 else if ( PyBool_Check( a1 ) )
678 rv = sipCpp->setAttribute( a0, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
680 else if ( PyLong_Check( a1 ) )
682 rv = sipCpp->setAttribute( a0, QVariant( PyLong_AsLongLong( a1 ) ) );
684 else if ( PyFloat_Check( a1 ) )
686 rv = sipCpp->setAttribute( a0, QVariant( PyFloat_AsDouble( a1 ) ) );
688 else if ( PyUnicode_Check( a1 ) )
690 rv = sipCpp->setAttribute( a0, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
692 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
695 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
702 rv = sipCpp->setAttribute( a0, *qvariant );
704 sipReleaseType( qvariant, sipType_QVariant, state );
713 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
746 void resizeAttributes(
int fieldCount )
SIP_HOLDGIL;
765 void deleteAttribute(
int field );
795 if ( a0 >= 0 && a0 < sipCpp->attributeCount() )
796 sipCpp->deleteAttribute( a0 );
799 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
848 void setGeometry( const QgsGeometry &geometry )
SIP_HOLDGIL;
881 void setGeometry( std::unique_ptr< QgsAbstractGeometry > geometry );
886 sipCpp->setGeometry( std::unique_ptr< QgsAbstractGeometry>( a0 ) );
928 Q_INVOKABLE
bool setAttribute(
const QString &name,
const QVariant &value );
958 void setAttribute(
const QString &name, SIP_PYOBJECT value
SIP_TYPEHINT( Optional[Union[
bool,
int,
float, str, QVariant]] ) )
SIP_HOLDGIL;
960 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
961 if ( fieldIdx == -1 )
963 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
970 sipCpp->setAttribute( fieldIdx, QVariant( QVariant::Int ) );
972 else if ( PyBool_Check( a1 ) )
974 sipCpp->setAttribute( fieldIdx, QVariant( PyObject_IsTrue( a1 ) == 1 ) );
976 else if ( PyLong_Check( a1 ) )
978 sipCpp->setAttribute( fieldIdx, QVariant( PyLong_AsLongLong( a1 ) ) );
980 else if ( PyFloat_Check( a1 ) )
982 sipCpp->setAttribute( fieldIdx, QVariant( PyFloat_AsDouble( a1 ) ) );
984 else if ( PyUnicode_Check( a1 ) )
986 sipCpp->setAttribute( fieldIdx, QVariant( QString::fromUtf8( PyUnicode_AsUTF8( a1 ) ) ) );
988 else if ( sipCanConvertToType( a1, sipType_QVariant, SIP_NOT_NONE ) )
991 QVariant *qvariant =
reinterpret_cast<QVariant *
>( sipConvertToType( a1, sipType_QVariant, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
994 sipCpp->setAttribute( fieldIdx, *qvariant );
996 sipReleaseType( qvariant, sipType_QVariant, state );
1018 bool deleteAttribute(
const QString &name );
1051 bool deleteAttribute(
const QString &name )
SIP_HOLDGIL;
1053 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1054 if ( fieldIdx == -1 )
1056 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1062 sipCpp->deleteAttribute( fieldIdx );
1080 Q_INVOKABLE QVariant attribute(
const QString &name )
const;
1109 Q_INVOKABLE SIP_PYOBJECT attribute(
const QString &name )
const SIP_HOLDGIL;
1111 int fieldIdx = sipCpp->fieldNameIndex( *a0 );
1112 if ( fieldIdx == -1 )
1114 PyErr_SetString( PyExc_KeyError, a0->toLatin1() );
1119 QVariant *v =
new QVariant( sipCpp->attribute( fieldIdx ) );
1120 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1135 QVariant attribute(
int fieldIdx )
const;
1163 SIP_PYOBJECT attribute(
int fieldIdx )
const SIP_HOLDGIL;
1166 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1168 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1173 QVariant *v =
new QVariant( sipCpp->attribute( a0 ) );
1174 sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
1190 bool isUnsetValue(
int fieldIdx )
const;
1201 bool isUnsetValue(
int fieldIdx )
const SIP_HOLDGIL;
1204 if ( a0 < 0 || a0 >= sipCpp->attributeCount() )
1206 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
1211 sipRes = sipCpp->isUnsetValue( a0 );
1223 const QgsSymbol *embeddedSymbol() const
SIP_HOLDGIL;
1243 int fieldNameIndex( const QString &fieldName ) const
SIP_HOLDGIL;
1254 int approximateMemoryUsage() const;
1257 operator QVariant()
const
1259 return QVariant::fromValue( *
this );
1264 QExplicitlySharedDataPointer<QgsFeaturePrivate> d;