From 7bfbbf3cb784f8e22dde74ebe28ba5e5eda4b7db Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Sun, 11 Dec 2011 23:13:12 -0300 Subject: No more training wheels. The last occurrences of the old template Converter where removed. Also related fixes here and there. --- PySide/QtCore/glue/hwnd_conversions.h | 54 ------ PySide/QtCore/glue/qbytearray_bufferprotocol.cpp | 2 +- PySide/QtCore/glue/qeasingcurve_glue.cpp | 2 +- PySide/QtCore/glue/qobject_connect.cpp | 8 +- PySide/QtCore/qbool_conversions.h | 16 -- PySide/QtCore/qbytearray_conversions.h | 44 ----- PySide/QtCore/qchar_conversions.h | 35 ---- PySide/QtCore/qdate_conversions.h | 53 ------ PySide/QtCore/qdatetime_conversions.h | 56 ------ PySide/QtCore/qhash_conversions.h | 4 - PySide/QtCore/qlist_conversions.h | 4 - PySide/QtCore/qmap_conversions.h | 5 - PySide/QtCore/qmultimap_conversions.h | 5 - PySide/QtCore/qpair_conversions.h | 4 - PySide/QtCore/qset_conversions.h | 4 - PySide/QtCore/qstack_conversion.h | 4 - PySide/QtCore/qstring_conversions.h | 49 ----- PySide/QtCore/qstringlist_conversions.h | 5 - PySide/QtCore/qstringref_conversions.h | 18 -- PySide/QtCore/qtime_conversions.h | 45 ----- PySide/QtCore/qvariant_conversions.h | 219 ----------------------- PySide/QtCore/qvariant_type_conversions.h | 87 --------- PySide/QtCore/qvector_conversions.h | 4 - PySide/QtCore/typesystem_core_common.xml | 65 +++---- PySide/QtCore/typesystem_core_win.xml | 2 +- PySide/QtDeclarative/pysideqmlregistertype.cpp | 19 +- PySide/QtGui/glue/qlayout_help_functions.cpp | 122 +++++++++++++ PySide/QtGui/glue/qlayout_help_functions.h | 130 -------------- PySide/QtGui/glue/qmenu_glue.cpp | 21 +++ PySide/QtGui/glue/qmenu_glue.h | 22 --- PySide/QtGui/glue/qmenubar_glue.cpp | 20 +++ PySide/QtGui/glue/qmenubar_glue.h | 20 --- PySide/QtGui/glue/qtgui_qapp.cpp | 2 +- PySide/QtGui/glue/qwidget_glue.cpp | 65 +++++++ PySide/QtGui/glue/qwidget_glue.h | 65 ------- PySide/QtGui/glue/wid_conversions.h | 39 ---- PySide/QtGui/qpixmap_conversion.h | 49 ----- PySide/QtGui/typesystem_gui_common.xml | 41 ++--- PySide/QtGui/typesystem_gui_win.xml | 2 +- PySide/QtUiTools/glue/uitools_loadui.cpp | 52 ++++++ PySide/QtUiTools/glue/uitools_loadui.h | 54 ------ PySide/QtUiTools/typesystem_uitools.xml | 7 +- PySide/QtWebKit/typesystem_webkit.xml | 4 +- 43 files changed, 355 insertions(+), 1173 deletions(-) delete mode 100644 PySide/QtCore/glue/hwnd_conversions.h delete mode 100644 PySide/QtCore/qbool_conversions.h delete mode 100644 PySide/QtCore/qbytearray_conversions.h delete mode 100644 PySide/QtCore/qchar_conversions.h delete mode 100644 PySide/QtCore/qdate_conversions.h delete mode 100644 PySide/QtCore/qdatetime_conversions.h delete mode 100644 PySide/QtCore/qhash_conversions.h delete mode 100644 PySide/QtCore/qlist_conversions.h delete mode 100644 PySide/QtCore/qmap_conversions.h delete mode 100644 PySide/QtCore/qmultimap_conversions.h delete mode 100644 PySide/QtCore/qpair_conversions.h delete mode 100644 PySide/QtCore/qset_conversions.h delete mode 100644 PySide/QtCore/qstack_conversion.h delete mode 100644 PySide/QtCore/qstring_conversions.h delete mode 100644 PySide/QtCore/qstringlist_conversions.h delete mode 100644 PySide/QtCore/qstringref_conversions.h delete mode 100644 PySide/QtCore/qtime_conversions.h delete mode 100644 PySide/QtCore/qvariant_conversions.h delete mode 100644 PySide/QtCore/qvariant_type_conversions.h delete mode 100644 PySide/QtCore/qvector_conversions.h create mode 100644 PySide/QtGui/glue/qlayout_help_functions.cpp delete mode 100644 PySide/QtGui/glue/qlayout_help_functions.h create mode 100644 PySide/QtGui/glue/qmenu_glue.cpp delete mode 100644 PySide/QtGui/glue/qmenu_glue.h create mode 100644 PySide/QtGui/glue/qmenubar_glue.cpp delete mode 100644 PySide/QtGui/glue/qmenubar_glue.h create mode 100644 PySide/QtGui/glue/qwidget_glue.cpp delete mode 100644 PySide/QtGui/glue/qwidget_glue.h delete mode 100644 PySide/QtGui/glue/wid_conversions.h delete mode 100644 PySide/QtGui/qpixmap_conversion.h create mode 100644 PySide/QtUiTools/glue/uitools_loadui.cpp delete mode 100644 PySide/QtUiTools/glue/uitools_loadui.h (limited to 'PySide') diff --git a/PySide/QtCore/glue/hwnd_conversions.h b/PySide/QtCore/glue/hwnd_conversions.h deleted file mode 100644 index 6dbaa8f4e..000000000 --- a/PySide/QtCore/glue/hwnd_conversions.h +++ /dev/null @@ -1,54 +0,0 @@ -namespace Shiboken { -template <> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return false; - } - - static bool isConvertible(PyObject* pyobj) - { - if (pyobj == Py_None) - return true; - -#ifdef IS_PY3K - return PyCapsule_CheckExact(pyobj); -#else - return PyCObject_Check(pyobj); -#endif - } - - static inline PyObject* toPython(void* cppobj) - { - // not supported - Q_ASSERT(true); - return 0; - } - - static PyObject* toPython(HWND cppobj) - { - if (!cppobj) - Py_RETURN_NONE; - -#ifdef IS_PY3K - return PyCapsule_New(cppobj, 0, 0); -#else - return PyCObject_FromVoidPtr(cppobj, 0); -#endif - } - - static HWND toCpp(PyObject* pyobj) - { - if (pyobj == Py_None) - return 0; - -#ifdef IS_PY3K - return (HWND)PyCapsule_GetPointer(pyobj, 0); -#else - return (HWND)PyCObject_AsVoidPtr(pyobj); -#endif - } -}; - -} diff --git a/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp b/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp index 03ffcb4af..acc7bb93e 100644 --- a/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp +++ b/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp @@ -18,7 +18,7 @@ static Py_ssize_t SbkQByteArray_readbufferproc(PyObject* self, Py_ssize_t segmen if (segment || !Shiboken::Object::isValid(self)) return -1; - QByteArray* cppSelf = Shiboken::Converter::toCpp(self); + QByteArray* cppSelf = %CONVERTTOCPP[QByteArray*](self); *ptrptr = reinterpret_cast(cppSelf->data()); return cppSelf->size(); } diff --git a/PySide/QtCore/glue/qeasingcurve_glue.cpp b/PySide/QtCore/glue/qeasingcurve_glue.cpp index fd2dee092..7f56315b3 100644 --- a/PySide/QtCore/glue/qeasingcurve_glue.cpp +++ b/PySide/QtCore/glue/qeasingcurve_glue.cpp @@ -93,7 +93,7 @@ qreal PySideEasingCurveFunctor::operator()(qreal progress) PyObject* result = PyObject_CallObject(m_func, args); qreal cppResult = 0.0; if (result) { - cppResult = Shiboken::Converter::toCpp(result); + Shiboken::Conversions::pythonToCppCopy(Shiboken::Conversions::PrimitiveTypeConverter(), result, &cppResult); Py_DECREF(result); } Py_DECREF(args); diff --git a/PySide/QtCore/glue/qobject_connect.cpp b/PySide/QtCore/glue/qobject_connect.cpp index b46cbcfbc..96bcfb227 100644 --- a/PySide/QtCore/glue/qobject_connect.cpp +++ b/PySide/QtCore/glue/qobject_connect.cpp @@ -13,13 +13,13 @@ static bool getReceiver(QObject *source, const char* signal, PyObject* callback, bool forceGlobalReceiver = false; if (PyMethod_Check(callback)) { *self = PyMethod_GET_SELF(callback); - if (Shiboken::Converter::checkType(*self)) - *receiver = Shiboken::Converter::toCpp(*self); + if (%CHECKTYPE[QObject*](*self)) + *receiver = %CONVERTTOCPP[QObject*](*self); forceGlobalReceiver = isDecorator(callback, *self); } else if (PyCFunction_Check(callback)) { *self = PyCFunction_GET_SELF(callback); - if (*self && Shiboken::Converter::checkType(*self)) - *receiver = Shiboken::Converter::toCpp(*self); + if (*self && %CHECKTYPE[QObject*](*self)) + *receiver = %CONVERTTOCPP[QObject*](*self); } else if (PyCallable_Check(callback)) { // Ok, just a callable object *receiver = 0; diff --git a/PySide/QtCore/qbool_conversions.h b/PySide/QtCore/qbool_conversions.h deleted file mode 100644 index f4fb43fa6..000000000 --- a/PySide/QtCore/qbool_conversions.h +++ /dev/null @@ -1,16 +0,0 @@ -namespace Shiboken { -template <> -struct Converter : public ValueTypeConverter -{ - using ValueTypeConverter::toPython; - - static PyObject* toPython(const QBool& cppobj) - { - return PyBool_FromLong((bool) cppobj); - } - static QBool toCpp(PyObject* pyobj) - { - return QBool(pyobj == Py_True); - } -}; -} diff --git a/PySide/QtCore/qbytearray_conversions.h b/PySide/QtCore/qbytearray_conversions.h deleted file mode 100644 index d776d82c4..000000000 --- a/PySide/QtCore/qbytearray_conversions.h +++ /dev/null @@ -1,44 +0,0 @@ -namespace Shiboken { - -inline bool Converter::checkType(PyObject* pyObj) -{ - return ValueTypeConverter::checkType(pyObj); -} - -inline bool Converter::isConvertible(PyObject* pyObj) -{ - if (ValueTypeConverter::isConvertible(pyObj)) - return true; - SbkObjectType* shiboType = reinterpret_cast(SbkType< ::QByteArray >()); - return Shiboken::Converter::checkType(pyObj) - || PyBytes_Check(pyObj) - || (ObjectType::isExternalConvertible(shiboType, pyObj)); -} - -inline QByteArray Converter::toCpp(PyObject* pyObj) -{ - if (pyObj == Py_None) { - return 0; - } else if (PyObject_TypeCheck(pyObj, SbkType())) { - return *Converter::toCpp(pyObj); - } else if (PyBytes_Check(pyObj)) { - return QByteArray(PyBytes_AS_STRING(pyObj), PyBytes_GET_SIZE(pyObj)); - } else if (PyUnicode_Check(pyObj)) { - Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(pyObj)); - if (!data.isNull()) - return QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); - else - return QByteArray(); - } else if (Shiboken::String::check(pyObj)) { - return QByteArray(Shiboken::String::toCString(pyObj)); - } else { - return ValueTypeConverter::toCpp(pyObj); - } -} - -inline PyObject* Converter::toPython(const ::QByteArray& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} - -} diff --git a/PySide/QtCore/qchar_conversions.h b/PySide/QtCore/qchar_conversions.h deleted file mode 100644 index f79bac3c7..000000000 --- a/PySide/QtCore/qchar_conversions.h +++ /dev/null @@ -1,35 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return Shiboken::String::check(pyObj) && (Shiboken::String::len(pyObj) == 1); - } - - static bool isConvertible(PyObject* pyObj) - { - return (Shiboken::String::check(pyObj) && (Shiboken::String::len(pyObj) == 1)) - || pyObj == Py_None - || PyInt_Check(pyObj); - } - - static QChar toCpp(PyObject* pyObj) - { - if (Shiboken::String::check(pyObj) && (Shiboken::String::len(pyObj) == 1)) - return QChar(Shiboken::Converter::toCpp(pyObj)); - else if (PyInt_Check(pyObj)) - return QChar(Shiboken::Converter::toCpp(pyObj)); - return QChar(); - } - - static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } - static PyObject* toPython(const QChar& cppObj) - { - wchar_t c = (wchar_t)cppObj.unicode(); - PyObject* pyObj = PyUnicode_FromWideChar(&c, 1); - return pyObj; - } -}; -} diff --git a/PySide/QtCore/qdate_conversions.h b/PySide/QtCore/qdate_conversions.h deleted file mode 100644 index 0d97a057a..000000000 --- a/PySide/QtCore/qdate_conversions.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifdef IS_PY3K -#define PySideDateTime_IMPORT PyDateTime_IMPORT -#else -#define PySideDateTime_IMPORT \ - PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import((char*)"datetime", \ - (char*)"datetime_CAPI") -#endif - -namespace Shiboken { - -inline bool Converter::checkType(PyObject* pyObj) -{ - return ValueTypeConverter::checkType(pyObj); -} - -inline PyObject* Converter::toPython(const ::QDate& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} - -inline bool Converter::isConvertible(PyObject* pyObj) -{ - if (ValueTypeConverter::isConvertible(pyObj)) - return true; - - if (!PyDateTimeAPI) - PySideDateTime_IMPORT; - - SbkObjectType* shiboType = reinterpret_cast(SbkType< ::QDate >()); - return PyDate_Check(pyObj) || ObjectType::isExternalConvertible(shiboType, pyObj); -} - -inline QDate Converter::toCpp(PyObject* pyObj) -{ - if (!PyDateTimeAPI) - PySideDateTime_IMPORT; - - if (pyObj == Py_None) { - return QDate(); - } else if (PyObject_TypeCheck(pyObj, SbkType())) { - return *Converter::toCpp(pyObj); - } else if (PyDate_Check(pyObj)) { - int day = PyDateTime_GET_DAY(pyObj); - int month = PyDateTime_GET_MONTH(pyObj); - int year = PyDateTime_GET_YEAR(pyObj); - return QDate(year, month, day); - } else { - return ValueTypeConverter::toCpp(pyObj); - } -} - - -} diff --git a/PySide/QtCore/qdatetime_conversions.h b/PySide/QtCore/qdatetime_conversions.h deleted file mode 100644 index bcf9ad3fe..000000000 --- a/PySide/QtCore/qdatetime_conversions.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifdef IS_PY3K -#define PySideDateTime_IMPORT PyDateTime_IMPORT -#else -#define PySideDateTime_IMPORT \ - PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import((char*)"datetime", \ - (char*)"datetime_CAPI") -#endif -namespace Shiboken { - -inline bool Converter::checkType(PyObject* pyObj) -{ - return ValueTypeConverter::checkType(pyObj); -} - -inline PyObject* Converter::toPython(const ::QDateTime& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} - -inline bool Converter::isConvertible(PyObject* pyObj) -{ - if (ValueTypeConverter::isConvertible(pyObj)) - return true; - - if (!PyDateTimeAPI) - PySideDateTime_IMPORT; - - SbkObjectType* shiboType = reinterpret_cast(SbkType< ::QDateTime >()); - return PyDateTime_Check(pyObj) || ObjectType::isExternalConvertible(shiboType, pyObj); -} - - -inline QDateTime Converter::toCpp(PyObject* pyObj) -{ - if (!PyDateTimeAPI) - PySideDateTime_IMPORT; - - if (pyObj == Py_None) { - return QDateTime(); - } else if (PyObject_TypeCheck(pyObj, SbkType())) { - return *Converter::toCpp(pyObj); - } else if (PyDateTime_Check(pyObj)) { - int day = PyDateTime_GET_DAY(pyObj); - int month = PyDateTime_GET_MONTH(pyObj); - int year = PyDateTime_GET_YEAR(pyObj); - int hour = PyDateTime_DATE_GET_HOUR(pyObj); - int min = PyDateTime_DATE_GET_MINUTE(pyObj); - int sec = PyDateTime_DATE_GET_SECOND(pyObj); - int usec = PyDateTime_DATE_GET_MICROSECOND(pyObj); - return QDateTime(QDate(year, month, day), QTime(hour, min, sec, usec/1000)); - } else { - return ValueTypeConverter::toCpp(pyObj); - } -} - -} diff --git a/PySide/QtCore/qhash_conversions.h b/PySide/QtCore/qhash_conversions.h deleted file mode 100644 index f9e2e4217..000000000 --- a/PySide/QtCore/qhash_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : QtDictConverter > {}; -} diff --git a/PySide/QtCore/qlist_conversions.h b/PySide/QtCore/qlist_conversions.h deleted file mode 100644 index cb1d26bd5..000000000 --- a/PySide/QtCore/qlist_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : StdListConverter > {}; -} diff --git a/PySide/QtCore/qmap_conversions.h b/PySide/QtCore/qmap_conversions.h deleted file mode 100644 index 3153fae92..000000000 --- a/PySide/QtCore/qmap_conversions.h +++ /dev/null @@ -1,5 +0,0 @@ -namespace Shiboken { -template -struct Converter > : QtDictConverter > { -}; -} diff --git a/PySide/QtCore/qmultimap_conversions.h b/PySide/QtCore/qmultimap_conversions.h deleted file mode 100644 index 43abd84df..000000000 --- a/PySide/QtCore/qmultimap_conversions.h +++ /dev/null @@ -1,5 +0,0 @@ -namespace Shiboken { -template -struct Converter > : QtMultiMapConverter > { -}; -} diff --git a/PySide/QtCore/qpair_conversions.h b/PySide/QtCore/qpair_conversions.h deleted file mode 100644 index 99e9cd8b8..000000000 --- a/PySide/QtCore/qpair_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : StdPairConverter > {}; -} diff --git a/PySide/QtCore/qset_conversions.h b/PySide/QtCore/qset_conversions.h deleted file mode 100644 index c46fef00b..000000000 --- a/PySide/QtCore/qset_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : QSequenceConverter > {}; -} diff --git a/PySide/QtCore/qstack_conversion.h b/PySide/QtCore/qstack_conversion.h deleted file mode 100644 index 709a91891..000000000 --- a/PySide/QtCore/qstack_conversion.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : StdListConverter > {}; -} diff --git a/PySide/QtCore/qstring_conversions.h b/PySide/QtCore/qstring_conversions.h deleted file mode 100644 index 33c393b1f..000000000 --- a/PySide/QtCore/qstring_conversions.h +++ /dev/null @@ -1,49 +0,0 @@ -namespace Shiboken { - -template<> -inline PyTypeObject* SbkType() -{ - return &PyUnicode_Type; -} - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return Shiboken::String::check(pyObj); - } - - static bool isConvertible(PyObject* pyObj) - { - return Shiboken::String::isConvertible(pyObj); - } - - static QString toCpp(PyObject* pyObj) - { - if (PyUnicode_Check(pyObj)) { - Py_UNICODE* unicode = PyUnicode_AS_UNICODE(pyObj); - #if defined(Py_UNICODE_WIDE) || defined(__CYGWIN__) - // cast as Py_UNICODE can be a different type - return QString::fromUcs4(reinterpret_cast(unicode)); - #else - return QString::fromUtf16(unicode, PyUnicode_GET_SIZE(pyObj)); - #endif - } else if (Shiboken::String::check(pyObj)) { - return QString(Shiboken::String::toCString(pyObj)); - } - return QString(); - } - - static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } - static PyObject* toPython(const QString& cppObj) - { - const int N = cppObj.length(); - wchar_t* str = new wchar_t[N]; - cppObj.toWCharArray(str); - PyObject* pyObj = PyUnicode_FromWideChar(str, N); - delete[] str; - return pyObj; - } -}; -} diff --git a/PySide/QtCore/qstringlist_conversions.h b/PySide/QtCore/qstringlist_conversions.h deleted file mode 100644 index 6075c1672..000000000 --- a/PySide/QtCore/qstringlist_conversions.h +++ /dev/null @@ -1,5 +0,0 @@ -namespace Shiboken -{ -template<> -struct Converter : StdListConverter {}; -} diff --git a/PySide/QtCore/qstringref_conversions.h b/PySide/QtCore/qstringref_conversions.h deleted file mode 100644 index db3eefcae..000000000 --- a/PySide/QtCore/qstringref_conversions.h +++ /dev/null @@ -1,18 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter : public Converter -{ - static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } - - static PyObject* toPython(const QStringRef& cppObj) - { - return Converter::toPython(cppObj.toString()); - } - - static QStringRef toCpp(PyObject* pyObj) - { - return QStringRef(); - } -}; -} diff --git a/PySide/QtCore/qtime_conversions.h b/PySide/QtCore/qtime_conversions.h deleted file mode 100644 index 4600ef758..000000000 --- a/PySide/QtCore/qtime_conversions.h +++ /dev/null @@ -1,45 +0,0 @@ -namespace Shiboken { - -inline bool Converter::checkType(PyObject* pyObj) -{ - return ValueTypeConverter::checkType(pyObj); -} - -inline PyObject* Converter::toPython(const ::QTime& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} - -inline bool Converter::isConvertible(PyObject* pyObj) -{ - if (ValueTypeConverter::isConvertible(pyObj)) - return true; - - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - SbkObjectType* shiboType = reinterpret_cast(SbkType< ::QTime >()); - return PyTime_Check(pyObj) || ObjectType::isExternalConvertible(shiboType, pyObj); -} - -inline QTime Converter::toCpp(PyObject* pyObj) -{ - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - if (pyObj == Py_None) { - return QTime(); - } else if (PyObject_TypeCheck(pyObj, SbkType())) { - return *Converter::toCpp(pyObj); - } else if (PyTime_Check(pyObj)) { - int hour = PyDateTime_TIME_GET_HOUR(pyObj); - int min = PyDateTime_TIME_GET_MINUTE(pyObj); - int sec = PyDateTime_TIME_GET_SECOND(pyObj); - int usec = PyDateTime_TIME_GET_MICROSECOND(pyObj); - return QTime(hour, min, sec, usec/1000); - } else { - return ValueTypeConverter::toCpp(pyObj); - } -} - -} diff --git a/PySide/QtCore/qvariant_conversions.h b/PySide/QtCore/qvariant_conversions.h deleted file mode 100644 index eda2acce9..000000000 --- a/PySide/QtCore/qvariant_conversions.h +++ /dev/null @@ -1,219 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return false; // lets avoid the chaos - } - - // all types are convertible to QVariant - static bool isConvertible(PyObject* pyObj) - { - return true; - } - - static const char* resolveMetaType(PyTypeObject* type, int* typeId) - { - if (PyObject_TypeCheck(type, &SbkObjectType_Type)) { - SbkObjectType* sbkType = reinterpret_cast(type); - const char* typeName = Shiboken::ObjectType::getOriginalName(sbkType); - if (!typeName) - return 0; - bool valueType = '*' != typeName[qstrlen(typeName) - 1]; - - // Do not convert user type of value - if (valueType && Shiboken::ObjectType::isUserType(type)) - return 0; - - int obTypeId = QMetaType::type(typeName); - if (obTypeId) { - *typeId = obTypeId; - return typeName; - } - - // Do not resolve types to value type - if (valueType) - return 0; - - // find in base types - if (type->tp_base) { - return resolveMetaType(type->tp_base, typeId); - } else if (type->tp_bases) { - int size = PyTuple_GET_SIZE(type->tp_bases); - for(int i=0; i < size; i++){ - const char* derivedName = resolveMetaType(reinterpret_cast(PyTuple_GET_ITEM(type->tp_bases, i)), typeId); - if (derivedName) - return derivedName; - } - } - } - *typeId = 0; - return 0; - } - - static QVariant toCpp(PyObject* pyObj) - { - using namespace Shiboken; - - // Primitive types - if (Converter::checkType(pyObj)) { - // QVariant(bool) - return QVariant(Converter::toCpp(pyObj)); - } else if (pyObj == Py_None) { - // QVariant() - return QVariant(); - } else if (Converter::checkType(pyObj)) { - // QVariant(const char*) - return QVariant(Converter::toCpp(pyObj)); - } else if (Converter::checkType(pyObj)) { - // QVariant(QByteArray) - return QVariant(Converter::toCpp(pyObj)); - } else if (PyFloat_CheckExact(pyObj)) { - // QVariant(double) - return QVariant(Converter::toCpp(pyObj)); - } else if (PyInt_Check(pyObj)) { - // QVariant(int) - return QVariant(Converter::toCpp(pyObj)); - } else if (PyLong_CheckExact(pyObj)) { - // QVariant(qlonglong) - return QVariant(Converter::toCpp(pyObj)); - } else if (Shiboken::isShibokenEnum(pyObj)) { - // QVariant(enum) - return QVariant(Converter::toCpp(pyObj)); - } else if (PyNumber_Check(pyObj)) { - Shiboken::AutoDecRef pyValue(PyNumber_Long(pyObj)); - return QVariant((int)PyLong_AsLong(pyValue.object())); - } else if (Shiboken::Object::checkType(pyObj)) { - // a class supported by QVariant? - int typeCode; - const char* typeName = resolveMetaType(pyObj->ob_type, &typeCode); - if (typeCode && typeName) { - Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(typeName); - QVariant var(typeCode, (void*)0); - void* args[] = { var.data() }; - tr->toCpp(pyObj, args); - return var; - } - } - - // Sequence and dictionary - if (PyDict_Check(pyObj)) { - QVariant ret = convertToVariantMap(pyObj); - if (ret.isValid()) - return ret; - } else if (PySequence_Check(pyObj)) { - return convertToVariantList(pyObj); - } - - // Is a shiboken type not known by Qt - return QVariant::fromValue(pyObj); - } - - static PyObject* toPython(void* cppObj) - { - return toPython(*reinterpret_cast(cppObj)); - } - - static PyObject* toPython(const QVariant& cppObj) - { - if (cppObj.isValid()) { - if (qstrcmp(cppObj.typeName(), "QVariantList") == 0) - return Converter >::toPython(cppObj.value()); - - if (qstrcmp(cppObj.typeName(), "QStringList") == 0) - return Converter >::toPython(cppObj.value()); - - if (qstrcmp(cppObj.typeName(), "QVariantMap") == 0) - return Converter >::toPython(cppObj.value()); - - Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(cppObj.typeName()); - if (tr) - return tr->toPython(const_cast(cppObj.data())); - } - Py_RETURN_NONE; - } - - static QVariant convertToValueList(PyObject* list) - { - if (PySequence_Size(list) < 1) - return QVariant(); - - Shiboken::AutoDecRef element(PySequence_GetItem(list, 0)); - int typeId; - const char* typeName = resolveMetaType(element.cast(), &typeId); - if (typeName) { - QByteArray listTypeName("QList<"); - listTypeName += typeName; - listTypeName += '>'; - typeId = QMetaType::type(listTypeName); - if (typeId > 0) { - Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(listTypeName); - if (!tr) { - qWarning() << "TypeResolver for :" << listTypeName << "not registered."; - } else { - QVariant var(typeId, (void*)0); - void* args[] = { var.data(), 0 }; - tr->toCpp(list, args); - return var; - } - } - } - return QVariant(); - } - - static QVariant convertToVariantMap(PyObject* map) - { - PyObject *key, *value; - Py_ssize_t pos = 0; - AutoDecRef keys(PyDict_Keys(map)); - bool keysIsString = isStringList(keys); - if (keysIsString) { - QMap ret; - while (PyDict_Next(map, &pos, &key, &value)) - ret.insert(Converter::toCpp(key), toCpp(value)); - return QVariant(ret); - } else { - return QVariant(); - } - } - - static bool isStringList(PyObject *list) - { - bool allString = true; - AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); - Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); - for(int i=0; i < size; i++) { - PyObject* item = PySequence_Fast_GET_ITEM(fast.object(), i); - if (!Converter::checkType(item)) { - allString = false; - break; - } - } - return allString; - } - - static QVariant convertToVariantList(PyObject* list) - { - bool allString = isStringList(list); - if (allString) { - QStringList lst = Converter >::toCpp(list); - return QVariant(lst); - } else { - QVariant valueList = convertToValueList(list); - if (valueList.isValid()) - return valueList; - QList lst; - AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); - Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); - for(int i=0; i < size; i++) { - PyObject* item = PySequence_Fast_GET_ITEM(fast.object(), i); - lst.append(toCpp(item)); - } - return QVariant(lst); - } - Q_ASSERT(false); - } -}; -} diff --git a/PySide/QtCore/qvariant_type_conversions.h b/PySide/QtCore/qvariant_type_conversions.h deleted file mode 100644 index 9fad1f183..000000000 --- a/PySide/QtCore/qvariant_type_conversions.h +++ /dev/null @@ -1,87 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return pyObj == Py_None || PyType_Check(pyObj) || Converter::checkType(pyObj); - } - - static bool isConvertible(PyObject* pyObj) - { - return checkType(pyObj); - } - - static QVariant::Type toCpp(PyObject* pyObj) - { - const char* typeName = 0; - if (pyObj == Py_None) - return QVariant::Invalid; - - if (Shiboken::String::checkType(reinterpret_cast(pyObj))) - typeName = "QString"; - - - else if (pyObj == reinterpret_cast(&PyFloat_Type)) - typeName = "double"; // float is a UserType in QVariant. - else if (pyObj == reinterpret_cast(&PyLong_Type)) - typeName = "int"; // long is a UserType in QVariant. - else if (PyType_Check(pyObj)) { - if (pyObj->ob_type == &SbkObjectType_Type) - typeName = Shiboken::ObjectType::getOriginalName(reinterpret_cast(pyObj)); - else - typeName = reinterpret_cast(pyObj)->tp_name; - } - else if (Shiboken::String::check(pyObj)) - typeName = Shiboken::String::toCString(pyObj); - else if (PyDict_Check(pyObj) && checkAllStringKeys(pyObj)) - typeName = "QVariantMap"; - else if (PySequence_Check(pyObj)) - if (isStringList(pyObj)) - typeName = "QStringList"; - else - typeName = "QVariantList"; - else - Q_ASSERT(false); - - return QVariant::nameToType(typeName); - } - - static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } - static PyObject* toPython(const QVariant::Type& cppObj) - { - const char* typeName = QVariant::typeToName(cppObj); - PyObject* pyObj; - if (!typeName) { - pyObj = Py_None; - } else { - Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(typeName); - pyObj = tr ? reinterpret_cast(tr->pythonType()) : Py_None; - } - Py_INCREF(pyObj); - return pyObj; - } - - static bool isStringList(PyObject* list) - { - bool allString = true; - AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); - Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); - for(int i=0; i < size; i++) { - PyObject* item = PySequence_Fast_GET_ITEM(fast.object(), i); - if (!Converter::checkType(item)) { - allString = false; - break; - } - } - return allString; - } - - static bool checkAllStringKeys(PyObject* dict) - { - AutoDecRef keys(PyDict_Keys(dict)); - return isStringList(keys); - } -}; -} diff --git a/PySide/QtCore/qvector_conversions.h b/PySide/QtCore/qvector_conversions.h deleted file mode 100644 index 0857036ae..000000000 --- a/PySide/QtCore/qvector_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : StdListConverter > {}; -} diff --git a/PySide/QtCore/typesystem_core_common.xml b/PySide/QtCore/typesystem_core_common.xml index 965433b8d..aa39e9536 100644 --- a/PySide/QtCore/typesystem_core_common.xml +++ b/PySide/QtCore/typesystem_core_common.xml @@ -153,7 +153,7 @@ - + return PyBool_FromLong((bool)%in); @@ -180,7 +180,7 @@ - + const int N = %in.length(); wchar_t* str = new wchar_t[N]; @@ -213,8 +213,7 @@ - - + const int N = %in.toString().length(); wchar_t* str = new wchar_t[N]; @@ -231,7 +230,7 @@ - + wchar_t c = (wchar_t)%in.unicode(); return PyUnicode_FromWideChar(&c, 1); @@ -254,7 +253,7 @@ - + if (!%in.isValid()) Py_RETURN_NONE; @@ -448,7 +447,7 @@ - + const char* typeName = QVariant::typeToName(%in); PyObject* %out; @@ -524,7 +523,7 @@ - + @@ -560,7 +559,7 @@ - + @@ -574,7 +573,7 @@ - + @@ -588,7 +587,7 @@ - + @@ -603,7 +602,7 @@ - + @@ -669,7 +668,7 @@ - + @@ -682,7 +681,7 @@ - + @@ -695,7 +694,7 @@ - + @@ -709,7 +708,7 @@ - + PyObject* %out = PyTuple_New(2); PyTuple_SET_ITEM(%out, 0, %CONVERTTOPYTHON[%INTYPE_0](%in.first)); @@ -1110,9 +1109,15 @@ @@ -1121,7 +1126,7 @@ - + %out = %OUTTYPE(); @@ -1157,8 +1162,8 @@ - if (!PyDateTimeAPI) PyDateTime_IMPORT; - %PYARG_0 = PyDate_FromDate(%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()); + if (!PyDateTimeAPI) PySideDateTime_IMPORT; + %PYARG_0 = PyDate_FromDate(%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()); @@ -1211,7 +1216,7 @@ - + %out = %OUTTYPE(); @@ -1260,10 +1265,10 @@ - QDate date = %CPPSELF.date(); - QTime time = %CPPSELF.time(); - if (!PyDateTimeAPI) PyDateTime_IMPORT; - %PYARG_0 = PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec()*1000); + QDate date = %CPPSELF.date(); + QTime time = %CPPSELF.time(); + if (!PyDateTimeAPI) PySideDateTime_IMPORT; + %PYARG_0 = PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec()*1000); @@ -1570,7 +1575,7 @@ - + %out = %OUTTYPE(); @@ -1607,8 +1612,8 @@ - if (!PyDateTimeAPI) PyDateTime_IMPORT; - %PYARG_0 = PyTime_FromTime(%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()*1000); + if (!PyDateTimeAPI) PySideDateTime_IMPORT; + %PYARG_0 = PyTime_FromTime(%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()*1000); @@ -2259,7 +2264,7 @@ - + %out = %OUTTYPE(); diff --git a/PySide/QtCore/typesystem_core_win.xml b/PySide/QtCore/typesystem_core_win.xml index f4b8cab24..26c7a82a2 100644 --- a/PySide/QtCore/typesystem_core_win.xml +++ b/PySide/QtCore/typesystem_core_win.xml @@ -21,7 +21,7 @@ - + #ifdef IS_PY3K return PyCapsule_New(%in, 0, 0); diff --git a/PySide/QtDeclarative/pysideqmlregistertype.cpp b/PySide/QtDeclarative/pysideqmlregistertype.cpp index 30844c671..4efc4bf77 100644 --- a/PySide/QtDeclarative/pysideqmlregistertype.cpp +++ b/PySide/QtDeclarative/pysideqmlregistertype.cpp @@ -282,12 +282,13 @@ int propListCount(QDeclarativeListProperty* propList) Shiboken::AutoDecRef retVal(PyObject_CallObject(data->count, args)); // Check return type + int cppResult = 0; + PythonToCppFunc pythonToCpp; if (PyErr_Occurred()) PyErr_Print(); - else if (Shiboken::Converter::isConvertible(retVal)) - return Shiboken::Converter::toCpp(retVal); - - return 0; + else if ((pythonToCpp = Shiboken::Conversions::isPythonToCppConvertible(Shiboken::Conversions::PrimitiveTypeConverter(), retVal))) + pythonToCpp(retVal, &cppResult); + return cppResult; } // Implementation of QDeclarativeListProperty::AtFunction callback @@ -302,12 +303,12 @@ QDeclarativeItem* propListAt(QDeclarativeListProperty* propLis DeclarativeListProperty* data = reinterpret_cast(propList->data); Shiboken::AutoDecRef retVal(PyObject_CallObject(data->at, args)); + QDeclarativeItem* result = 0; if (PyErr_Occurred()) PyErr_Print(); else if (PyType_IsSubtype(Py_TYPE(retVal), data->type)) - return Shiboken::Converter::toCpp(retVal); - - return 0; + Shiboken::Conversions::pythonToCppPointer((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QDECLARATIVEITEM_IDX], retVal, &result); + return result; } // Implementation of QDeclarativeListProperty::ClearFunction callback @@ -332,7 +333,9 @@ static void propListMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::Ca return; DeclarativeListProperty* data = reinterpret_cast(PySide::Property::userData(pp)); - QDeclarativeListProperty declProp(Shiboken::Converter::toCpp(self), data, &propListAppender); + QObject* qobj; + Shiboken::Conversions::pythonToCppPointer((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], self, &qobj); + QDeclarativeListProperty declProp(qobj, data, &propListAppender); if (data->count) declProp.count = &propListCount; diff --git a/PySide/QtGui/glue/qlayout_help_functions.cpp b/PySide/QtGui/glue/qlayout_help_functions.cpp new file mode 100644 index 000000000..b36606136 --- /dev/null +++ b/PySide/QtGui/glue/qlayout_help_functions.cpp @@ -0,0 +1,122 @@ +void addLayoutOwnership(QLayout* layout, QLayoutItem* item); +void removeLayoutOwnership(QLayout* layout, QWidget* widget); + +inline QByteArray retrieveObjectName(PyObject* obj) +{ + Shiboken::AutoDecRef objName(PyObject_Str(obj)); + return Shiboken::String::toCString(objName); +} + +inline void addLayoutOwnership(QLayout* layout, QWidget* widget) +{ + //transfer ownership to parent widget + QWidget *lw = layout->parentWidget(); + QWidget *pw = widget->parentWidget(); + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](widget)); + + //Transfer parent to layout widget + if (pw && lw && pw != lw) + Shiboken::Object::setParent(0, pyChild); + + if (!lw && !pw) { + //keep the reference while the layout is orphan + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](layout)); + Shiboken::Object::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); + } else { + if (!lw) + lw = pw; + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](lw)); + Shiboken::Object::setParent(pyParent, pyChild); + } +} + +inline void addLayoutOwnership(QLayout* layout, QLayout* other) +{ + //transfer all children widgets from other to layout parent widget + QWidget* parent = layout->parentWidget(); + if (!parent) { + //keep the reference while the layout is orphan + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout*](other)); + Shiboken::Object::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); + return; + } + + for (int i=0, i_max=other->count(); i < i_max; i++) { + QLayoutItem* item = other->itemAt(i); + if (PyErr_Occurred() || !item) + return; + addLayoutOwnership(layout, item); + } + + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout*](other)); + Shiboken::Object::setParent(pyParent, pyChild); +} + +inline void addLayoutOwnership(QLayout* layout, QLayoutItem* item) +{ + if (!item) + return; + + QWidget* w = item->widget(); + if (w) + addLayoutOwnership(layout, w); + else { + QLayout* l = item->layout(); + if (l) + addLayoutOwnership(layout, l); + } + + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayoutItem*](item)); + Shiboken::Object::setParent(pyParent, pyChild); +} + +static void removeWidgetFromLayout(QLayout* layout, QWidget* widget) +{ + QWidget* parent = widget->parentWidget(); + + if (!parent) { + //remove reference on layout + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](widget)); + Shiboken::Object::removeReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild); + } else { + //give the ownership to parent + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](parent)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](widget)); + Shiboken::Object::setParent(pyParent, pyChild); + } +} + +inline void removeLayoutOwnership(QLayout* layout, QLayoutItem* item) +{ + QWidget* w = item->widget(); + if (w) + removeWidgetFromLayout(layout, w); + else { + QLayout* l = item->layout(); + if (l) + removeLayoutOwnership(layout, l); + } + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayoutItem*](item)); + Shiboken::Object::invalidate(pyChild); + Shiboken::Object::setParent(0, pyChild); +} + +inline void removeLayoutOwnership(QLayout* layout, QWidget* widget) +{ + if (!widget) + return; + + for (int i=0, i_max=layout->count(); i < i_max; i++) { + QLayoutItem* item = layout->itemAt(i); + if (PyErr_Occurred() || !item) + return; + if (item->widget() == widget) + removeLayoutOwnership(layout, item); + } +} diff --git a/PySide/QtGui/glue/qlayout_help_functions.h b/PySide/QtGui/glue/qlayout_help_functions.h deleted file mode 100644 index 00f0dbde7..000000000 --- a/PySide/QtGui/glue/qlayout_help_functions.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef QLAYOUT_HELP_FUNCTIONS -#define QLAYOUT_HELP_FUNCTIONS - -void addLayoutOwnership(QLayout* layout, QLayoutItem* item); -void removeLayoutOwnership(QLayout* layout, QWidget* widget); - -inline QByteArray retrieveObjectName(PyObject* obj) -{ - Shiboken::AutoDecRef objName(PyObject_Str(obj)); - return Shiboken::String::toCString(objName); -} - -inline void addLayoutOwnership(QLayout* layout, QWidget* widget) -{ - //transfer ownership to parent widget - QWidget *lw = layout->parentWidget(); - QWidget *pw = widget->parentWidget(); - - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(widget)); - - //Transfer parent to layout widget - if (pw && lw && pw != lw) - Shiboken::Object::setParent(0, pyChild); - - if (!lw && !pw) { - //keep the reference while the layout is orphan - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::Object::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); - } else { - if (!lw) - lw = pw; - - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(lw)); - Shiboken::Object::setParent(pyParent, pyChild); - } -} - -inline void addLayoutOwnership(QLayout* layout, QLayout* other) -{ - //transfer all children widgets from other to layout parent widget - QWidget* parent = layout->parentWidget(); - if (!parent) { - //keep the reference while the layout is orphan - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(other)); - Shiboken::Object::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); - return; - } - - for (int i=0, i_max=other->count(); i < i_max; i++) { - QLayoutItem* item = other->itemAt(i); - if (PyErr_Occurred() || !item) - return; - - addLayoutOwnership(layout, item); - } - - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(other)); - Shiboken::Object::setParent(pyParent, pyChild); - -} - -inline void addLayoutOwnership(QLayout* layout, QLayoutItem* item) -{ - if (!item) - return; - - QWidget* w = item->widget(); - if (w) - addLayoutOwnership(layout, w); - else { - QLayout* l = item->layout(); - if (l) - addLayoutOwnership(layout, l); - } - - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(item)); - Shiboken::Object::setParent(pyParent, pyChild); -} - -static void removeWidgetFromLayout(QLayout* layout, QWidget* widget) -{ - QWidget* parent = widget->parentWidget(); - - if (!parent) { - //remove reference on layout - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(widget)); - Shiboken::Object::removeReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild); - } else { - //give the ownership to parent - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(parent)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(widget)); - Shiboken::Object::setParent(pyParent, pyChild); - } -} - -inline void removeLayoutOwnership(QLayout* layout, QLayoutItem* item) -{ - QWidget* w = item->widget(); - if (w) - removeWidgetFromLayout(layout, w); - else { - QLayout* l = item->layout(); - if (l) - removeLayoutOwnership(layout, l); - } - - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(item)); - Shiboken::Object::invalidate(pyChild); - Shiboken::Object::setParent(0, pyChild); -} - -inline void removeLayoutOwnership(QLayout* layout, QWidget* widget) -{ - if (!widget) - return; - - for (int i=0, i_max=layout->count(); i < i_max; i++) { - QLayoutItem* item = layout->itemAt(i); - if (PyErr_Occurred() || !item) - return; - if (item->widget() == widget) - removeLayoutOwnership(layout, item); - } -} - -#endif diff --git a/PySide/QtGui/glue/qmenu_glue.cpp b/PySide/QtGui/glue/qmenu_glue.cpp new file mode 100644 index 000000000..0636dfab0 --- /dev/null +++ b/PySide/QtGui/glue/qmenu_glue.cpp @@ -0,0 +1,21 @@ +inline PyObject* addActionWithPyObject(QMenu* self, const QIcon& icon, const QString& text, PyObject* callback, const QKeySequence& shortcut) +{ + QAction* act = new QAction(text, self); + + if (!icon.isNull()) + act->setIcon(icon); + + if (!shortcut.isEmpty()) + act->setShortcut(shortcut); + + self->addAction(act); + + PyObject* pyAct = %CONVERTTOPYTHON[QAction*](act); + Shiboken::AutoDecRef result(PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, SIGNAL(triggered()), callback)); + if (result.isNull()) { + Py_DECREF(pyAct); + return 0; + } + + return pyAct; +} diff --git a/PySide/QtGui/glue/qmenu_glue.h b/PySide/QtGui/glue/qmenu_glue.h deleted file mode 100644 index 94eab15e0..000000000 --- a/PySide/QtGui/glue/qmenu_glue.h +++ /dev/null @@ -1,22 +0,0 @@ - -inline PyObject* addActionWithPyObject(QMenu* self, const QIcon& icon, const QString& text, PyObject* callback, const QKeySequence& shortcut) -{ - QAction* act = new QAction(text, self); - - if (!icon.isNull()) - act->setIcon(icon); - - if (!shortcut.isEmpty()) - act->setShortcut(shortcut); - - self->addAction(act); - - PyObject* pyAct = Shiboken::Converter::toPython(act); - Shiboken::AutoDecRef result(PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, SIGNAL(triggered()), callback)); - if (result.isNull()) { - Py_DECREF(pyAct); - return 0; - } - - return pyAct; -} diff --git a/PySide/QtGui/glue/qmenubar_glue.cpp b/PySide/QtGui/glue/qmenubar_glue.cpp new file mode 100644 index 000000000..2326a76cc --- /dev/null +++ b/PySide/QtGui/glue/qmenubar_glue.cpp @@ -0,0 +1,20 @@ +inline PyObject* +addActionWithPyObject(QMenuBar* self, const QString& text, PyObject* callback) +{ + QAction* act = new QAction(text, self); + + self->addAction(act); + + PyObject* pyAct = %CONVERTTOPYTHON[QAction*](act); + PyObject* result = PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, + SIGNAL(triggered(bool)), callback); + + if (result == 0 || result == Py_False) { + if (result) + Py_DECREF(result); + Py_DECREF(pyAct); + return 0; + } + + return pyAct; +} diff --git a/PySide/QtGui/glue/qmenubar_glue.h b/PySide/QtGui/glue/qmenubar_glue.h deleted file mode 100644 index 9568fa87c..000000000 --- a/PySide/QtGui/glue/qmenubar_glue.h +++ /dev/null @@ -1,20 +0,0 @@ -inline PyObject* -addActionWithPyObject(QMenuBar* self, const QString& text, PyObject* callback) -{ - QAction* act = new QAction(text, self); - - self->addAction(act); - - PyObject* pyAct = Shiboken::Converter::toPython(act); - PyObject* result = PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, - SIGNAL(triggered(bool)), callback); - - if (result == 0 || result == Py_False) { - if (result) - Py_DECREF(result); - Py_DECREF(pyAct); - return 0; - } - - return pyAct; -} diff --git a/PySide/QtGui/glue/qtgui_qapp.cpp b/PySide/QtGui/glue/qtgui_qapp.cpp index 4c4508b70..5148b579b 100644 --- a/PySide/QtGui/glue/qtgui_qapp.cpp +++ b/PySide/QtGui/glue/qtgui_qapp.cpp @@ -1,6 +1,6 @@ // Init qApp macro to None. if (qApp) { - PyObject* pyApp = Shiboken::Converter::toPython(qApp); + PyObject* pyApp = %CONVERTTOPYTHON[QApplication*](qApp); Py_INCREF(pyApp); PyModule_AddObject(module, "qApp", pyApp); } else { diff --git a/PySide/QtGui/glue/qwidget_glue.cpp b/PySide/QtGui/glue/qwidget_glue.cpp new file mode 100644 index 000000000..cfa3f6757 --- /dev/null +++ b/PySide/QtGui/glue/qwidget_glue.cpp @@ -0,0 +1,65 @@ +static QString retrieveObjectName(PyObject *obj) +{ + Shiboken::AutoDecRef objName(PyObject_Str(obj)); + return QString(Shiboken::String::toCString(objName)); +} + + +/** + * Tranfer objects ownership from layout to widget + **/ +static inline void qwidgetReparentLayout(QWidget *parent, QLayout *layout) +{ + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](parent)); + + for (int i=0; i < layout->count(); i++) { + QLayoutItem* item = layout->itemAt(i); + if (PyErr_Occurred() || !item) + return; + + QWidget* w = item->widget(); + if (w) { + QWidget* pw = w->parentWidget(); + if (pw != parent) { + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](w)); + Shiboken::Object::setParent(pyParent, pyChild); + } + } else { + QLayout* l = item->layout(); + if (l) + qwidgetReparentLayout(parent, l); + } + } + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::Object::setParent(pyParent, pyChild); + //remove previous references + Shiboken::Object::keepReference(reinterpret_cast(pyChild.object()), qPrintable(retrieveObjectName(pyChild)), Py_None); +} + +static inline void qwidgetSetLayout(QWidget *self, QLayout *layout) +{ + if (!layout || self->layout()) + return; + + QObject* oldParent = layout->parent(); + if (oldParent && oldParent != self) { + if (oldParent->isWidgetType()) { + // remove old parent policy + Shiboken::AutoDecRef pyLayout(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::Object::setParent(Py_None, pyLayout); + } else { + PyErr_Format(PyExc_RuntimeError, "QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", + qPrintable(layout->objectName()), self->metaObject()->className(), qPrintable(self->objectName())); + return; + } + } + + if (oldParent != self) { + qwidgetReparentLayout(self, layout); + if (PyErr_Occurred()) + return; + + self->setLayout(layout); + } +} diff --git a/PySide/QtGui/glue/qwidget_glue.h b/PySide/QtGui/glue/qwidget_glue.h deleted file mode 100644 index 931a5288e..000000000 --- a/PySide/QtGui/glue/qwidget_glue.h +++ /dev/null @@ -1,65 +0,0 @@ -static QString retrieveObjectName(PyObject *obj) -{ - Shiboken::AutoDecRef objName(PyObject_Str(obj)); - return QString(Shiboken::String::toCString(objName)); -} - - -/** - * Tranfer objects ownership from layout to widget - **/ -static inline void qwidgetReparentLayout(QWidget *parent, QLayout *layout) -{ - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(parent)); - - for (int i=0; i < layout->count(); i++) { - QLayoutItem* item = layout->itemAt(i); - if (PyErr_Occurred() || !item) - return; - - QWidget* w = item->widget(); - if (w) { - QWidget* pw = w->parentWidget(); - if (pw != parent) { - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(w)); - Shiboken::Object::setParent(pyParent, pyChild); - } - } else { - QLayout* l = item->layout(); - if (l) - qwidgetReparentLayout(parent, l); - } - } - - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(layout)); - Shiboken::Object::setParent(pyParent, pyChild); - //remove previous references - Shiboken::Object::keepReference(reinterpret_cast(pyChild.object()), qPrintable(retrieveObjectName(pyChild)), Py_None); -} - -static inline void qwidgetSetLayout(QWidget *self, QLayout *layout) -{ - if (!layout || self->layout()) - return; - - QObject* oldParent = layout->parent(); - if (oldParent && oldParent != self) { - if (oldParent->isWidgetType()) { - // remove old parent policy - Shiboken::AutoDecRef pyLayout(Shiboken::Converter::toPython(layout)); - Shiboken::Object::setParent(Py_None, pyLayout); - } else { - PyErr_Format(PyExc_RuntimeError, "QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", - qPrintable(layout->objectName()), self->metaObject()->className(), qPrintable(self->objectName())); - return; - } - } - - if (oldParent != self) { - qwidgetReparentLayout(self, layout); - if (PyErr_Occurred()) - return; - - self->setLayout(layout); - } -} diff --git a/PySide/QtGui/glue/wid_conversions.h b/PySide/QtGui/glue/wid_conversions.h deleted file mode 100644 index 68d752884..000000000 --- a/PySide/QtGui/glue/wid_conversions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef Q_WS_WIN - -namespace Shiboken { -template <> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return false; - } - - static bool isConvertible(PyObject* pyobj) - { - return pyobj == Py_None || PyNumber_Check(pyobj); - } - - static inline PyObject* toPython(void* cppobj) - { - // not supported - Q_ASSERT(true); - return 0; - } - - static PyObject* toPython(WId cppobj) - { - return PyLong_FromVoidPtr((void*)cppobj); - } - - static WId toCpp(PyObject* pyobj) - { - if (pyobj == Py_None) - return 0; - return (WId)PyLong_AsVoidPtr(pyobj); - } -}; - -} - -#endif diff --git a/PySide/QtGui/qpixmap_conversion.h b/PySide/QtGui/qpixmap_conversion.h deleted file mode 100644 index fc49af6be..000000000 --- a/PySide/QtGui/qpixmap_conversion.h +++ /dev/null @@ -1,49 +0,0 @@ -namespace Shiboken { -inline bool Converter::checkType(PyObject* pyObj) -{ - return ValueTypeConverter::checkType(pyObj); -} - -inline bool Converter::isConvertible(PyObject* pyobj) -{ - if (ValueTypeConverter::isConvertible(pyobj)) - return true; - SbkObjectType* shiboType = reinterpret_cast(SbkType()); - bool isVariant = Shiboken::Converter::checkType(pyobj); - if (isVariant) { - QVariant var(Shiboken::Converter::toCpp(pyobj)); - return var.type() == QVariant::Pixmap; - } else if (Shiboken::Converter::checkType(pyobj) || Shiboken::Converter::checkType(pyobj)) { - return true; - } else { - return Shiboken::ObjectType::isExternalConvertible(shiboType, pyobj); - } - return false; - -} - -inline QPixmap Converter::toCpp(PyObject* pyobj) -{ - SbkObjectType* shiboType = reinterpret_cast(SbkType()); - bool isVariant = Converter::checkType(pyobj); - if (isVariant) { - QVariant var(Converter::toCpp(pyobj)); - return var.value(); - } else if (Converter::checkType(pyobj)) { - return QPixmap(Shiboken::Converter::toCpp(pyobj)); - } else if (Converter::checkType(pyobj)) { - return QPixmap(Shiboken::Converter::toCpp(pyobj)); - } else if (Shiboken::ObjectType::isExternalConvertible(shiboType, pyobj) && Shiboken::ObjectType::hasExternalCppConversions(shiboType)) { - QPixmap* cptr = reinterpret_cast(Shiboken::ObjectType::callExternalCppConversion(shiboType, pyobj)); - std::auto_ptr cptr_auto_ptr(cptr); - return *cptr; - } - - return *Converter::toCpp(pyobj); -} - -inline PyObject* Converter::toPython(const QPixmap& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} -} diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml index 6922bcfa9..e9058b563 100644 --- a/PySide/QtGui/typesystem_gui_common.xml +++ b/PySide/QtGui/typesystem_gui_common.xml @@ -798,7 +798,14 @@ free(xpm); - + + + + + + + + @@ -2357,9 +2364,7 @@ - - - + @@ -2453,9 +2458,7 @@ - - - + @@ -3136,10 +3139,7 @@ - - - - + @@ -3239,9 +3239,7 @@ - - - + @@ -3251,9 +3249,7 @@ - - - + @@ -3297,9 +3293,7 @@ - - - + @@ -4027,9 +4021,10 @@ - + + @@ -5687,9 +5682,7 @@ - - - + diff --git a/PySide/QtGui/typesystem_gui_win.xml b/PySide/QtGui/typesystem_gui_win.xml index 93d422a22..387964d2b 100644 --- a/PySide/QtGui/typesystem_gui_win.xml +++ b/PySide/QtGui/typesystem_gui_win.xml @@ -20,7 +20,7 @@ --> - + #ifdef IS_PY3K return PyCapsule_New(%in, 0, 0); diff --git a/PySide/QtUiTools/glue/uitools_loadui.cpp b/PySide/QtUiTools/glue/uitools_loadui.cpp new file mode 100644 index 000000000..829adf7d0 --- /dev/null +++ b/PySide/QtUiTools/glue/uitools_loadui.cpp @@ -0,0 +1,52 @@ +/* + * Based on code provided by: + * Antonio Valentino + * Frédéric + */ + +#include +#include +#include +#include + +static void createChildrenNameAttributes(PyObject* root, QObject* object) +{ + foreach (QObject* child, object->children()) { + const QByteArray name = child->objectName().toLocal8Bit(); + + if (!name.isEmpty() && !name.startsWith("_") && !name.startsWith("qt_")) { + bool hasAttr = PyObject_HasAttrString(root, name.constData()); + if (!hasAttr) { + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject*](child)); + PyObject_SetAttrString(root, name.constData(), pyChild); + } + createChildrenNameAttributes(root, child); + } + createChildrenNameAttributes(root, child); + } +} + +static PyObject* QUiLoadedLoadUiFromDevice(QUiLoader* self, QIODevice* dev, QWidget* parent) +{ + QWidget* wdg = self->load(dev, parent); + + if (wdg) { + PyObject* pyWdg = %CONVERTTOPYTHON[QWidget*](wdg); + createChildrenNameAttributes(pyWdg, wdg); + if (parent) { + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](parent)); + Shiboken::Object::setParent(pyParent, pyWdg); + } + return pyWdg; + } + + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Unable to open/read ui device"); + return 0; +} + +static PyObject* QUiLoaderLoadUiFromFileName(QUiLoader* self, const QString& uiFile, QWidget* parent) +{ + QFile fd(uiFile); + return QUiLoadedLoadUiFromDevice(self, &fd, parent); +} diff --git a/PySide/QtUiTools/glue/uitools_loadui.h b/PySide/QtUiTools/glue/uitools_loadui.h deleted file mode 100644 index 654ba0aa1..000000000 --- a/PySide/QtUiTools/glue/uitools_loadui.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Based on code provided by: - * Antonio Valentino - * Frédéric - */ - -#include -#include -#include -#include - -static void createChildrenNameAttributes(PyObject* root, QObject* object) -{ - foreach (QObject* child, object->children()) { - const QByteArray name = child->objectName().toLocal8Bit(); - - if (!name.isEmpty() && !name.startsWith("_") && !name.startsWith("qt_")) { - bool hasAttr = PyObject_HasAttrString(root, name.constData()); - if (!hasAttr) { - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(child)); - PyObject_SetAttrString(root, name.constData(), pyChild); - } - createChildrenNameAttributes(root, child); - } - createChildrenNameAttributes(root, child); - } -} - -static PyObject* QUiLoadedLoadUiFromDevice(QUiLoader* self, QIODevice* dev, QWidget* parent) -{ - QWidget* wdg = self->load(dev, parent); - - if (wdg) { - PyObject* pyWdg = Shiboken::Converter::toPython(wdg); - - createChildrenNameAttributes(pyWdg, wdg); - if (parent) { - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(parent)); - Shiboken::Object::setParent(pyParent, pyWdg); - } - - return pyWdg; - } - - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Unable to open/read ui device"); - return 0; -} - -static PyObject* QUiLoaderLoadUiFromFileName(QUiLoader* self, const QString& uiFile, QWidget* parent) -{ - QFile fd(uiFile); - return QUiLoadedLoadUiFromDevice(self, &fd, parent); -} diff --git a/PySide/QtUiTools/typesystem_uitools.xml b/PySide/QtUiTools/typesystem_uitools.xml index d7e405b96..c86ae4499 100644 --- a/PySide/QtUiTools/typesystem_uitools.xml +++ b/PySide/QtUiTools/typesystem_uitools.xml @@ -26,6 +26,7 @@ + Q_IMPORT_PLUGIN(uiplugin); @@ -94,9 +95,6 @@ - - - @@ -112,9 +110,6 @@ - - - diff --git a/PySide/QtWebKit/typesystem_webkit.xml b/PySide/QtWebKit/typesystem_webkit.xml index ac57dd1f0..86b8431a0 100644 --- a/PySide/QtWebKit/typesystem_webkit.xml +++ b/PySide/QtWebKit/typesystem_webkit.xml @@ -98,11 +98,11 @@ // Cast the parameters according to the extension type if (extension == QWebPage::ChooseMultipleFilesExtension) { const ChooseMultipleFilesExtension$TYPE_SUFFIX* _in = reinterpret_cast<const ChooseMultipleFilesExtension$TYPE_SUFFIX*>(%in); - %out = %CONVERTTOPYTHON[const ChooseMultipleFilesExtension$TYPE_SUFFIX*](_in); + %out = %CONVERTTOPYTHON[const QWebPage::ChooseMultipleFilesExtension$TYPE_SUFFIX*](_in); #if QT_VERSION >= 0x040600 } else if (extension == QWebPage::ErrorPageExtension) { const ErrorPageExtension$TYPE_SUFFIX* _in = reinterpret_cast<const ErrorPageExtension$TYPE_SUFFIX*>(%in); - %out = %CONVERTTOPYTHON[const ErrorPageExtension$TYPE_SUFFIX*](_in); + %out = %CONVERTTOPYTHON[const QWebPage::ErrorPageExtension$TYPE_SUFFIX*](_in); #endif } -- cgit v1.2.3