18#ifndef QGSATTRIBUTES_H
19#define QGSATTRIBUTES_H
27#include <QExplicitlySharedDataPointer>
37class QgsFeaturePrivate;
46typedef QMap<int, QgsField> QgsFieldMap;
67 : QVector<QVariant>( size )
76 : QVector<QVariant>( size, v )
84 : QVector<QVariant>( v )
98 if ( size() != v.size() )
100 const QVariant *b = constData();
101 const QVariant *i = b + size();
102 const QVariant *j = v.constData() + size();
127 if ( index < 0 || index >= size() )
130 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 );
318 % ConvertFromTypeCode
322 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
326 for (
int i = 0; i < sipCpp->size(); ++i )
328 const QVariant v = sipCpp->at( i );
329 PyObject *tobj = NULL;
333 Py_INCREF( Py_None );
338 switch ( v.userType() )
340 case QMetaType::Type::Int:
341 tobj = PyLong_FromLong( v.toInt() );
344 case QMetaType::Type::UInt:
345 tobj = PyLong_FromUnsignedLong( v.toUInt() );
348 case QMetaType::Type::Long:
349 case QMetaType::Type::LongLong:
350 tobj = PyLong_FromLongLong( v.toLongLong() );
353 case QMetaType::Type::ULong:
354 case QMetaType::Type::ULongLong:
355 tobj = PyLong_FromUnsignedLongLong( v.toULongLong() );
358 case QMetaType::Type::Bool:
359 tobj = PyBool_FromLong( v.toBool() ? 1 : 0 );
362 case QMetaType::Type::Float:
363 case QMetaType::Type::Double:
364 tobj = PyFloat_FromDouble( v.toDouble() );
367 case QMetaType::Type::QString:
368 tobj = PyUnicode_FromString( v.toString().toUtf8().constData() );
373 QVariant *newV =
new QVariant( v );
374 tobj = sipConvertFromNewType( newV, sipType_QVariant, sipTransferObj );
385 PyList_SET_ITEM( l, i, tobj );
393 if ( sipIsErr == NULL )
395 if ( !PyList_Check( sipPy ) )
398 for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
399 if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QVariant, SIP_NOT_NONE ) )
405 SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
409 const QVariant nullVariant( QVariant::Int );
411 QVariant *outData = qv->data();
413 for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
415 PyObject *obj = PyList_GET_ITEM( sipPy, i );
416 if ( obj == Py_None )
421 else if ( PyBool_Check( obj ) )
423 *outData++ = QVariant( PyObject_IsTrue( obj ) == 1 );
425 else if ( PyLong_Check( obj ) )
427 *outData++ = QVariant( PyLong_AsLongLong( obj ) );
429 else if ( PyFloat_Check( obj ) )
431 *outData++ = QVariant( PyFloat_AsDouble( obj ) );
433 else if ( PyUnicode_Check( obj ) )
435 *outData++ = QVariant( QString::fromUtf8( PyUnicode_AsUTF8( obj ) ) );
440 QVariant *t =
reinterpret_cast<QVariant *
>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
444 sipReleaseType( t, sipType_QVariant, state );
451 sipReleaseType( t, sipType_QVariant, state );
457 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