18#ifndef QGSATTRIBUTES_H
19#define QGSATTRIBUTES_H
27#include <QExplicitlySharedDataPointer>
37class QgsFeaturePrivate;
46typedef QMap<int, QgsField> QgsFieldMap;
68 : QVector<QVariant>( size )
77 : QVector<QVariant>( size, v )
85 : QVector<QVariant>( v )
99 if ( size() != v.size() )
101 const QVariant *b = constData();
102 const QVariant *i = b + size();
103 const QVariant *j = v.constData() + size();
128 if ( index < 0 || index >= size() )
131 return at( index ).userType() == qMetaTypeId<QgsUnsetAttributeValue>();
152 % ConvertFromTypeCode
156 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
160 for (
int i = 0; i < sipCpp->size(); ++i )
162 const QVariant v = sipCpp->at( i );
163 PyObject *tobj = NULL;
166 Py_INCREF( Py_None );
172 PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
173 PyObject *args = PyTuple_Pack( 1, vartype );
174 PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
175 tobj = PyObject_Call( ( PyObject * )typeObj, args,
nullptr );
177 Py_DECREF( vartype );
181 switch ( v.userType() )
183 case QMetaType::Type::Int:
184 tobj = PyLong_FromLong( v.toInt() );
187 case QMetaType::Type::UInt:
188 tobj = PyLong_FromUnsignedLong( v.toUInt() );
191 case QMetaType::Type::Long:
192 case QMetaType::Type::LongLong:
193 tobj = PyLong_FromLongLong( v.toLongLong() );
196 case QMetaType::Type::ULong:
197 case QMetaType::Type::ULongLong:
198 tobj = PyLong_FromUnsignedLongLong( v.toULongLong() );
201 case QMetaType::Type::Bool:
202 tobj = PyBool_FromLong( v.toBool() ? 1 : 0 );
205 case QMetaType::Type::Float:
206 case QMetaType::Type::Double:
207 tobj = PyFloat_FromDouble( v.toDouble() );
210 case QMetaType::Type::QString:
211 tobj = PyUnicode_FromString( v.toString().toUtf8().constData() );
216 QVariant *newV =
new QVariant( v );
217 tobj = sipConvertFromNewType( newV, sipType_QVariant, sipTransferObj );
228 PyList_SET_ITEM( l, i, tobj );
236 if ( sipIsErr == NULL )
238 if ( !PyList_Check( sipPy ) )
241 for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
242 if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QVariant, SIP_NOT_NONE ) )
248 SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
252 const QVariant nullVariant( QVariant::Int );
254 QVariant *outData = qv->data();
256 for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
258 PyObject *obj = PyList_GET_ITEM( sipPy, i );
259 if ( obj == Py_None )
264 else if ( PyBool_Check( obj ) )
266 *outData++ = QVariant( PyObject_IsTrue( obj ) == 1 );
268 else if ( PyLong_Check( obj ) )
270 *outData++ = QVariant( PyLong_AsLongLong( obj ) );
272 else if ( PyFloat_Check( obj ) )
274 *outData++ = QVariant( PyFloat_AsDouble( obj ) );
276 else if ( PyUnicode_Check( obj ) )
278 *outData++ = QVariant( QString::fromUtf8( PyUnicode_AsUTF8( obj ) ) );
283 QVariant *t =
reinterpret_cast<QVariant *
>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
287 sipReleaseType( t, sipType_QVariant, state );
294 sipReleaseType( t, sipType_QVariant, state );
300 return sipGetState( sipTransferObj );
316 % ConvertFromTypeCode
320 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
324 for (
int i = 0; i < sipCpp->size(); ++i )
326 const QVariant v = sipCpp->at( i );
327 PyObject *tobj = NULL;
331 Py_INCREF( Py_None );
336 switch ( v.userType() )
338 case QMetaType::Type::Int:
339 tobj = PyLong_FromLong( v.toInt() );
342 case QMetaType::Type::UInt:
343 tobj = PyLong_FromUnsignedLong( v.toUInt() );
346 case QMetaType::Type::Long:
347 case QMetaType::Type::LongLong:
348 tobj = PyLong_FromLongLong( v.toLongLong() );
351 case QMetaType::Type::ULong:
352 case QMetaType::Type::ULongLong:
353 tobj = PyLong_FromUnsignedLongLong( v.toULongLong() );
356 case QMetaType::Type::Bool:
357 tobj = PyBool_FromLong( v.toBool() ? 1 : 0 );
360 case QMetaType::Type::Float:
361 case QMetaType::Type::Double:
362 tobj = PyFloat_FromDouble( v.toDouble() );
365 case QMetaType::Type::QString:
366 tobj = PyUnicode_FromString( v.toString().toUtf8().constData() );
371 QVariant *newV =
new QVariant( v );
372 tobj = sipConvertFromNewType( newV, sipType_QVariant, sipTransferObj );
383 PyList_SET_ITEM( l, i, tobj );
391 if ( sipIsErr == NULL )
393 if ( !PyList_Check( sipPy ) )
396 for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
397 if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QVariant, SIP_NOT_NONE ) )
403 SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
407 const QVariant nullVariant( QVariant::Int );
409 QVariant *outData = qv->data();
411 for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
413 PyObject *obj = PyList_GET_ITEM( sipPy, i );
414 if ( obj == Py_None )
419 else if ( PyBool_Check( obj ) )
421 *outData++ = QVariant( PyObject_IsTrue( obj ) == 1 );
423 else if ( PyLong_Check( obj ) )
425 *outData++ = QVariant( PyLong_AsLongLong( obj ) );
427 else if ( PyFloat_Check( obj ) )
429 *outData++ = QVariant( PyFloat_AsDouble( obj ) );
431 else if ( PyUnicode_Check( obj ) )
433 *outData++ = QVariant( QString::fromUtf8( PyUnicode_AsUTF8( obj ) ) );
438 QVariant *t =
reinterpret_cast<QVariant *
>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
442 sipReleaseType( t, sipType_QVariant, state );
449 sipReleaseType( t, sipType_QVariant, state );
455 return sipGetState( sipTransferObj );
bool operator!=(const QgsAttributes &v) const
QgsAttributes(int size)
Create a new vector of attributes with the given size.
bool isUnsetValue(int index) const
Returns true if the attribute at the specified index is an unset value.
QgsAttributes(int size, const QVariant &v)
Constructs a vector with an initial size of size elements.
bool operator==(const QgsAttributes &v) const
Compares two vectors of attributes.
QgsAttributes(const QVector< QVariant > &v)
Copies another vector of attributes.
CORE_EXPORT QgsAttributeMap toMap() const
Returns a QgsAttributeMap of the attribute values.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
A rectangle specified with double values.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
CORE_EXPORT uint qHash(const QgsAttributes &attributes)
Hash for QgsAttributes.
QMap< int, QString > QgsFieldNameMap
QMap< int, QVariant > QgsAttributeMap