/************************************************************************ * This file has been generated automatically from * * * * src/core/qgsattributes.h * * * * Do not edit manually ! Edit header and run scripts/sipify.py again * ************************************************************************/ typedef QMap QgsAttributeMap; typedef QMap QgsFieldNameMap; typedef QMap QgsFieldMap; typedef QVector QgsAttributes; %MappedType QgsAttributes { %TypeHeaderCode #include "qgsfeature.h" %End %ConvertFromTypeCode // Create the list. PyObject *l; if ( ( l = PyList_New( sipCpp->size() ) ) == NULL ) return NULL; // Set the list elements. for ( int i = 0; i < sipCpp->size(); ++i ) { QVariant *v = new QVariant( sipCpp->at( i ) ); PyObject *tobj; if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant, Py_None ) ) == NULL ) { Py_DECREF( l ); delete v; return NULL; } PyList_SET_ITEM( l, i, tobj ); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if ( sipIsErr == NULL ) { if ( !PyList_Check( sipPy ) ) return 0; for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i ) if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QVariant, SIP_NOT_NONE ) ) return 0; return 1; } SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy ); // Initialize attributes to null. This has two motivations: // 1. It speeds up the QVector construction, as otherwise we are creating n default QVariant objects (default QVariant constructor is not free!) // 2. It lets us shortcut in the loop below when a Py_None is encountered in the list const QVariant nullVariant( QVariant::Int ); QgsAttributes *qv = new QgsAttributes( listSize, nullVariant ); QVariant *outData = qv->data(); for ( SIP_SSIZE_T i = 0; i < listSize; ++i ) { PyObject *obj = PyList_GET_ITEM( sipPy, i ); if ( obj == Py_None ) { // outData was already initialized to null values *outData++; } else if ( PyBool_Check( obj ) ) { *outData++ = QVariant( PyObject_IsTrue( obj ) == 1 ); } else if ( PyLong_Check( obj ) ) { *outData++ = QVariant( PyLong_AsLongLong( obj ) ); } else if ( PyFloat_Check( obj ) ) { *outData++ = QVariant( PyFloat_AsDouble( obj ) ); } else if ( PyUnicode_Check( obj ) ) { *outData++ = QVariant( QString::fromUtf8( PyUnicode_AsUTF8( obj ) ) ); } else { int state; QVariant *t = reinterpret_cast( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) ); if ( *sipIsErr ) { sipReleaseType( t, sipType_QVariant, state ); delete qv; return 0; } *outData++ = *t; sipReleaseType( t, sipType_QVariant, state ); } } *sipCppPtr = qv; return sipGetState( sipTransferObj ); %End }; /************************************************************************ * This file has been generated automatically from * * * * src/core/qgsattributes.h * * * * Do not edit manually ! Edit header and run scripts/sipify.py again * ************************************************************************/