Skip to content

Commit

Permalink
fix build on PyQt <4.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Sep 14, 2014
1 parent 4d858eb commit 05c4522
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
53 changes: 53 additions & 0 deletions python/core/conversions.sip
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ which are not wrapped by PyQt:
%Feature QSETINT_CONVERSION
%Feature QSETTYPE_CONVERSION
%Feature QLISTCONSTPTR_CONVERSION
%Feature QVECTORINT_CONVERSION

%ModuleHeaderCode

Expand Down Expand Up @@ -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.