Skip to content
Permalink
Browse files

fix build on PyQt <4.9.5

  • Loading branch information
jef-n committed Sep 14, 2014
1 parent 4d858eb commit 05c4522a63dca187defbf22c6f481b6787860c28
Showing with 57 additions and 0 deletions.
  1. +4 −0 python/CMakeLists.txt
  2. +53 −0 python/core/conversions.sip
@@ -125,6 +125,10 @@ IF(PYQT4_VERSION_NUM LESS 264196) # 0x040804
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} QLISTCONSTPTR_CONVERSION)
ENDIF(PYQT4_VERSION_NUM LESS 264196)

IF(NOT PYQT4_VERSION_NUM LESS 264453) # 0x040905
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} QVECTORINT_CONVERSION)
ENDIF(NOT PYQT4_VERSION_NUM LESS 264453)

# core module
FILE(GLOB_RECURSE sip_files_core core/*.sip)
SET(SIP_EXTRA_FILES_DEPEND ${sip_files_core})
@@ -23,6 +23,7 @@ which are not wrapped by PyQt:
%Feature QSETINT_CONVERSION
%Feature QSETTYPE_CONVERSION
%Feature QLISTCONSTPTR_CONVERSION
%Feature QVECTORINT_CONVERSION

%ModuleHeaderCode

@@ -1512,3 +1513,55 @@ template <TYPE>
return sipGetState(sipTransferObj);
%End
};

%If (QVECTORINT_CONVERSION)
// QVector<int> is implemented as a Python list of integers.
%MappedType QVector<int> /DocType="list-of-int"/
{
%TypeHeaderCode
#include <qvector.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)
{
PyObject *pobj;

// Convert to a Python long to make sure it doesn't get interpreted as
// a signed value.
if ((pobj = SIPLong_FromLong(sipCpp->value(i))) == NULL)
{
Py_DECREF(l);

return NULL;
}

PyList_SET_ITEM(l, i, pobj);
}

return l;
%End

%ConvertToTypeCode
// Check the type if that is all that is required.
if (sipIsErr == NULL)
return PyList_Check(sipPy);

QVector<int> *qv = new QVector<int>;

for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i)
qv->append(SIPLong_AsLong(PyList_GET_ITEM(sipPy, i)));

*sipCppPtr = qv;

return sipGetState(sipTransferObj);
%End
};
%Endif

0 comments on commit 05c4522

Please sign in to comment.
You can’t perform that action at this time.