diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a6f6f58..696b4e30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,10 @@ project(pysidebindings) cmake_minimum_required(VERSION 2.6) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Macros/ ${CMAKE_MODULE_PATH}) -find_package(GeneratorRunner 0.6.3 REQUIRED) -find_package(Shiboken 1.0.0 REQUIRED) +find_package(GeneratorRunner 0.6.16 REQUIRED) +find_package(Shiboken 1.1.0 REQUIRED) find_package(Qt4 4.5.0 REQUIRED) +find_file(GL_H "gl.h" PATH_SUFFIXES "GL") include(FindQt4Extra) set(XVFB_EXEC "") @@ -15,11 +16,12 @@ option(USE_XVFB "Uses xvfb-run with the unit tests to avoid QtGui tests popping if(USE_XVFB) find_program(XVFB_RUN NAMES xvfb-run) if (NOT ${XVFB_RUN} MATCHES "XVFB_RUN-NOTFOUND") - set(XVFB_EXEC ${XVFB_RUN}) + set(XVFB_EXEC ${XVFB_RUN} -a) message(STATUS "Using xvfb-run to perform QtGui tests.") endif() endif() +option(BUILD_TESTS "Build tests." TRUE) option(ENABLE_VERSION_SUFFIX "Used to use current version in suffix to generated files. This is used to allow multiples versions installed simultaneous." FALSE) set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE) @@ -30,7 +32,7 @@ endif() if(MSVC) set(CMAKE_CXX_FLAGS "/Zc:wchar_t- /GR /EHsc /DNOCOLOR /DWIN32 /D_WINDOWS /D_SCL_SECURE_NO_WARNINGS") else() - if(CMAKE_HOST_UNIX) + if(CMAKE_HOST_UNIX AND NOT CYGWIN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fvisibility=hidden -Wno-strict-aliasing") endif() set(CMAKE_CXX_FLAGS_DEBUG "-g") @@ -55,14 +57,23 @@ else() endif() if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) + set(CMAKE_BUILD_TYPE ${SHIBOKEN_BUILD_TYPE}) endif() set(BINDING_NAME PySide) set(BINDING_API_MAJOR_VERSION "1") -set(BINDING_API_MINOR_VERSION "0") -set(BINDING_API_MICRO_VERSION "0") +set(BINDING_API_MINOR_VERSION "1") +set(BINDING_API_MICRO_VERSION "1") +set(BINDING_API_RELEASE_LEVEL "final") # alpha, beta, rc, or final +set(BINDING_API_SERIAL 1) # leave as 0 when release level is final set(BINDING_API_VERSION "${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}.${BINDING_API_MICRO_VERSION}" CACHE STRING "PySide version" FORCE) +if (BINDING_API_RELEASE_LEVEL STREQUAL "final") + set(BINDING_API_VERSION_FULL "${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}.${BINDING_API_MICRO_VERSION}" + CACHE STRING "PySide version [full]" FORCE) +else() + set(BINDING_API_VERSION_FULL "${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}.${BINDING_API_MICRO_VERSION}~${BINDING_API_RELEASE_LEVEL}${BINDING_API_SERIAL}" + CACHE STRING "PySide version [full]" FORCE) +endif() set(PYSIDE_QT_VERSION "${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" CACHE STRING "Qt version used to compile PySide" FORCE) if(ENABLE_VERSION_SUFFIX) set(pyside_SUFFIX "-${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}") @@ -106,11 +117,7 @@ else() endif() # Define supported Qt Version -if(${QT_VERSION_MAJOR} EQUAL 4 AND ${QT_VERSION_MINOR} GREATER 6) - set(SUPPORTED_QT_VERSION 4.7) -else() - set(SUPPORTED_QT_VERSION 4.6) -endif() +set(SUPPORTED_QT_VERSION "${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}") set(BINDING_VERSION ${BINDING_API_VERSION}.${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}) @@ -122,7 +129,7 @@ add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") -set(ARCHIVE_NAME pyside-qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}+${BINDING_API_VERSION}) +set(ARCHIVE_NAME pyside-qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}+${BINDING_API_VERSION_FULL}) add_custom_target(dist COMMAND mkdir -p "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}" && git log > "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}/ChangeLog" && @@ -135,7 +142,7 @@ add_custom_target(dist if (NOT SITE_PACKAGE) execute_process( COMMAND ${SHIBOKEN_PYTHON_INTERPRETER} -c "from distutils import sysconfig; \\ - print sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}')" + print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE SITE_PACKAGE OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT SITE_PACKAGE) @@ -145,9 +152,14 @@ if (NOT SITE_PACKAGE) endif() endif() -set(GENERATOR_EXTRA_FLAGS --generatorSet=shiboken --enable-parent-ctor-heuristic --enable-pyside-extensions --enable-return-value-heuristic) - -enable_testing() +set(GENERATOR_EXTRA_FLAGS --generator-set=shiboken --enable-parent-ctor-heuristic --enable-pyside-extensions --enable-return-value-heuristic --use-isnull-as-nb_nonzero) +if(WIN32 OR DEFINED AVOID_PROTECTED_HACK) + message(STATUS "PySide will be generated avoiding the protected hack!") + set(GENERATOR_EXTRA_FLAGS ${GENERATOR_EXTRA_FLAGS} --avoid-protected-hack) + add_definitions(-DAVOID_PROTECTED_HACK) +else() + message(STATUS "PySide will be generated using the protected hack!") +endif() add_subdirectory(libpyside) if(QT_QTUITOOLS_FOUND AND QT_QTDESIGNER_FOUND) @@ -155,7 +167,10 @@ if(QT_QTUITOOLS_FOUND AND QT_QTDESIGNER_FOUND) endif() # project directories add_subdirectory(PySide) -add_subdirectory(tests) +if (BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif () find_program(DOT_EXEC dot) if (QT_SRC_DIR AND DOT_EXEC) diff --git a/PySide/CMakeLists.txt b/PySide/CMakeLists.txt index 3b85e3d4..d8371c0b 100644 --- a/PySide/CMakeLists.txt +++ b/PySide/CMakeLists.txt @@ -1,19 +1,14 @@ project(pyside) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" "${CMAKE_CURRENT_BINARY_DIR}/private.py" - DESTINATION "${SITE_PACKAGE}/${BINDING_NAME}${pyside_SUFFIX}") include(PySideModules) # Configure include based on platform configure_file("${CMAKE_CURRENT_SOURCE_DIR}/global.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/global.h" @ONLY) + "${CMAKE_CURRENT_BINARY_DIR}/pyside_global.h" @ONLY) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY) -execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/private.py" - "${CMAKE_BINARY_DIR}/PySide/private.py") - HAS_QT_MODULE(QT_QTCORE_FOUND QtCore) HAS_QT_MODULE(QT_QTGUI_FOUND QtGui) HAS_QT_MODULE(QT_QTNETWORK_FOUND QtNetwork) @@ -23,7 +18,9 @@ HAS_QT_MODULE(QT_QTXML_FOUND QtXml) HAS_QT_MODULE(QT_QTTEST_FOUND QtTest) HAS_QT_MODULE(QT_QTOPENGL_FOUND QtOpenGL) HAS_QT_MODULE(QT_QTSQL_FOUND QtSql) -HAS_QT_MODULE(QT_QTUITOOLS_FOUND QtUiTools) +if(QT_QTDESIGNER_FOUND) + HAS_QT_MODULE(QT_QTUITOOLS_FOUND QtUiTools) +endif() HAS_QT_MODULE(QT_QTHELP_FOUND QtHelp) HAS_QT_MODULE(QT_QTXMLPATTERNS_FOUND QtXmlPatterns) HAS_QT_MODULE(QT_QTMAEMO5_FOUND QtMaemo5) @@ -34,6 +31,10 @@ HAS_QT_MODULE(QT_PHONON_FOUND phonon) HAS_QT_MODULE(QT_QTDECLARATIVE_FOUND QtDeclarative) # install +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" + DESTINATION "${SITE_PACKAGE}/${BINDING_NAME}${pyside_SUFFIX}") install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_templates.xml DESTINATION share/PySide${pyside_SUFFIX}/typesystems) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pyside_global.h + DESTINATION include/${BINDING_NAME}${pyside_SUFFIX}) diff --git a/PySide/QtCore/CMakeLists.txt b/PySide/QtCore/CMakeLists.txt index 056597cd..a2337c0a 100644 --- a/PySide/QtCore/CMakeLists.txt +++ b/PySide/QtCore/CMakeLists.txt @@ -1,5 +1,7 @@ project(QtCore) +set(QtCore_gluecode "${CMAKE_CURRENT_SOURCE_DIR}/glue/qeasingcurve_glue.cpp") + if (${QT_VERSION_MAJOR} EQUAL 4 AND ${QT_VERSION_MINOR} LESS 6) set (QtCore_46_SRC ) else() @@ -34,7 +36,14 @@ else() ) endif() - +if(ENABLE_WIN) + set(SPECIFIC_OS_FILES + ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/msg_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/point_wrapper.cpp + ) +else() + set(SPECIFIC_OS_FILES "") +endif() set(QtCore_SRC ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qabstracteventdispatcher_wrapper.cpp @@ -60,7 +69,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qdiriterator_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qdynamicpropertychangeevent_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qevent_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qeventloop_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/${BINDING_NAME}/QtCore/qfactoryinterface_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfactoryinterface_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfile_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfileinfo_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfilesystemwatcher_wrapper.cpp @@ -135,9 +144,14 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qxmlstreamreader_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qxmlstreamwriter_wrapper.cpp ${QtCore_46_SRC} ${QtCore_47_SRC} +${SPECIFIC_OS_FILES} ) -set(QtCore_typesystem_path "") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/typesystem_core.xml.in" + "${CMAKE_CURRENT_BINARY_DIR}/typesystem_core.xml" @ONLY) + +set(QtCore_typesystem_path "${QtCore_SOURCE_DIR}") + set(QtCore_include_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${BINDING_NAME}/QtCore/ ${QT_INCLUDE_DIR} @@ -155,4 +169,5 @@ create_pyside_module(QtCore "" QtCore_typesystem_path QtCore_SRC - "") + QtCore_gluecode + ${CMAKE_CURRENT_BINARY_DIR}/typesystem_core.xml) diff --git a/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp b/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp index 03ffcb4a..acc7bb93 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/qcoreapplication_init.cpp b/PySide/QtCore/glue/qcoreapplication_init.cpp index 0c0e1f8f..c92f03e0 100644 --- a/PySide/QtCore/glue/qcoreapplication_init.cpp +++ b/PySide/QtCore/glue/qcoreapplication_init.cpp @@ -2,43 +2,23 @@ static int QCoreApplicationArgCount; static char** QCoreApplicationArgValues; -int Sbk_QCoreApplication_Init(PyObject* self, PyObject* args, PyObject*) +void QCoreApplication_constructor(PyObject* self, PyObject* args, QCoreApplicationWrapper** cptr) { - if (Shiboken::Object::isUserType(self) && !Shiboken::ObjectType::canCallConstructor(self->ob_type, Shiboken::SbkType())) - return -1; - - if (QCoreApplication::instance()) { PyErr_SetString(PyExc_RuntimeError, "A QCoreApplication instance already exists."); - return -1; + return; } int numArgs = PyTuple_GET_SIZE(args); - if (numArgs != 1) { + if (numArgs != 1 + || !Shiboken::sequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) { PyErr_BadArgument(); - return -1; + return; } - if (!Shiboken::sequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) { - PyErr_BadArgument(); - return -1; - } - - SbkObject* sbkSelf = reinterpret_cast(self); - QCoreApplicationWrapper* cptr = new QCoreApplicationWrapper(QCoreApplicationArgCount, QCoreApplicationArgValues); - Shiboken::Object::setCppPointer(sbkSelf, - Shiboken::SbkType(), - cptr); - - Shiboken::Object::setValidCpp(sbkSelf, true); - Shiboken::Object::setHasCppWrapper(sbkSelf, true); - Shiboken::Object::releaseOwnership(sbkSelf); - - Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr); - PySide::Signal::updateSourceObject(self); - cptr->metaObject(); + *cptr = new QCoreApplicationWrapper(QCoreApplicationArgCount, QCoreApplicationArgValues); + Shiboken::Object::releaseOwnership(reinterpret_cast(self)); PySide::registerCleanupFunction(&PySide::destroyQCoreApplication); Py_INCREF(self); - return 1; } diff --git a/PySide/QtCore/glue/qeasingcurve_glue.cpp b/PySide/QtCore/glue/qeasingcurve_glue.cpp new file mode 100644 index 00000000..7f56315b --- /dev/null +++ b/PySide/QtCore/glue/qeasingcurve_glue.cpp @@ -0,0 +1,120 @@ +#include +#include +#include +#include + +#include "glue/qeasingcurve_glue.h" + +#define __ECF_ATT_NAME__ "__ecf__" +#define MAX_CUSTOM_FUNCTIONS 10 + +static void deleteData(void* data); + +struct CustomFunctionsData +{ + static CustomFunctionsData m_list[MAX_CUSTOM_FUNCTIONS]; + + PySideEasingCurveFunctor* m_obj; + QEasingCurve::EasingFunction m_func; +}; + +CustomFunctionsData CustomFunctionsData::m_list[MAX_CUSTOM_FUNCTIONS]; + +template +struct CustomFunctions +{ + static void init() + { + CustomFunctionsData data; + data.m_obj = 0; + data.m_func = &CustomFunctions::callback; + CustomFunctionsData::m_list[N] = data; + + CustomFunctions::init(); + } + + static qreal callback(qreal v) + { + return (*CustomFunctionsData::m_list[N].m_obj)(v); + } +}; + +template<> +struct CustomFunctions<0> +{ + static void init() + { + CustomFunctionsData data; + data.m_obj = 0; + data.m_func = &CustomFunctions<0>::callback; + CustomFunctionsData::m_list[0] = data; + } + + static qreal callback(qreal v) + { + return (*CustomFunctionsData::m_list[0].m_obj)(v); + } +}; + +void deleteData(void* data) +{ + delete (PySideEasingCurveFunctor*)(data); +} + +void PySideEasingCurveFunctor::init() +{ + CustomFunctions::init(); +} + +QEasingCurve::EasingFunction PySideEasingCurveFunctor::createCustomFuntion(PyObject* parent, PyObject* pyFunc) +{ + for(int i=0; i < MAX_CUSTOM_FUNCTIONS; i++) { + CustomFunctionsData& data = CustomFunctionsData::m_list[i]; + if (data.m_obj == 0) { + data.m_obj = new PySideEasingCurveFunctor(i, parent, pyFunc); + return data.m_func; + } + } + //PyErr_Format(PyExc_RuntimeError, "PySide only supports %d custom functions simultaneously.", MAX_CUSTOM_FUNCTIONS); + return 0; +} + +PySideEasingCurveFunctor::~PySideEasingCurveFunctor() +{ + + CustomFunctionsData::m_list[m_index].m_obj = 0; + PyObject_SetAttrString(m_parent, __ECF_ATT_NAME__, Py_None); +} + +qreal PySideEasingCurveFunctor::operator()(qreal progress) +{ + Shiboken::GilState state; + PyObject* args = Py_BuildValue("(f)", progress); + PyObject* result = PyObject_CallObject(m_func, args); + qreal cppResult = 0.0; + if (result) { + Shiboken::Conversions::pythonToCppCopy(Shiboken::Conversions::PrimitiveTypeConverter(), result, &cppResult); + Py_DECREF(result); + } + Py_DECREF(args); + return cppResult; +} + +PyObject* PySideEasingCurveFunctor::callable() +{ + Py_INCREF(m_func); + return m_func; +} + +PyObject* PySideEasingCurveFunctor::callable(PyObject* parent) +{ + return PyObject_GetAttrString(parent, __ECF_ATT_NAME__); +} + +PySideEasingCurveFunctor::PySideEasingCurveFunctor(int index, PyObject* parent, PyObject* pyFunc) + : m_parent(parent), m_func(pyFunc), m_index(index) +{ + PyObject_SetAttrString(m_parent, __ECF_ATT_NAME__, m_func); + PySide::WeakRef::create(m_parent, deleteData, this); +} + diff --git a/PySide/QtCore/glue/qeasingcurve_glue.h b/PySide/QtCore/glue/qeasingcurve_glue.h new file mode 100644 index 00000000..282e4391 --- /dev/null +++ b/PySide/QtCore/glue/qeasingcurve_glue.h @@ -0,0 +1,27 @@ +#ifndef __QEASINGCURVE_GLUE__ +#define __QEASINGCURVE_GLUE__ + +#include +#include + +class PySideEasingCurveFunctor +{ + public: + static void init(); + static QEasingCurve::EasingFunction createCustomFuntion(PyObject* parent, PyObject* pyFunc); + + qreal operator()(qreal progress); + + PyObject* callable(); //Return New reference + static PyObject* callable(PyObject* parent); //Return New reference + + ~PySideEasingCurveFunctor(); + private: + PyObject* m_parent; + PyObject* m_func; + int m_index; + + PySideEasingCurveFunctor(int index, PyObject* parent, PyObject *pyFunc); +}; + +#endif diff --git a/PySide/QtCore/glue/qobject_connect.cpp b/PySide/QtCore/glue/qobject_connect.cpp index 91c830ab..96bcfb22 100644 --- a/PySide/QtCore/glue/qobject_connect.cpp +++ b/PySide/QtCore/glue/qobject_connect.cpp @@ -1,23 +1,46 @@ -static bool getReceiver(PyObject* callback, QObject** receiver, PyObject** self) +static bool isDecorator(PyObject* method, PyObject* self) { + Shiboken::AutoDecRef methodName(PyObject_GetAttrString(method, "__name__")); + if (!PyObject_HasAttr(self, methodName)) + return true; + Shiboken::AutoDecRef otherMethod(PyObject_GetAttr(self, methodName)); + return reinterpret_cast(otherMethod.object())->im_func != \ + reinterpret_cast(method)->im_func; +} + +static bool getReceiver(QObject *source, const char* signal, PyObject* callback, QObject** receiver, PyObject** self, QByteArray* callbackSig) +{ + 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; *self = 0; } - bool usingGlobalReceiver = !*receiver; + bool usingGlobalReceiver = !*receiver || forceGlobalReceiver; + + // Check if this callback is a overwrite of a non-virtual Qt slot. + if (!usingGlobalReceiver && receiver && self) { + *callbackSig = PySide::Signal::getCallbackSignature(signal, *receiver, callback, usingGlobalReceiver).toAscii(); + const QMetaObject* metaObject = (*receiver)->metaObject(); + int slotIndex = metaObject->indexOfSlot(callbackSig->constData()); + if (slotIndex != -1 && slotIndex < metaObject->methodOffset() && PyMethod_Check(callback)) + usingGlobalReceiver = true; + } + if (usingGlobalReceiver) { PySide::SignalManager& signalManager = PySide::SignalManager::instance(); - *receiver = signalManager.globalReceiver(); + *receiver = signalManager.globalReceiver(source, callback); + *callbackSig = PySide::Signal::getCallbackSignature(signal, *receiver, callback, usingGlobalReceiver).toAscii(); } return usingGlobalReceiver; @@ -47,40 +70,48 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject return false; signal++; - if (!PySide::SignalManager::registerMetaMethod(source, signal, QMetaMethod::Signal)) + int signalIndex = PySide::SignalManager::registerMetaMethodGetIndex(source, signal, QMetaMethod::Signal); + if (signalIndex == -1) return false; - int signalIndex = source->metaObject()->indexOfMethod(signal); - PySide::SignalManager& signalManager = PySide::SignalManager::instance(); // Extract receiver from callback QObject* receiver = 0; PyObject* self = 0; - bool usingGlobalReceiver = getReceiver(callback, &receiver, &self); + QByteArray callbackSig; + bool usingGlobalReceiver = getReceiver(source, signal, callback, &receiver, &self, &callbackSig); if (receiver == 0 && self == 0) return false; const QMetaObject* metaObject = receiver->metaObject(); - const QByteArray callbackSig = PySide::Signal::getCallbackSignature(signal, receiver, callback, usingGlobalReceiver).toAscii(); const char* slot = callbackSig.constData(); int slotIndex = metaObject->indexOfSlot(slot); + if (slotIndex == -1) { if (!usingGlobalReceiver && self && !Shiboken::Object::hasCppWrapper((SbkObject*)self)) { qWarning() << "You can't add dynamic slots on an object originated from C++."; + if (usingGlobalReceiver) + signalManager.releaseGlobalReceiver(source, receiver); + return false; } - if (usingGlobalReceiver) { - signalManager.addGlobalSlot(slot, callback); - } else { - if (!PySide::SignalManager::registerMetaMethod(receiver, slot, QMetaMethod::Slot)) - return false; + + if (usingGlobalReceiver) + slotIndex = signalManager.globalReceiverSlotIndex(receiver, slot); + else + slotIndex = PySide::SignalManager::registerMetaMethodGetIndex(receiver, slot, QMetaMethod::Slot); + + if (slotIndex == -1) { + if (usingGlobalReceiver) + signalManager.releaseGlobalReceiver(source, receiver); + + return false; } - slotIndex = metaObject->indexOfSlot(slot); } if (QMetaObject::connect(source, signalIndex, receiver, slotIndex, type)) { if (usingGlobalReceiver) - signalManager.globalReceiverConnectNotify(source, slotIndex); + signalManager.notifyGlobalReceiver(receiver); #ifndef AVOID_PROTECTED_HACK source->connectNotify(signal - 1); #else @@ -91,6 +122,10 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject return true; } + + if (usingGlobalReceiver) + signalManager.releaseGlobalReceiver(source, receiver); + return false; } @@ -105,27 +140,28 @@ static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObj // Extract receiver from callback QObject* receiver = 0; PyObject* self = 0; - bool usingGlobalReceiver = getReceiver(callback, &receiver, &self); + QByteArray callbackSig; + bool usingGlobalReceiver = getReceiver(NULL, signal, callback, &receiver, &self, &callbackSig); if (receiver == 0 && self == 0) return false; const QMetaObject* metaObject = receiver->metaObject(); - const QByteArray callbackSig = PySide::Signal::getCallbackSignature(signal, receiver, callback, usingGlobalReceiver).toAscii(); - QByteArray qtSlotName(callbackSig); - qtSlotName = qtSlotName.prepend('1'); - - if (QObject::disconnect(source, signal, receiver, qtSlotName.constData())) { - if (usingGlobalReceiver) { - int slotIndex = metaObject->indexOfSlot(callbackSig.constData()); - signalManager.globalReceiverDisconnectNotify(source, slotIndex); + int signalIndex = source->metaObject()->indexOfSignal(++signal); + int slotIndex = -1; + + slotIndex = metaObject->indexOfSlot(callbackSig); + + if (QMetaObject::disconnectOne(source, signalIndex, receiver, slotIndex)) { + if (usingGlobalReceiver) + signalManager.releaseGlobalReceiver(source, receiver); + #ifndef AVOID_PROTECTED_HACK - source->disconnectNotify(signal - 1); + source->disconnectNotify(callbackSig); #else // Need to cast to QObjectWrapper* and call the public version of // connectNotify when avoiding the protected hack. - reinterpret_cast(source)->disconnectNotify(signal - 1); + reinterpret_cast(source)->disconnectNotify(callbackSig); #endif - } return true; } return false; diff --git a/PySide/QtCore/glue/qobject_findchild.cpp b/PySide/QtCore/glue/qobject_findchild.cpp index 351aa69a..669beac4 100644 --- a/PySide/QtCore/glue/qobject_findchild.cpp +++ b/PySide/QtCore/glue/qobject_findchild.cpp @@ -17,14 +17,23 @@ static QObject* _findChildHelper(const QObject* parent, const QString& name, PyT return 0; } -static void _findChildrenHelper(const QObject* parent, const QString& name, PyTypeObject* desiredType, PyObject* result) +static inline bool _findChildrenComparator(const QObject*& child, const QRegExp& name) { - foreach(QObject* child, parent->children()) { + return name.indexIn(child->objectName()) != -1; +} + +static inline bool _findChildrenComparator(const QObject*& child, const QString& name) +{ + return name.isNull() || name == child->objectName(); +} + +template +static void _findChildrenHelper(const QObject* parent, const T& name, PyTypeObject* desiredType, PyObject* result) +{ + foreach(const QObject* child, parent->children()) { Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject*](child)); - if (PyType_IsSubtype(pyChild->ob_type, desiredType) - && (name.isNull() || name == child->objectName())) { + if (PyType_IsSubtype(pyChild->ob_type, desiredType) && _findChildrenComparator(child, name)) PyList_Append(result, pyChild); - } _findChildrenHelper(child, name, desiredType, result); } -} \ No newline at end of file +} diff --git a/PySide/QtCore/glue/qt_version.cpp b/PySide/QtCore/glue/qt_version.cpp deleted file mode 100644 index 66f8c004..00000000 --- a/PySide/QtCore/glue/qt_version.cpp +++ /dev/null @@ -1,5 +0,0 @@ -QList version = QByteArray(qVersion()).split('.'); -PyObject *pyQtVersion = Shiboken::makeTuple(version[0].toInt(), version[1].toInt(), version[2].toInt()); - -PyModule_AddStringConstant(module, "__version__", qVersion()); -PyModule_AddObject(module, "__version_info__", pyQtVersion); diff --git a/PySide/QtCore/qbool_conversions.h b/PySide/QtCore/qbool_conversions.h deleted file mode 100644 index f4fb43fa..00000000 --- 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/qchar_conversions.h b/PySide/QtCore/qchar_conversions.h deleted file mode 100644 index 1ebcb646..00000000 --- a/PySide/QtCore/qchar_conversions.h +++ /dev/null @@ -1,35 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return PyString_Check(pyObj) && (PyString_Size(pyObj) == 1); - } - - static bool isConvertible(PyObject* pyObj) - { - return (PyString_Check(pyObj) && (PyString_Size(pyObj) == 1)) - || pyObj == Py_None - || PyInt_Check(pyObj); - } - - static QChar toCpp(PyObject* pyObj) - { - if (PyString_Check(pyObj) && PyString_Size(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 e0f1dd95..00000000 --- a/PySide/QtCore/qdate_conversions.h +++ /dev/null @@ -1,35 +0,0 @@ -namespace Shiboken { -template <> -struct PythonConverter -{ - static bool isPythonConvertible(PyObject* pyObj) - { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return pyObj && PyDate_Check(pyObj); - } - - static QDate* transformFromPython(PyObject* obj) - { - if (isPythonConvertible(obj)) { - int day = PyDateTime_GET_DAY(obj); - int month = PyDateTime_GET_MONTH(obj); - int year = PyDateTime_GET_YEAR(obj); - return new QDate(year, month, day); - } - return 0; - } - - static PyObject* transformToPython(QDate* d) - { - if (d) { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return PyDate_FromDate(d->year(), d->month(), d->day()); - } - return 0; - } -}; -} diff --git a/PySide/QtCore/qdatetime_conversions.h b/PySide/QtCore/qdatetime_conversions.h deleted file mode 100644 index a3cdf092..00000000 --- a/PySide/QtCore/qdatetime_conversions.h +++ /dev/null @@ -1,41 +0,0 @@ -namespace Shiboken { -template <> -struct PythonConverter -{ - static bool isPythonConvertible(PyObject* pyObj) - { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return pyObj && PyDateTime_Check(pyObj); - } - - static QDateTime* transformFromPython(PyObject* obj) - { - if (isPythonConvertible(obj)) { - int day = PyDateTime_GET_DAY(obj); - int month = PyDateTime_GET_MONTH(obj); - int year = PyDateTime_GET_YEAR(obj); - int hour = PyDateTime_DATE_GET_HOUR(obj); - int min = PyDateTime_DATE_GET_MINUTE(obj); - int sec = PyDateTime_DATE_GET_SECOND(obj); - int msec = PyDateTime_DATE_GET_MICROSECOND(obj); - return new QDateTime(QDate(year, month, day), QTime(hour, min, sec, msec)); - } - return 0; - } - - static PyObject* transformToPython(QDateTime* d) - { - if (d) { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - QDate date = d->date(); - QTime time = d->time(); - return PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec()); - } - return 0; - } -}; -} diff --git a/PySide/QtCore/qhash_conversions.h b/PySide/QtCore/qhash_conversions.h deleted file mode 100644 index f9e2e421..00000000 --- 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 cb1d26bd..00000000 --- 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 3153fae9..00000000 --- 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 43abd84d..00000000 --- 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 99e9cd8b..00000000 --- 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 c46fef00..00000000 --- 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 709a9189..00000000 --- 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 bfb06f20..00000000 --- a/PySide/QtCore/qstring_conversions.h +++ /dev/null @@ -1,51 +0,0 @@ -namespace Shiboken { - -template<> -inline PyTypeObject* SbkType() -{ - return &PyUnicode_Type; -} - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return PyString_Check(pyObj) || PyUnicode_Check(pyObj); - } - - static bool isConvertible(PyObject* pyObj) - { - return PyString_Check(pyObj) - || PyUnicode_Check(pyObj) - || pyObj == Py_None; - } - - static QString toCpp(PyObject* pyObj) - { - if (PyUnicode_Check(pyObj)) { - Py_UNICODE* unicode = PyUnicode_AS_UNICODE(pyObj); - #if defined(Py_UNICODE_WIDE) - // 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 (PyString_Check(pyObj)) { - return QString(Converter::toCpp(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 6075c167..00000000 --- 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 db3eefca..00000000 --- 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 5e172fa0..00000000 --- a/PySide/QtCore/qtime_conversions.h +++ /dev/null @@ -1,36 +0,0 @@ -namespace Shiboken { -template <> -struct PythonConverter -{ - static bool isPythonConvertible(PyObject* pyObj) - { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return pyObj && PyTime_Check(pyObj); - } - - static QTime* transformFromPython(PyObject* obj) - { - if (isPythonConvertible(obj)) { - int hour = PyDateTime_TIME_GET_HOUR(obj); - int min = PyDateTime_TIME_GET_MINUTE(obj); - int sec = PyDateTime_TIME_GET_SECOND(obj); - int msec = PyDateTime_TIME_GET_MICROSECOND(obj); - return new QTime(hour, min, sec, msec); - } - return 0; - } - - static PyObject* transformToPython(QTime* d) - { - if (d) { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return PyTime_FromTime(d->hour(), d->minute(), d->second(), d->msec()); - } - return 0; - } -}; -} diff --git a/PySide/QtCore/qvariant_conversions.h b/PySide/QtCore/qvariant_conversions.h deleted file mode 100644 index 68b6e8f5..00000000 --- a/PySide/QtCore/qvariant_conversions.h +++ /dev/null @@ -1,221 +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 QByteArray resolveMetaType(PyTypeObject* type, int &typeId) - { - if (PyObject_TypeCheck(type, &SbkObjectType_Type)) { - SbkObjectType* sbkType = reinterpret_cast(type); - QByteArray typeName(Shiboken::ObjectType::getOriginalName(sbkType)); - bool valueType = !typeName.endsWith("*"); - - // Do not convert user type of value - if (valueType && Shiboken::ObjectType::isUserType(type)) - return QByteArray(); - - int obTypeId = QMetaType::type(typeName); - if (obTypeId) { - typeId = obTypeId; - return QByteArray(typeName); - } - - // Do not resolve types to value type - if (valueType) - return QByteArray(); - - // 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++){ - QByteArray derivedName = resolveMetaType(reinterpret_cast(PyTuple_GET_ITEM(type->tp_bases, i)), typeId); - if (!derivedName.isEmpty()) - return derivedName; - } - } - } - typeId = 0; - return QByteArray(); - } - - 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 (PyDict_Check(pyObj)) { - return convertToVariantMap(pyObj); - } else if (PySequence_Check(pyObj)) { - return convertToVariantList(pyObj); - } else { - // a class supported by QVariant? - if (Shiboken::Object::checkType(pyObj)) { - SbkObjectType* objType = reinterpret_cast(pyObj->ob_type); - int typeCode = 0; - QByteArray typeName = resolveMetaType(reinterpret_cast(objType), typeCode); - if (typeCode) { - Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(typeName); - void* data = 0; - data = tr->toCpp(pyObj, &data, true); - if (typeName.endsWith("*")) { - QVariant var(typeCode, &data); - tr->deleteObject(data); - return var; - } else { - QVariant var(typeCode, data); - tr->deleteObject(data); - return var; - } - } - } - // 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 = 0; - QByteArray typeName = resolveMetaType(element.cast(), typeId); - if (!typeName.isEmpty()) { - QByteArray listTypeName = QByteArray("QList<"+typeName+">"); - typeId = QMetaType::type(listTypeName); - if (typeId > 0) { - Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(listTypeName); - if (!tr) { - qWarning() << "TypeResolver for :" << listTypeName << "not registered."; - return QVariant(); - } else { - void *data = 0; - data = tr->toCpp(list, &data, true); - QVariant var(typeId, data); - tr->deleteObject(data); - return var; - } - } else { - return QVariant(); - } - } - - 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 toCpp(map); - } - } - - 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 bacf6c07..00000000 --- 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 (pyObj == reinterpret_cast(&PyString_Type) || pyObj == reinterpret_cast(&PyUnicode_Type)) - 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 (PyString_Check(pyObj)) - typeName = PyString_AS_STRING(pyObj); - else if (PyUnicode_Check(pyObj)) - typeName = PyString_AsString(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 0857036a..00000000 --- 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.xml.in b/PySide/QtCore/typesystem_core.xml.in new file mode 100644 index 00000000..9de2082f --- /dev/null +++ b/PySide/QtCore/typesystem_core.xml.in @@ -0,0 +1,24 @@ + + + + + + diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core_common.xml similarity index 50% rename from PySide/QtCore/typesystem_core.xml rename to PySide/QtCore/typesystem_core_common.xml index 6da4f64c..b0ea23d4 100644 --- a/PySide/QtCore/typesystem_core.xml +++ b/PySide/QtCore/typesystem_core_common.xml @@ -1,7 +1,7 @@ @@ -56,24 +93,12 @@ - - - - - - - - - - - - @@ -88,11 +113,14 @@ + + + @@ -107,120 +135,603 @@ - - + + - + + - + + - + - + - + - - + + + - + + - - - - - + + + return PyBool_FromLong((bool)%in); + + + + %out = %OUTTYPE(%in == Py_True); + + + - + + bool py2kStrCheck(PyObject* obj) + { + #ifdef IS_PY3K + return false; + #else + return PyString_Check(obj); + #endif + } + + + - + + + const int N = %in.length(); + wchar_t* str = new wchar_t[N]; + %in.toWCharArray(str); + PyObject* %out = PyUnicode_FromWideChar(str, N); + delete[] str; + return %out; + + + + Py_UNICODE* unicode = PyUnicode_AS_UNICODE(%in); + #if defined(Py_UNICODE_WIDE) + // cast as Py_UNICODE can be a different type + %out = QString::fromUcs4((const uint*)unicode); + #else + %out = QString::fromUtf16(unicode, PyUnicode_GET_SIZE(%in)); + #endif + + + #ifndef IS_PY3K + const char* str = %CONVERTTOCPP[const char*](%in); + %out = %OUTTYPE(str); + #endif + + + %out = %OUTTYPE(); + + + - - - - + - + + + const int N = %in.toString().length(); + wchar_t* str = new wchar_t[N]; + %in.toString().toWCharArray(str); + PyObject* %out = PyUnicode_FromWideChar(str, N); + delete[] str; + return %out; + + + + %out = %OUTTYPE(); + + + - + + + wchar_t c = (wchar_t)%in.unicode(); + return PyUnicode_FromWideChar(&c, 1); + + + + char c = %CONVERTTOCPP[char](%in); + %out = %OUTTYPE(c); + + + int i = %CONVERTTOCPP[int](%in); + %out = %OUTTYPE(i); + + + %out = %OUTTYPE(); + + + - - + + + + + if (!%in.isValid()) + Py_RETURN_NONE; + + if (qstrcmp(%in.typeName(), "QVariantList") == 0) { + QList<QVariant> var = %in.value<QVariantList>(); + return %CONVERTTOPYTHON[QList<QVariant>](var); + } + + if (qstrcmp(%in.typeName(), "QStringList") == 0) { + QStringList var = %in.value<QStringList>(); + return %CONVERTTOPYTHON[QList<QString>](var); + } + + if (qstrcmp(%in.typeName(), "QVariantMap") == 0) { + QMap<QString, QVariant> var = %in.value<QVariantMap>(); + return %CONVERTTOPYTHON[QMap<QString, QVariant>](var); + } + + Shiboken::Conversions::SpecificConverter converter(cppInRef.typeName()); + if (converter) { + void* ptr = cppInRef.data(); + return converter.toPython(ptr); + } + PyErr_Format(PyExc_RuntimeError, "Can't find converter for '%s'.", %in.typeName()); + return 0; + + + + %out = %OUTTYPE(%in == Py_True); + + + %out = %OUTTYPE(); + + + QString in = %CONVERTTOCPP[QString](%in); + %out = %OUTTYPE(in); + + + QByteArray in = %CONVERTTOCPP[QByteArray](%in); + %out = %OUTTYPE(in); + + + double in = %CONVERTTOCPP[double](%in); + %out = %OUTTYPE(in); + + + int in = %CONVERTTOCPP[int](%in); + %out = %OUTTYPE(in); + + + qlonglong in = %CONVERTTOCPP[qlonglong](%in); + %out = %OUTTYPE(in); + + + int in = %CONVERTTOCPP[int](%in); + %out = %OUTTYPE(in); + + + // a class supported by QVariant? + int typeCode; + const char* typeName = QVariant_resolveMetaType(%in->ob_type, &typeCode); + if (!typeCode || !typeName) + return; + QVariant var(typeCode, (void*)0); + Shiboken::Conversions::SpecificConverter converter(typeName); + converter.toCpp(pyIn, var.data()); + %out = var; + + + QVariant ret = QVariant_convertToVariantMap(%in); + %out = ret.isValid() ? ret : QVariant::fromValue<PySide::PyObjectWrapper>(%in); + + + %out = QVariant_convertToVariantList(%in); + + + // Is a shiboken type not known by Qt + %out = QVariant::fromValue<PySide::PyObjectWrapper>(%in); + + + + + static const char* QVariant_resolveMetaType(PyTypeObject* type, int* typeId) + { + if (PyObject_TypeCheck(type, &SbkObjectType_Type)) { + SbkObjectType* sbkType = (SbkObjectType*)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 QVariant_resolveMetaType(type->tp_base, typeId); + } else if (type->tp_bases) { + for(int i = 0; i < PyTuple_GET_SIZE(type->tp_bases); ++i) { + const char* derivedName = QVariant_resolveMetaType((PyTypeObject*)PyTuple_GET_ITEM(type->tp_bases, i), typeId); + if (derivedName) + return derivedName; + } + } + } + *typeId = 0; + return 0; + } + static QVariant QVariant_convertToValueList(PyObject* list) + { + if (PySequence_Size(list) < 1) + return QVariant(); + Shiboken::AutoDecRef element(PySequence_GetItem(list, 0)); + int typeId; + const char* typeName = QVariant_resolveMetaType(element.cast<PyTypeObject*>(), &typeId); + if (typeName) { + QByteArray listTypeName("QList<"); + listTypeName += typeName; + listTypeName += '>'; + typeId = QMetaType::type(listTypeName); + if (typeId > 0) { + Shiboken::Conversions::SpecificConverter converter(listTypeName); + if (converter) { + QVariant var(typeId, (void*)0); + converter.toCpp(list, &var); + return var; + } + qWarning() << "Type converter for :" << listTypeName << "not registered."; + } + } + return QVariant(); + } + static bool QVariant_isStringList(PyObject *list) + { + bool allString = true; + Shiboken::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 (!%CHECKTYPE[QString](item)) { + allString = false; + break; + } + } + return allString; + } + static QVariant QVariant_convertToVariantMap(PyObject* map) + { + Py_ssize_t pos = 0; + Shiboken::AutoDecRef keys(PyDict_Keys(map)); + if (!QVariant_isStringList(keys)) + return QVariant(); + PyObject* key; + PyObject* value; + QMap<QString,QVariant> ret; + while (PyDict_Next(map, &pos, &key, &value)) { + QString cppKey = %CONVERTTOCPP[QString](key); + QVariant cppValue = %CONVERTTOCPP[QVariant](value); + ret.insert(cppKey, cppValue); + } + return QVariant(ret); + } + static QVariant QVariant_convertToVariantList(PyObject* list) + { + if (QVariant_isStringList(list)) { + QList<QString > lst = %CONVERTTOCPP[QList<QString>](list); + return QVariant(QStringList(lst)); + } + QVariant valueList = QVariant_convertToValueList(list); + if (valueList.isValid()) + return valueList; + QList<QVariant> lst; + Shiboken::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* pyItem = PySequence_Fast_GET_ITEM(fast.object(), i); + QVariant item = %CONVERTTOCPP[QVariant](pyItem); + lst.append(item); + } + return QVariant(lst); + } + - + + + const char* typeName = QVariant::typeToName(%in); + PyObject* %out; + PyTypeObject* pyType = 0; + if (typeName) + pyType = Shiboken::Conversions::getPythonTypeObject(typeName); + %out = pyType ? ((PyObject*)pyType) : Py_None; + Py_INCREF(%out); + return %out; + + + + %out = QVariant::Invalid; + + + const char* typeName; + if (Shiboken::String::checkType((PyTypeObject*)%in)) + typeName = "QString"; + else if (%in == (PyObject*)&PyFloat_Type) + typeName = "double"; // float is a UserType in QVariant. + else if (%in == (PyObject*)&PyLong_Type) + typeName = "int"; // long is a UserType in QVariant. + else if (%in->ob_type == &SbkObjectType_Type) + typeName = Shiboken::ObjectType::getOriginalName((SbkObjectType*)%in); + else + typeName = ((PyTypeObject*)%in)->tp_name; + %out = QVariant::nameToType(typeName); + + + %out = QVariant::nameToType(Shiboken::String::toCString(%in)); + + + %out = QVariant::nameToType("QVariantMap"); + + + const char* typeName; + if (QVariantType_isStringList(%in)) + typeName = "QStringList"; + else + typeName = "QVariantList"; + %out = QVariant::nameToType(typeName); + + + + + + + + Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QTCORE_QMAP_QSTRING_QVARIANT_IDX], "QVariantMap"); + + + + static bool QVariantType_isStringList(PyObject* list) + { + bool allString = true; + Shiboken::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 (!%CHECKTYPE[QString](item)) { + allString = false; + break; + } + } + return allString; + } + static bool QVariantType_checkAllStringKeys(PyObject* dict) + { + Shiboken::AutoDecRef keys(PyDict_Keys(dict)); + return QVariantType_isStringList(keys); + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + - - + + + + + + + + + + - + + + + + + + + + + + - + + + PyObject* %out = PyTuple_New(2); + PyTuple_SET_ITEM(%out, 0, %CONVERTTOPYTHON[%INTYPE_0](%in.first)); + PyTuple_SET_ITEM(%out, 1, %CONVERTTOPYTHON[%INTYPE_1](%in.second)); + return %out; + + + + %out.first = %CONVERTTOCPP[%OUTTYPE_0](PySequence_Fast_GET_ITEM(%in, 0)); + %out.second = %CONVERTTOCPP[%OUTTYPE_1](PySequence_Fast_GET_ITEM(%in, 1)); + + + @@ -256,261 +767,25 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - + - + @@ -522,38 +797,38 @@ - + - + - + - - - + + + - - + + - + - + - + - - - + + + @@ -565,26 +840,29 @@ - - + + - + - + - - + + + + + @@ -592,11 +870,62 @@ - %PYARG_0 = %CONVERTTOPYTHON[double](qAbs(%1)); + double _abs = qAbs(%1); + %PYARG_0 = %CONVERTTOPYTHON[double](_abs); - + + namespace PySide { + static QStack<PyObject*> globalPostRoutineFunctions; + void globalPostRoutineCallback() + { + foreach(PyObject* callback, globalPostRoutineFunctions) { + Shiboken::AutoDecRef result(PyObject_CallObject(callback, NULL)); + Py_DECREF(callback); + } + globalPostRoutineFunctions.clear(); + } + void addPostRoutine(PyObject* callback) + { + if (PyCallable_Check(callback)) { + globalPostRoutineFunctions << callback; + Py_INCREF(callback); + } else { + PyErr_SetString(PyExc_TypeError, "qAddPostRoutine: The argument must be a callable object."); + } + } + } // namespace + + + + PySide::addPostRoutine(%1); + + + + qAddPostRoutine(PySide::globalPostRoutineCallback); + + + + QList<QByteArray> version = QByteArray(qVersion()).split('.'); + PyObject* pyQtVersion = PyTuple_New(3); + for (int i = 0; i < 3; ++i) + PyTuple_SET_ITEM(pyQtVersion, i, PyInt_FromLong(version[i].toInt())); + PyModule_AddObject(module, "__version_info__", pyQtVersion); + PyModule_AddStringConstant(module, "__version__", qVersion()); + + + + { // Avoid name clash + Shiboken::AutoDecRef atexit(Shiboken::Module::import("atexit")); + Shiboken::AutoDecRef regFunc(PyObject_GetAttrString(atexit, "register")); + PyObject* shutDownFunc = PyObject_GetAttrString(module, "__moduleShutdown"); + Shiboken::AutoDecRef args(PyTuple_New(1)); + PyTuple_SET_ITEM(args, 0, shutDownFunc); + Shiboken::AutoDecRef retval(PyObject_Call(regFunc, args, 0)); + Q_ASSERT(!retval.isNull()); + } + @@ -606,8 +935,10 @@ - Shiboken::TypeResolver::createValueTypeResolver<QString>("unicode"); - Shiboken::TypeResolver::createValueTypeResolver<QString>("str"); + Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QSTRING_IDX], "unicode"); + Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QSTRING_IDX], "str"); + Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QTCORE_QLIST_QVARIANT_IDX], "QVariantList"); + PySide::init(module); Py_AtExit(QtCoreModuleExit); @@ -619,13 +950,15 @@ // Define a global variable to handle qInstallMsgHandler callback static PyObject* qtmsghandler = 0; - void - msghandlercallback(QtMsgType type, const char* msg) + static void msgHandlerCallback(QtMsgType type, const char* msg) { - Shiboken::AutoDecRef arglist(Shiboken::makeTuple(type, msg)); + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(2)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QtMsgType](type)); + PyTuple_SET_ITEM(arglist, 1, %CONVERTTOPYTHON[const char*](msg)); Shiboken::AutoDecRef ret(PyObject_CallObject(qtmsghandler, arglist)); } - void QtCoreModuleExit() + static void QtCoreModuleExit() { PySide::SignalManager::instance().clear(); } @@ -642,7 +975,7 @@ %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None; Py_INCREF(%PYARG_1); qtmsghandler = %PYARG_1; - qInstallMsgHandler(msghandlercallback); + qInstallMsgHandler(msgHandlerCallback); } if (%PYARG_0 == Py_None) @@ -662,10 +995,19 @@ + + + + + + + + + - + @@ -677,17 +1019,44 @@ } }; + + + + + + + + + + + + + + + + + + - + + + + + + + + + + @@ -696,51 +1065,117 @@ - QPointF p; - %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, &p); - %PYARG_0 = Shiboken::makeTuple(retval, p); + QPointF p; + %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, &p); + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QPointF](p)); - - - - - - - + + + + - + + + + + + + + + + %out = %OUTTYPE(); + + + int day = PyDateTime_GET_DAY(%in); + int month = PyDateTime_GET_MONTH(%in); + int year = PyDateTime_GET_YEAR(%in); + %out = %OUTTYPE(year, month, day); + + + - + + + + + + + + + + - + + + + if (!PyDateTimeAPI) PySideDateTime_IMPORT; + %PYARG_0 = PyDate_FromDate(%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()); + + @@ -756,8 +1191,13 @@ int year, month, day; + %BEGIN_ALLOW_THREADS %CPPSELF.%FUNCTION_NAME(&year, &month, &day); - %PYARG_0 = Shiboken::makeTuple(year, month, day); + %END_ALLOW_THREADS + %PYARG_0 = PyTuple_New(3); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[int](year)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[int](month)); + PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[int](day)); @@ -769,14 +1209,40 @@ int yearNumber; + %BEGIN_ALLOW_THREADS int week = %CPPSELF.%FUNCTION_NAME(&yearNumber); - %PYARG_0 = Shiboken::makeTuple(week, yearNumber); + %END_ALLOW_THREADS + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[int](week)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[int](yearNumber)); + - + + + + + + + + + %out = %OUTTYPE(); + + + int day = PyDateTime_GET_DAY(%in); + int month = PyDateTime_GET_MONTH(%in); + int year = PyDateTime_GET_YEAR(%in); + int hour = PyDateTime_DATE_GET_HOUR(%in); + int min = PyDateTime_DATE_GET_MINUTE(%in); + int sec = PyDateTime_DATE_GET_SECOND(%in); + int usec = PyDateTime_DATE_GET_MICROSECOND(%in); + %out = %OUTTYPE(QDate(year, month, day), QTime(hour, min, sec, usec/1000)); + + + @@ -791,34 +1257,66 @@ %0 = new %TYPE(date, time, Qt::TimeSpec(%8)); + + + QDate date(%1, %2, %3); + QTime time(%4, %5, %6); + %0 = new %TYPE(date, time); + + + + + + + + + + + - + + + + 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); + + - - + + - + - + + + + + + + + + - + @@ -830,26 +1328,67 @@ } }; + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + - + @@ -861,14 +1400,62 @@ } }; + - + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + %out = %OUTTYPE(); + + + int hour = PyDateTime_TIME_GET_HOUR(%in); + int min = PyDateTime_TIME_GET_MINUTE(%in); + int sec = PyDateTime_TIME_GET_SECOND(%in); + int usec = PyDateTime_TIME_GET_MICROSECOND(%in); + %out = %OUTTYPE(hour, min, sec, usec/1000); + + + + + + + + + + + + + + + + - + - - - - + + + if (!PyDateTimeAPI) PySideDateTime_IMPORT; + %PYARG_0 = PyTime_FromTime(%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()*1000); + + - - + + + + + + + + + + + + + + + + + + - + - @@ -953,10 +1673,15 @@ - + + + + + + @@ -975,6 +1700,9 @@ + + + @@ -984,6 +1712,9 @@ + + + @@ -993,6 +1724,9 @@ + + + @@ -1002,6 +1736,9 @@ + + + @@ -1010,6 +1747,9 @@ + + + @@ -1018,6 +1758,9 @@ + + + @@ -1026,6 +1769,9 @@ + + + @@ -1034,13 +1780,15 @@ + + + - return %CPPSELF.size(); @@ -1048,11 +1796,12 @@ - if (_i < 0 || _i >= %CPPSELF.size()) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - return 0; - } - return %CONVERTTOPYTHON[bool](%CPPSELF.at(_i)); + if (_i < 0 || _i >= %CPPSELF.size()) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + return 0; + } + bool ret = %CPPSELF.at(_i); + return %CONVERTTOPYTHON[bool](ret); @@ -1074,13 +1823,35 @@ + + + + + + + + + %CPPSELF.unlock(); + + + + + + + + + + + %CPPSELF.unlock(); + + - + @@ -1099,21 +1870,46 @@ + - - + + + - + + + + + + + + + + - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.%FUNCTION_NAME(%1, %2, %PYARG_3)); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(%1, %2, %PYARG_3); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + Creates a model index for the given row and column with the internal pointer ptr. + When using a QSortFilterProxyModel, its indexes have their own internal pointer. It is not advisable to access this internal pointer outside of the model. Use the data() function instead. + This function provides a consistent interface that model subclasses must use to create model indexes. + + .. warning:: Because of some Qt/Python itegration rules, the ptr argument do not get the reference incremented during the QModelIndex life time. So it is necessary to keep the object used on ptr argument alive during the whole process. Do not destroy the object if you are not sure about that. + - + - + + + + + + + @@ -1126,10 +1922,11 @@ - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.%FUNCTION_NAME()); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); - + @@ -1173,7 +1970,8 @@ // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnect(%1, %2, %CPPSELF, %3, %4)); + %RETURN_TYPE %0 = qobjectConnect(%1, %2, %CPPSELF, %3, %4); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); @@ -1182,7 +1980,8 @@ // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnect(%1, %2, %3, %4, %5)); + %RETURN_TYPE %0 = qobjectConnect(%1, %2, %3, %4, %5); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); @@ -1193,7 +1992,8 @@ // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnectCallback(%1, %2, %PYARG_3, %4)); + %RETURN_TYPE %0 = qobjectConnectCallback(%1, %2, %PYARG_3, %4); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); @@ -1204,7 +2004,8 @@ // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnectCallback(%CPPSELF, %1, %PYARG_2, %3)); + %RETURN_TYPE %0 = qobjectConnectCallback(%CPPSELF, %1, %PYARG_2, %3); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); @@ -1214,55 +2015,35 @@ // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnect(%CPPSELF, %1, %2, %3, %4)); + %RETURN_TYPE %0 = qobjectConnect(%CPPSELF, %1, %2, %3, %4); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); - %PYARG_0 = %CONVERTTOPYTHON[bool](PySide::SignalManager::instance().emitSignal(%CPPSELF, %1, %PYARG_2)); + %RETURN_TYPE %0 = PySide::SignalManager::instance().emitSignal(%CPPSELF, %1, %PYARG_2); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectDisconnectCallback(%CPPSELF, %1, %2)); + %RETURN_TYPE %0 = qobjectDisconnectCallback(%CPPSELF, %1, %2); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectDisconnectCallback(%1, %2, %3)); + %RETURN_TYPE %0 = qobjectDisconnectCallback(%1, %2, %3); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); - - static bool - qobjectInheritsInternal(PyTypeObject *objType, const char *class_name) - { - if (strcmp(objType->tp_name, class_name) == 0) - return true; - - PyTypeObject* base = (objType)->tp_base; - if (base == 0) - return false; - return qobjectInheritsInternal(base, class_name); - } - - - - bool retval = qobjectInheritsInternal(self->ob_type, %1) ? true : %CPPSELF.%FUNCTION_NAME(%1); - %PYARG_0 = %CONVERTTOPYTHON[bool](retval); - - - - - - - %PYARG_0 = %CONVERTTOPYTHON[QObject*](_findChildHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1)); + QObject* child = _findChildHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1); + %PYARG_0 = %CONVERTTOPYTHON[QObject*](child); @@ -1279,6 +2060,18 @@ + + + + + + + %PYARG_0 = PyList_New(0); + _findChildrenHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1, %PYARG_0); + + + + @@ -1294,7 +2087,7 @@ if (QCoreApplication::instance()) { PyObject *klass = PyObject_GetAttrString(%PYSELF, "__class__"); PyObject *cname = PyObject_GetAttrString(klass, "__name__"); - result = QString(QCoreApplication::instance()->translate(PyString_AsString(cname), %1, %2, QCoreApplication::CodecForTr, %3)); + result = QString(QCoreApplication::instance()->translate(Shiboken::String::toCString(cname), %1, %2, QCoreApplication::CodecForTr, %3)); Py_DECREF(klass); Py_DECREF(cname); @@ -1305,6 +2098,18 @@ + @@ -1313,18 +2118,24 @@ - QString result; - if (QCoreApplication::instance()) { - PyObject *klass = PyObject_GetAttrString(%PYSELF, "__class__"); - PyObject *cname = PyObject_GetAttrString(klass, "__name__"); - result = QString(QCoreApplication::instance()->translate(PyString_AsString(cname), %1, %2, QCoreApplication::UnicodeUTF8, %3)); - - Py_DECREF(klass); - Py_DECREF(cname); - } else { - result = QString(QString::fromLatin1(%1)); - } - %PYARG_0 = %CONVERTTOPYTHON[QString](result); + + + + + + + + + + + + + + + + + + @@ -1332,10 +2143,9 @@ // Avoid return +1 because SignalManager connect to "destroyed()" signal to control object timelife int ret = %CPPSELF.%FUNCTION_NAME(%1); - if (ret > 0 && ((strcmp(%1, SIGNAL(destroyed())) == 0) || (strcmp(%1, SIGNAL(destroyed(QObject*))) == 0))) { - if (PySide::SignalManager::instance().hasConnectionWith(%CPPSELF)) - ret--; - } + if (ret > 0 && ((strcmp(%1, SIGNAL(destroyed())) == 0) || (strcmp(%1, SIGNAL(destroyed(QObject*))) == 0))) + ret -= PySide::SignalManager::instance().countConnectionsWith(%CPPSELF); + %PYARG_0 = %CONVERTTOPYTHON[int](ret); @@ -1348,9 +2158,22 @@ - + - + + + + + + + + + + + + + + @@ -1359,7 +2182,7 @@ - + <para>URLs can be represented in two forms: encoded or unencoded. The unencoded representation is suitable for showing to users, but the encoded representation is typically what you would send to a web server. For example, the unencoded URL "http://bühler.example.com" would be sent to the server as "http://xn--bhler-kva.example.com/List%20of%20applicants.xml".</para> @@ -1367,10 +2190,19 @@ + + + + + + + + + - + @@ -1382,14 +2214,58 @@ + + + + + + + + + - + + + + + + + + + + Replaces every occurrence of the regular expression in *sourceString* with *after*. + Returns a new Python string with the modified contents. For example: + + :: + + s = "Banana" + re = QRegExp("a[mn]") + s = re.replace(s, "ox") + # s == "Boxoxa" + + + For regular expressions containing capturing parentheses, occurrences of \1, \2, ..., in *after* + are replaced with rx.cap(1), cap(2), ... + + :: + + t = "A <i>bon mot</i>." + re = QRegExp("<i>([^<]*)</i>") + t = re.replace(t, "\\emph{\\1}") + # t == "A \\emph{bon mot}." + + + + %1.replace(*%CPPSELF, %2); + %PYARG_0 = %CONVERTTOPYTHON[QString](%1); + + @@ -1399,29 +2275,149 @@ - + + + + + %out = %OUTTYPE(); + + + %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in)); + + + #ifdef IS_PY3K + %out = %OUTTYPE(PyBytes_AS_STRING(%in), PyBytes_GET_SIZE(%in)); + #endif + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Shiboken::AutoDecRef str(PyUnicode_AsASCIIString(%PYARG_1)); + if (!str.isNull()) { + QByteArray b(PyBytes_AS_STRING(str.object()), PyBytes_GET_SIZE (str.object())); + b.prepend(*%CPPSELF); + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](b); + } + + + + + Shiboken::AutoDecRef str(PyUnicode_AsASCIIString(%PYARG_1)); + if (!str.isNull()) { + QByteArray b(PyBytes_AS_STRING(str.object()), PyBytes_GET_SIZE(str.object())); + b.append(*%CPPSELF); + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](b); + } + + + + + QByteArray ba = QByteArray(PyBytes_AS_STRING(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)) + *%CPPSELF; + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); + + + + + + + QByteArray b(((PyObject*)%PYSELF)->ob_type->tp_name); + PyObject* aux = Shiboken::String::fromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); + if (PyUnicode_CheckExact(aux)) { + PyObject* tmp = PyUnicode_AsASCIIString(aux); + Py_DECREF(aux); + aux = tmp; + } + b += "('"; + b += QByteArray(PyBytes_AS_STRING(aux), PyBytes_GET_SIZE(aux)); + b += "')"; + %PYARG_0 = Shiboken::String::fromStringAndSize(b.constData(), b.size()); + + + - - + + - int size = PyString_Size(pyargs[0]); - %0 = new QByteArray(%1, size); + if (PyBytes_Check(%PYARG_1)) { + %0 = new QByteArray(PyBytes_AsString(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)); + } if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + %0 = new QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + } else if (Shiboken::String::check(%PYARG_1)) { + %0 = new QByteArray(Shiboken::String::toCString(%PYARG_1), Shiboken::String::len(%PYARG_1)); + } @@ -1433,13 +2429,14 @@ #endif - + - %PYARG_0 = PyString_FromStringAndSize(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.size()); + %PYARG_0 = PyBytes_FromStringAndSize(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.size()); + @@ -1447,33 +2444,41 @@ + + + - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - char c = PyString_AS_STRING(%PYARG_1)[0]; - if (c) { - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.%FUNCTION_NAME(c)); - } - - + + @@ -1527,137 +2532,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + + + + + + + - - - + + + + + + + + + + + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(PyBytes_AsString(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + @@ -1675,9 +2573,9 @@ - + - %PYARG_0 = PyString_FromString(%CPPSELF.data()); + %PYARG_0 = Shiboken::String::fromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); @@ -1694,7 +2592,7 @@ char res[2]; res[0] = %CPPSELF.at(_i); res[1] = 0; - return PyString_FromString(res); + return PyBytes_FromStringAndSize(res, 1); } @@ -1708,10 +2606,22 @@ return !result ? -1 : 0; + + + Py_ssize_t max = %CPPSELF.count(); + _i1 = qBound(Py_ssize_t(0), _i1, max); + _i2 = qBound(Py_ssize_t(0), _i2, max); + QByteArray ba; + if (_i1 < _i2) + ba = %CPPSELF.mid(_i1, _i2 - _i1); + return %CONVERTTOPYTHON[QByteArray](ba); + + - + + @@ -1722,7 +2632,7 @@ - + @@ -1730,17 +2640,29 @@ - + + - - - - - - - + + + + + + uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(ptr); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2, Shiboken::Buffer::ReadWrite); + + @@ -1752,7 +2674,7 @@ - + @@ -1761,11 +2683,16 @@ - - - - - + + + + + + + + + + @@ -1774,7 +2701,7 @@ - + QByteArray ba; ba.resize(%2); @@ -1785,15 +2712,20 @@ - + - const QByteArray ba(%CONVERTTOCPP[QByteArray](%PYARG_0)); - memcpy(%1, ba.data(), ba.size()); - long long %out = ba.size(); + %RETURN_TYPE %out; + if (PyBytes_Check(%PYARG_0)) { + %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); + } else if (Shiboken::String::check(%PYARG_0)) { + %out = Shiboken::String::len((PyObject*)%PYARG_0); + memcpy(%1, Shiboken::String::toCString((PyObject*)%PYARG_0), %out); + } - + QByteArray ba; ba.resize(%2); @@ -1804,30 +2736,51 @@ - + - const QByteArray ba(%CONVERTTOCPP[QByteArray](%PYARG_0)); - memcpy(data, ba.data(), ba.size()); - long long %out = ba.size(); + %RETURN_TYPE %out; + if (!PyBytes_Check(%PYARG_0)) { + %out = -1; + } else { + %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); + } - + + + + + + %CPPSELF.%FUNCTION_NAME(Shiboken::String::toCString(%PYARG_1), Shiboken::String::len(%PYARG_1)); + + - + + + + + - + + + + + %CPPSELF.unlock(); + + @@ -1842,6 +2795,22 @@ + + + + + + + Shiboken::AutoDecRef fileNo(PyObject_GetAttrString(%PYARG_1, "fileno")); + if (!fileNo.isNull()) { + Shiboken::AutoDecRef fileNoValue(PyObject_CallObject(fileNo, 0)); + if (%CHECKTYPE[int](fileNoValue)) { + int cppFileNoValue = %CONVERTTOCPP[int](fileNoValue); + %0 = new %TYPE(cppFileNoValue, %2, %3); + } + } + + @@ -1863,7 +2832,7 @@ - + @@ -1889,13 +2858,18 @@ + + + + - + + @@ -1904,8 +2878,20 @@ - - + + + + + + + + + Py_ssize_t size; + uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1, &size); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(const_cast<const uchar*>(ptr), size); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + @@ -1916,10 +2902,8 @@ - - - + @@ -1941,7 +2925,8 @@ %PYARG_2, %3) ); - Shiboken::Object::invalidate((SbkObject*)pyTimer); + Shiboken::Object::releaseOwnership((SbkObject*)pyTimer); + Py_XDECREF(pyTimer); timer->setSingleShot(true); timer->connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); timer->start(%1); @@ -1955,11 +2940,10 @@ Shiboken::SbkType<QTimer>()->tp_init(pyTimer, emptyTuple, 0); QTimer* timer = %CONVERTTOCPP[QTimer*](pyTimer); timer->setSingleShot(true); - timer->connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); if (PyObject_TypeCheck(%2, &PySideSignalInstanceType)) { PySideSignalInstance* signalInstance = reinterpret_cast<PySideSignalInstance*>(%2); - Shiboken::AutoDecRef signalSignature(PyString_FromFormat("2%s", PySide::Signal::getSignature(signalInstance))); + Shiboken::AutoDecRef signalSignature(Shiboken::String::fromFormat("2%s", PySide::Signal::getSignature(signalInstance))); Shiboken::AutoDecRef result( PyObject_CallMethod(pyTimer, const_cast<char*>("connect"), @@ -1976,28 +2960,37 @@ const_cast<char*>("OsO"), pyTimer, SIGNAL(timeout()), - pyargs[1]) + %PYARG_2) ); } - Shiboken::Object::invalidate((SbkObject*)pyTimer); + + timer->connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater()), Qt::DirectConnection); + Shiboken::Object::releaseOwnership((SbkObject*)pyTimer); + Py_XDECREF(pyTimer); timer->start(%1); - + + + + + + + - + - + @@ -2009,8 +3002,78 @@ - - + + + + + + + + + + + + + uchar* ptr = (uchar*)Shiboken::Buffer::getPointer(%PYARG_1); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(ptr); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2, Shiboken::Buffer::ReadWrite); + + + + + + QByteArray ba; + ba.resize(%2); + %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + %PYARG_0 = PyBytes_FromStringAndSize(ba.constData(), ba.size()); + + + + + + + + %RETURN_TYPE %out; + if (!Shiboken::String::check(%PYARG_0)) { + %out = -1; + } else { + %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); + } + + + + + + QByteArray ba; + ba.resize(%2); + %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + %PYARG_0 = PyBytes_FromStringAndSize(ba.constData(), ba.size()); + + + + + + + + %RETURN_TYPE %out; + if (!Shiboken::String::check(%PYARG_0)) { + %out = -1; + } else { + %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); + } + + + @@ -2018,7 +3081,7 @@ - + @@ -2026,8 +3089,6 @@ - - @@ -2038,14 +3099,35 @@ qint64 pid; %RETURN_TYPE retval = %TYPE::%FUNCTION_NAME(%1, %2, %3, &pid); - %PYARG_0 = Shiboken::makeTuple(retval, pid); + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[qint64](pid)); + + + + + long result; + #ifdef WIN32 + _PROCESS_INFORMATION* procInfo = %CPPSELF.%FUNCTION_NAME(); + result = procInfo ? procInfo->dwProcessId : 0; + #else + result = %CPPSELF.%FUNCTION_NAME(); + #endif + %PYARG_0 = %CONVERTTOPYTHON[long](result); + + + + + + + @@ -2062,6 +3144,11 @@ in a more convenient form by the :meth:`~QCoreApplication.arguments()` method. + + + QCoreApplication_constructor(%PYSELF, args, &%0); + + @@ -2070,16 +3157,24 @@ - - - + + QCoreApplication* app = QCoreApplication::instance(); + PyObject* pyApp = Py_None; + if (app) { + pyApp = reinterpret_cast<PyObject*>(Shiboken::BindingManager::instance().retrieveWrapper(app)); + if (!pyApp) + pyApp = %CONVERTTOPYTHON[QCoreApplication*](app); // this will keep app live after python exit (extra ref) + } + %PYARG_0 = pyApp; + Py_XINCREF(%PYARG_0); + - - + - + + @@ -2095,6 +3190,31 @@ + + + + + long *%out = new long; + %out = 0; + + + + + + %RETURN_TYPE %out = false; + if (PySequence_Check(%PYARG_0) && (PySequence_Size(%PYARG_0) == 2)) { + Shiboken::AutoDecRef pyResult(PySequence_GetItem(%PYARG_0, 0)); + %out = %CONVERTTOCPP[bool](pyResult); + } + + + + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](%0)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[long](*result_out)); + delete result_out; + + @@ -2103,12 +3223,20 @@ - + - - + + + + + + + + .. warning:: QSettings.value can return different types (QVariant types) depending on the platform it's running on, so the safest way to use it is always casting the result to the desired type, e.g.: int(settings.value("myKey")) + + @@ -2117,7 +3245,7 @@ - + @@ -2135,9 +3263,10 @@ - + + @@ -2148,6 +3277,7 @@ + @@ -2160,7 +3290,9 @@ + + @@ -2173,55 +3305,52 @@ + + + + + + - - *(%CPPSELF) << %1; + + - - %RETURN_TYPE val; - *(%CPPSELF) >> val; - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](val); + + - - *(%CPPSELF) << %1; + + - - %RETURN_TYPE val; - *(%CPPSELF) >> val; - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](val); + + - - *(%CPPSELF) << %1; + + - - %RETURN_TYPE val; - *(%CPPSELF) >> val; - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](val); + + - - *(%CPPSELF) << %1; + + - - %RETURN_TYPE val; - *(%CPPSELF) >> val; - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](val); + + - @@ -2229,26 +3358,26 @@ QByteArray data; data.resize(%2); - %CPPSELF.%FUNCTION_NAME(data.data(), data.size()); - %PYARG_0 = PyString_FromStringAndSize(data.constData(), data.size()); + int result = %CPPSELF.%FUNCTION_NAME(data.data(), data.size()); + if (result == -1) { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; + } else { + %PYARG_0 = PyBytes_FromStringAndSize(data.data(), result); + } - - - int r = %CPPSELF.%FUNCTION_NAME(%1, PyString_Size(%PYARG_1)); + int r = %CPPSELF.%FUNCTION_NAME(%1, Shiboken::String::len(%PYARG_1)); %PYARG_0 = %CONVERTTOPYTHON[int](r); - - - @@ -2371,24 +3500,28 @@ - + + + - + - + - + + + @@ -2401,12 +3534,18 @@ + + + + + + @@ -2414,6 +3553,15 @@ + + + + + QString& res = *%0; + %PYARG_0 = %CONVERTTOPYTHON[QString](res); + + + @@ -2425,25 +3573,39 @@ - + - + + + + + + + + + + + + + + + Shiboken::Object::releaseOwnership(%PYARG_0); + + + - - - - + @@ -2451,22 +3613,21 @@ - - - + - + + + + + - %PYARG_0 = (PyObject*)%CPPSELF.%FUNCTION_NAME(); - if (!%PYARG_0) - %PYARG_0 = Py_None; - Py_XINCREF(%PYARG_0); + @@ -2487,31 +3648,43 @@ + + + + + + - + - + + + + + + + - + @@ -2532,33 +3705,33 @@ - + - + - + - + - + @@ -2585,28 +3758,45 @@ - for(int counter = 0; counter < %CPPSELF.animationCount(); ++counter ) { - PyObject* obj = %CONVERTTOPYTHON[QAbstractAnimation*](%CPPSELF.animationAt(counter)); - Shiboken::Object::setParent(NULL, obj); - Py_DECREF(obj); - } - %CPPSELF.clear(); + for(int counter = 0; counter < %CPPSELF.animationCount(); ++counter ) { + QAbstractAnimation* animation = %CPPSELF.animationAt(counter); + PyObject* obj = %CONVERTTOPYTHON[QAbstractAnimation*](animation); + Shiboken::Object::setParent(NULL, obj); + Py_DECREF(obj); + } + %CPPSELF.clear(); - - - - - - - + + + + + + + + + + PySideEasingCurveFunctor::init(); + + + + + QEasingCurve::EasingFunction func = PySideEasingCurveFunctor::createCustomFuntion(%PYSELF, %PYARG_1); + if (func) + %CPPSELF.%FUNCTION_NAME(func); + + + + + //%FUNCTION_NAME() + %PYARG_0 = PySideEasingCurveFunctor::callable(%PYSELF); + + - + @@ -2621,27 +3811,46 @@ - + - + - + + <code>machine = QStateMachine() + +s1 = new QState() +s11 = new QState(s1) +s12 = new QState(s1) - +s1h = QHistoryState(s1) +s1h.setDefaultState(s11) + +machine.addState(s1) + +s2 = QState() +machine.addState(s2) + +button = QPushButton() +# Clicking the button will cause the state machine to enter the child state +# that s1 was in the last time s1 was exited, or the history state's default +# state if s1 has never been entered. +s1.addTransition(button.clicked, s1h)</code> + + - + - + - + - + - + - + - + @@ -2661,7 +3870,7 @@ - + @@ -2674,12 +3883,14 @@ - QString signalName(%2); - if (PySide::SignalManager::registerMetaMethod(%1, signalName.mid(1).toAscii().data(), QMetaMethod::Signal)) { - %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%CPPSELF->addTransition(%1, %2, %3)); - } else { + QString signalName(%2); + if (PySide::SignalManager::registerMetaMethod(%1, signalName.mid(1).toAscii().data(), QMetaMethod::Signal)) { + QSignalTransition* %0 = %CPPSELF->addTransition(%1, %2, %3); + %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%0); + } else { + Py_INCREF(Py_None); %PYARG_0 = Py_None; - } + } @@ -2696,15 +3907,16 @@ - // Obviously the label used by the following goto is a very awkward solution, - // since it refers to a name very tied to the generator implementation. - // Check bug #362 for more information on this - // http://bugs.openbossa.org/show_bug.cgi?id=362 - if (!PyObject_TypeCheck(%1, &PySideSignalInstanceType)) - goto Sbk_%TYPEFunc_%FUNCTION_NAME_TypeError; - PySideSignalInstance* signalInstance = reinterpret_cast<PySideSignalInstance*>(%1); - QObject* sender = %CONVERTTOCPP[QObject*](PySide::Signal::getObject(signalInstance)); - %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%CPPSELF->%FUNCTION_NAME(sender, PySide::Signal::getSignature(signalInstance), %2)); + // Obviously the label used by the following goto is a very awkward solution, + // since it refers to a name very tied to the generator implementation. + // Check bug #362 for more information on this + // http://bugs.openbossa.org/show_bug.cgi?id=362 + if (!PyObject_TypeCheck(%1, &PySideSignalInstanceType)) + goto Sbk_%TYPEFunc_%FUNCTION_NAME_TypeError; + PySideSignalInstance* signalInstance = reinterpret_cast<PySideSignalInstance*>(%1); + QObject* sender = %CONVERTTOCPP[QObject*](PySide::Signal::getObject(signalInstance)); + QSignalTransition* %0 = %CPPSELF->%FUNCTION_NAME(sender, PySide::Signal::getSignature(signalInstance), %2); + %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%0); @@ -2715,13 +3927,13 @@ - + - - + + @@ -2734,8 +3946,6 @@ - - %PYARG_0 = PySet_New(0); @@ -2747,6 +3957,8 @@ + + %PYARG_0 = PyList_New(0); @@ -2759,36 +3971,46 @@ - + - + - %PYARG_0 = PyString_FromFormat("2%s", QMetaObject::normalizedSignature(%1).constData()); + %PYARG_0 = Shiboken::String::fromFormat("2%s", QMetaObject::normalizedSignature(%1).constData()); - + - %PYARG_0 = PyString_FromFormat("1%s", QMetaObject::normalizedSignature(%1).constData()); + %PYARG_0 = Shiboken::String::fromFormat("1%s", QMetaObject::normalizedSignature(%1).constData()); - - (void)%1;%PYARG_0 = %PYARG_1; + + + + - - (void)%1;%PYARG_0 = %PYARG_1; + + + + - - (void)%1;(void)%2;%PYARG_0 = %PYARG_2; + + + + - - (void)%1;(void)%2;(void)%3;%PYARG_0 = %PYARG_2; + + + + - - (void)%1;%PYARG_0 = %PYARG_1; + + + + @@ -2804,14 +4026,20 @@ const unsigned char *, const unsigned char *); - + - %PYARG_0 = %CONVERTTOPYTHON[bool](%FUNCTION_NAME(%1, (uchar*)%2, (uchar*)%3, (uchar*)%4)); + %RETURN_TYPE %0 = %FUNCTION_NAME(%1, (uchar*)PyBytes_AS_STRING(%PYARG_2), + (uchar*)PyBytes_AS_STRING(%PYARG_3), + (uchar*)PyBytes_AS_STRING(%PYARG_4)); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); - + - %PYARG_0 = %CONVERTTOPYTHON[bool](%FUNCTION_NAME(%1, (uchar*)%2, (uchar*)%3, (uchar*)%4)); + %RETURN_TYPE %0 = %FUNCTION_NAME(%1, (uchar*)PyBytes_AS_STRING(%PYARG_2), + (uchar*)PyBytes_AS_STRING(%PYARG_3), + (uchar*)PyBytes_AS_STRING(%PYARG_4)); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); @@ -2823,11 +4051,6 @@ - - - - - @@ -2842,8 +4065,6 @@ - - @@ -2851,10 +4072,27 @@ + + + + + + + + + + + + + + + + + diff --git a/PySide/QtCore/typesystem_core_mac.xml b/PySide/QtCore/typesystem_core_mac.xml new file mode 100644 index 00000000..0f9c5119 --- /dev/null +++ b/PySide/QtCore/typesystem_core_mac.xml @@ -0,0 +1,23 @@ + + + + + diff --git a/PySide/QtCore/typesystem_core_maemo.xml b/PySide/QtCore/typesystem_core_maemo.xml new file mode 100644 index 00000000..eba223c7 --- /dev/null +++ b/PySide/QtCore/typesystem_core_maemo.xml @@ -0,0 +1,26 @@ + + + + + + + + diff --git a/PySide/QtCore/typesystem_core_simulator.xml b/PySide/QtCore/typesystem_core_simulator.xml new file mode 100644 index 00000000..3a6c0dd0 --- /dev/null +++ b/PySide/QtCore/typesystem_core_simulator.xml @@ -0,0 +1,23 @@ + + + + + diff --git a/PySide/QtCore/typesystem_core_win.xml b/PySide/QtCore/typesystem_core_win.xml new file mode 100644 index 00000000..26c7a82a --- /dev/null +++ b/PySide/QtCore/typesystem_core_win.xml @@ -0,0 +1,57 @@ + + + + + + + + #ifdef IS_PY3K + return PyCapsule_New(%in, 0, 0); + #else + return PyCObject_FromVoidPtr(%in, 0); + #endif + + + + %out = 0; + + + #ifdef IS_PY3K + %out = (%OUTTYPE)PyCapsule_GetPointer(%in, 0); + #else + %out = (%OUTTYPE)PyCObject_AsVoidPtr(%in); + #endif + + + + + + + + + + + + + + + + diff --git a/PySide/QtCore/typesystem_core_x11.xml b/PySide/QtCore/typesystem_core_x11.xml new file mode 100644 index 00000000..eba223c7 --- /dev/null +++ b/PySide/QtCore/typesystem_core_x11.xml @@ -0,0 +1,26 @@ + + + + + + + + diff --git a/PySide/QtDeclarative/CMakeLists.txt b/PySide/QtDeclarative/CMakeLists.txt index 1788adcd..c9ea9313 100644 --- a/PySide/QtDeclarative/CMakeLists.txt +++ b/PySide/QtDeclarative/CMakeLists.txt @@ -1,5 +1,7 @@ project(QtDeclarative) +set(QtDeclarative_registerType "${CMAKE_CURRENT_SOURCE_DIR}/pysideqmlregistertype.cpp") + set(QtDeclarative_SRC ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative/qdeclarativecomponent_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative/qdeclarativecontext_wrapper.cpp @@ -21,7 +23,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative/qdeclarativeview_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative/qtdeclarative_module_wrapper.cpp ) -set(QtDeclarative_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}${PATH_SEP}${QtNetwork_SOURCE_DIR}${PATH_SEP}${QtDeclarative_SOURCE_DIR}${PATH_SEP}${QtGui_BINARY_DIR}") +set(QtDeclarative_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtCore_BINARY_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}${PATH_SEP}${QtNetwork_SOURCE_DIR}${PATH_SEP}${QtDeclarative_SOURCE_DIR}${PATH_SEP}${QtGui_BINARY_DIR}") set(QtDeclarative_include_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${QT_QTCORE_INCLUDE_DIR} @@ -56,5 +58,5 @@ create_pyside_module(QtDeclarative QtDeclarative_deps QtDeclarative_typesystem_path QtDeclarative_SRC - "") + QtDeclarative_registerType) diff --git a/PySide/QtDeclarative/pysideqmlregistertype.cpp b/PySide/QtDeclarative/pysideqmlregistertype.cpp new file mode 100644 index 00000000..4efc4bf7 --- /dev/null +++ b/PySide/QtDeclarative/pysideqmlregistertype.cpp @@ -0,0 +1,366 @@ +/* + * This file is part of the Shiboken Python Bindings Generator project. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "pysideqmlregistertype.h" +// Qt +#include +#include +#include +// shiboken +#include +#include +#include +// pyside +#include +#include +#include + +// auto generated headers +#include "qdeclarativeitem_wrapper.h" +#include "pyside_qtcore_python.h" +#include "pyside_qtdeclarative_python.h" + +#ifndef PYSIDE_MAX_QML_TYPES +// Maximum number of different types the user cna export to QML using qmlRegisterType. +#define PYSIDE_MAX_QML_TYPES 50 +#endif + +// Forward declarations +static void propListMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::Call call, void** args); + + +// All registered python types +static PyObject* pyTypes[PYSIDE_MAX_QML_TYPES]; +static void (*createFuncs[PYSIDE_MAX_QML_TYPES])(void*); + +// Mutex used to avoid race condition on PySide::nextQObjectMemoryAddr +static QMutex nextQmlElementMutex; + +template +struct ElementFactoryBase +{ + static void createInto(void* memory) + { + QMutexLocker locker(&nextQmlElementMutex); + PySide::setNextQObjectMemoryAddr(memory); + Shiboken::GilState state; + PyObject* obj = PyObject_CallObject(pyTypes[N], 0); + if (!obj || PyErr_Occurred()) + PyErr_Print(); + PySide::setNextQObjectMemoryAddr(0); + } +}; + +template +struct ElementFactory : ElementFactoryBase +{ + static void init() + { + createFuncs[N] = &ElementFactoryBase::createInto; + ElementFactory::init(); + } +}; + +template<> +struct ElementFactory<0> : ElementFactoryBase<0> +{ + static void init() + { + createFuncs[0] = &ElementFactoryBase<0>::createInto; + } +}; + +int PySide::qmlRegisterType(PyObject* pyObj, const char* uri, int versionMajor, int versionMinor, const char* qmlName) +{ + using namespace Shiboken; + + static PyTypeObject* qobjectType = Shiboken::Conversions::getPythonTypeObject("QObject*"); + static PyTypeObject* qdeclarativeType = Shiboken::Conversions::getPythonTypeObject("QDeclarativeItem*"); + assert(qobjectType); + static int nextType = 0; + + if (nextType >= PYSIDE_MAX_QML_TYPES) { + PyErr_Format(PyExc_TypeError, "QML doesn't really like language bindings, so you can only export %d types to QML.", PYSIDE_MAX_QML_TYPES); + return -1; + } + + if (!PySequence_Contains(((PyTypeObject*)pyObj)->tp_mro, (PyObject*)qobjectType)) { + PyErr_Format(PyExc_TypeError, "A type inherited from %s expected, got %s.", qobjectType->tp_name, ((PyTypeObject*)pyObj)->tp_name); + return -1; + } + + bool isDeclarativeType = PySequence_Contains(((PyTypeObject*)pyObj)->tp_mro, (PyObject*)qdeclarativeType); + + QMetaObject* metaObject = reinterpret_cast(ObjectType::getTypeUserData(reinterpret_cast(pyObj))); + Q_ASSERT(metaObject); + + // Inc ref the type object, don't worry about dec ref them because there's no way to unregister a QML type + Py_INCREF(pyObj); + + // All ready... now the ugly code begins... :-) + pyTypes[nextType] = pyObj; + + // Init proxy object static meta object + QDeclarativePrivate::RegisterType type; + type.version = 0; + if (isDeclarativeType) { + type.typeId = qMetaTypeId(); + type.listId = qMetaTypeId >(); + + type.attachedPropertiesFunction = QDeclarativePrivate::attachedPropertiesFunc(); + type.attachedPropertiesMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject(); + + type.parserStatusCast = QDeclarativePrivate::StaticCastSelector::cast(); + type.valueSourceCast = QDeclarativePrivate::StaticCastSelector::cast(); + type.valueInterceptorCast = QDeclarativePrivate::StaticCastSelector::cast(); + } else { + type.typeId = qMetaTypeId(); + type.listId = qMetaTypeId >(); + type.attachedPropertiesFunction = QDeclarativePrivate::attachedPropertiesFunc(); + type.attachedPropertiesMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject(); + + type.parserStatusCast = QDeclarativePrivate::StaticCastSelector::cast(); + type.valueSourceCast = QDeclarativePrivate::StaticCastSelector::cast(); + type.valueInterceptorCast = QDeclarativePrivate::StaticCastSelector::cast(); + } + type.objectSize = PySide::getSizeOfQObject(reinterpret_cast(pyObj)); + type.create = createFuncs[nextType]; + type.uri = uri; + type.versionMajor = versionMajor; + type.versionMinor = versionMinor; + type.elementName = qmlName; + type.metaObject = metaObject; + + type.extensionObjectCreate = 0; + type.extensionMetaObject = 0; + type.customParser = 0; + + int qmlTypeId = QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); + ++nextType; + return qmlTypeId; +} + +extern "C" +{ + +// This is the user data we store in the property. +struct DeclarativeListProperty +{ + PyTypeObject* type; + PyObject* append; + PyObject* at; + PyObject* clear; + PyObject* count; +}; + +static int propListTpInit(PyObject* self, PyObject* args, PyObject* kwds) +{ + static const char *kwlist[] = {"type", "append", "at", "clear", "count", 0}; + PySideProperty* pySelf = reinterpret_cast(self); + DeclarativeListProperty* data = new DeclarativeListProperty; + memset(data, 0, sizeof(DeclarativeListProperty)); + + if (!PyArg_ParseTupleAndKeywords(args, kwds, + "OO|OOO:QtDeclarative.ListProperty", (char**) kwlist, + &data->type, + &data->append, + &data->at, + &data->clear, + &data->count)) { + return 0; + } + PySide::Property::setMetaCallHandler(pySelf, &propListMetaCall); + PySide::Property::setTypeName(pySelf, "QDeclarativeListProperty"); + PySide::Property::setUserData(pySelf, data); + + return 1; +} + +void propListTpFree(void* self) +{ + PySideProperty* pySelf = reinterpret_cast(self); + delete reinterpret_cast(PySide::Property::userData(pySelf)); + // calls base type constructor + Py_TYPE(pySelf)->tp_base->tp_free(self); +} + +PyTypeObject PropertyListType = { + PyVarObject_HEAD_INIT(0, 0) + "ListProperty", /*tp_name*/ + sizeof(PySideProperty), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + 0, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + 0, /*tp_doc */ + 0, /*tp_traverse */ + 0, /*tp_clear */ + 0, /*tp_richcompare */ + 0, /*tp_weaklistoffset */ + 0, /*tp_iter */ + 0, /*tp_iternext */ + 0, /*tp_methods */ + 0, /*tp_members */ + 0, /*tp_getset */ + &PySidePropertyType, /*tp_base */ + 0, /*tp_dict */ + 0, /*tp_descr_get */ + 0, /*tp_descr_set */ + 0, /*tp_dictoffset */ + propListTpInit, /*tp_init */ + 0, /*tp_alloc */ + 0, /*tp_new */ + propListTpFree, /*tp_free */ + 0, /*tp_is_gc */ + 0, /*tp_bases */ + 0, /*tp_mro */ + 0, /*tp_cache */ + 0, /*tp_subclasses */ + 0, /*tp_weaklist */ + 0, /*tp_del */ +}; + +} // extern "C" + +// Implementation of QDeclarativeListProperty::AppendFunction callback +void propListAppender(QDeclarativeListProperty* propList, QDeclarativeItem* item) +{ + Shiboken::GilState state; + + Shiboken::AutoDecRef args(PyTuple_New(2)); + PyTuple_SET_ITEM(args, 0, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], propList->object)); + PyTuple_SET_ITEM(args, 1, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtDeclarativeTypes[SBK_QDECLARATIVEITEM_IDX], item)); + + DeclarativeListProperty* data = reinterpret_cast(propList->data); + Shiboken::AutoDecRef retVal(PyObject_CallObject(data->append, args)); + + if (PyErr_Occurred()) + PyErr_Print(); +} + +// Implementation of QDeclarativeListProperty::CountFunction callback +int propListCount(QDeclarativeListProperty* propList) +{ + Shiboken::GilState state; + + Shiboken::AutoDecRef args(PyTuple_New(1)); + PyTuple_SET_ITEM(args, 0, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], propList->object)); + + DeclarativeListProperty* data = reinterpret_cast(propList->data); + Shiboken::AutoDecRef retVal(PyObject_CallObject(data->count, args)); + + // Check return type + int cppResult = 0; + PythonToCppFunc pythonToCpp; + if (PyErr_Occurred()) + PyErr_Print(); + else if ((pythonToCpp = Shiboken::Conversions::isPythonToCppConvertible(Shiboken::Conversions::PrimitiveTypeConverter(), retVal))) + pythonToCpp(retVal, &cppResult); + return cppResult; +} + +// Implementation of QDeclarativeListProperty::AtFunction callback +QDeclarativeItem* propListAt(QDeclarativeListProperty* propList, int index) +{ + Shiboken::GilState state; + + Shiboken::AutoDecRef args(PyTuple_New(2)); + PyTuple_SET_ITEM(args, 0, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], propList->object)); + PyTuple_SET_ITEM(args, 1, Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter(), &index)); + + 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)) + Shiboken::Conversions::pythonToCppPointer((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QDECLARATIVEITEM_IDX], retVal, &result); + return result; +} + +// Implementation of QDeclarativeListProperty::ClearFunction callback +void propListClear(QDeclarativeListProperty* propList) +{ + Shiboken::GilState state; + + Shiboken::AutoDecRef args(PyTuple_New(1)); + PyTuple_SET_ITEM(args, 0, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], propList->object)); + + DeclarativeListProperty* data = reinterpret_cast(propList->data); + Shiboken::AutoDecRef retVal(PyObject_CallObject(data->clear, args)); + + if (PyErr_Occurred()) + PyErr_Print(); +} + +// qt_metacall specialization for ListProperties +static void propListMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::Call call, void** args) +{ + if (call != QMetaObject::ReadProperty) + return; + + DeclarativeListProperty* data = reinterpret_cast(PySide::Property::userData(pp)); + QObject* qobj; + Shiboken::Conversions::pythonToCppPointer((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], self, &qobj); + QDeclarativeListProperty declProp(qobj, data, &propListAppender); + + if (data->count) + declProp.count = &propListCount; + if (data->at) + declProp.at = &propListAt; + if (data->clear) + declProp.clear = &propListClear; + + // Copy the data to the memory location requested by the meta call + void* v = args[0]; + *reinterpret_cast*>(v) = declProp; +} + + +void PySide::initQmlSupport(PyObject* module) +{ + ElementFactory::init(); + + // Export DeclarativeListProperty type + if (PyType_Ready(&PropertyListType) < 0) + return; + + Py_INCREF((PyObject*)&PropertyListType); + PyModule_AddObject(module, PropertyListType.tp_name, (PyObject*)&PropertyListType); + +} + + diff --git a/PySide/QtDeclarative/pysideqmlregistertype.h b/PySide/QtDeclarative/pysideqmlregistertype.h new file mode 100644 index 00000000..aa252004 --- /dev/null +++ b/PySide/QtDeclarative/pysideqmlregistertype.h @@ -0,0 +1,57 @@ +/* + * This file is part of the Shiboken Python Bindings Generator project. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PYSIDEQMLREGISTERTYPE_H +#define PYSIDEQMLREGISTERTYPE_H + +#include + +struct SbkObjectType; + +namespace PySide +{ + +extern void* nextQmlElementMemoryAddr; + +/** + * Init the QML support doign things like registering QtDeclarative.ListProperty and create the necessary stuff for + * qmlRegisterType. + * + * \param module QtDeclarative python module + */ +void initQmlSupport(PyObject* module); + +/** + * PySide implementation of qmlRegisterType function. + * + * \param pyObj Python type to be registered. + * \param uri QML element uri. + * \param versionMajor QML component major version. + * \param versionMinor QML component minor version. + * \param qmlName QML element name + * \return the metatype id of the registered type. + */ +int qmlRegisterType(PyObject* pyObj, const char* uri, int versionMajor, int versionMinor, const char* qmlName); + +} + +#endif diff --git a/PySide/QtDeclarative/typesystem_declarative.xml b/PySide/QtDeclarative/typesystem_declarative.xml index 75c63e09..1bc18bad 100644 --- a/PySide/QtDeclarative/typesystem_declarative.xml +++ b/PySide/QtDeclarative/typesystem_declarative.xml @@ -23,43 +23,111 @@ + + + This function registers the Python type in the QML system with the name qmlName, in the library imported from uri having the version number composed from versionMajor and versionMinor. + Returns the QML type id. + + For example, this registers a Python class MySliderItem as a QML type named Slider for version 1.0 of a module called "com.mycompany.qmlcomponents": + + :: + + qmlRegisterType(MySliderItem, "com.mycompany.qmlcomponents", 1, 0, "Slider") + + Once this is registered, the type can be used in QML by importing the specified module name and version number: + + :: + + import com.mycompany.qmlcomponents 1.0 + + Slider { ... } + + Note that it's perfectly reasonable for a library to register types to older versions than the actual version of the library. Indeed, it is normal for the new library to allow QML written to previous versions to continue to work, even if more advanced versions of some of its types are available. + + + + int %0 = PySide::qmlRegisterType(%ARGUMENT_NAMES); + %PYARG_0 = %CONVERTTOPYTHON[int](%0); + + + + + - - Shiboken::TypeResolver::createValueTypeResolver< QList<QObject*> >("QList<QObject*>"); + + PySide::initQmlSupport(module); + + - - - + + QByteArray key("%FUNCTION_NAME_"); + key.append(%1.toLocal8Bit()); + Shiboken::Object::keepReference(reinterpret_cast<SbkObject*>(%PYSELF), key.constData(), %PYARG_2); + + + + + + + + + + + + + + + QString errorString; + %BEGIN_ALLOW_THREADS + %RETURN_TYPE ok_ = %CPPSELF.%FUNCTION_NAME(%1, %2, &errorString); + %END_ALLOW_THREADS + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](ok_)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](errorString)); + + - + + + + + + + + + + + + + @@ -78,7 +146,20 @@ - + + <code># create our data +ownerData = QDeclarativePropertyMap() +ownerData.insert("name", "John Smith") +ownerData.insert("phone", "555-5555") + +# expose it to the UI layer +view = QDeclarativeView() +ctxt = view.rootContext() +ctxt.setContextProperty("owner", ownerData) + +view.setSource(QUrl.fromLocalFile("main.qml")) +view.show()</code> + diff --git a/PySide/QtGui/CMakeLists.txt b/PySide/QtGui/CMakeLists.txt index 7178e60b..76256344 100644 --- a/PySide/QtGui/CMakeLists.txt +++ b/PySide/QtGui/CMakeLists.txt @@ -5,7 +5,7 @@ if(ENABLE_X11) ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qx11info_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qx11embedcontainer_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qx11embedwidget_wrapper.cpp - ) + ) if(Q_WS_MAEMO_5) set(SPECIFIC_OS_FILES @@ -15,9 +15,8 @@ if(ENABLE_X11) endif() endif() - if (${QT_VERSION_MAJOR} EQUAL 4 AND ${QT_VERSION_MINOR} LESS 6) - set (QtGui_46_SRC ) + set(QtGui_46_SRC "") else() set(QtGui_46_SRC ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qmatrix2x2_wrapper.cpp @@ -60,6 +59,31 @@ else() ) endif () +if (${QT_VERSION_MAJOR} EQUAL 4 AND ${QT_VERSION_MINOR} LESS 7) + set(QtGui_47_SRC "") +else() + set(QtGui_47_SRC + ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpainter_pixmapfragment_wrapper.cpp + ) +endif() + +set(QtGui_OPTIONAL_SRC ) +set(QtGui_DROPPED_ENTRIES ) +check_qt_class(QtGui QAbstractPageSetupDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QAbstractPrintDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QGtkStyle QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPageSetupDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrintDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrintEngine QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrintPreviewDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrintPreviewWidget QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrinter QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrinterInfo QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QSessionManager QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QSizeGrip QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QSystemTrayIcon QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QMacStyle QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) + qt4_wrap_cpp(QPYTEXTOBJECT_MOC "${pyside_SOURCE_DIR}/qpytextobject.h") set(QtGui_SRC @@ -225,6 +249,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpen_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpictureio_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpicture_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpixmapcache_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpixmapcache_key_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpixmap_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qplaintextdocumentlayout_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qplaintextedit_wrapper.cpp @@ -378,29 +403,17 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qwizard_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qworkspace_wrapper.cpp ${SPECIFIC_OS_FILES} +${QPYTEXTOBJECT_MOC} ${QtGui_46_SRC} +${QtGui_47_SRC} +${QtGui_OPTIONAL_SRC} ) - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/typesystem_gui.xml.in" "${CMAKE_CURRENT_BINARY_DIR}/typesystem_gui.xml" @ONLY) -check_qt_class(QtGui QGtkStyle QtGui_SRC) -check_qt_class(QtGui QSessionManager QtGui_SRC) -check_qt_class(QtGui QSizeGrip QtGui_SRC) -check_qt_class(QtGui QSystemTrayIcon QtGui_SRC) +set(QtGui_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtCore_BINARY_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}") -check_qt_class(QtGui QAbstractPageSetupDialog QtGui_SRC) -check_qt_class(QtGui QAbstractPrintDialog QtGui_SRC) -check_qt_class(QtGui QPageSetupDialog QtGui_SRC) -check_qt_class(QtGui QPrintDialog QtGui_SRC) -check_qt_class(QtGui QPrintPreviewWidget QtGui_SRC) -check_qt_class(QtGui QPrintPreviewDialog QtGui_SRC) -check_qt_class(QtGui QPrinter QtGui_SRC) -check_qt_class(QtGui QPrinterInfo QtGui_SRC) -check_qt_class(QtGui QPrintEngine QtGui_SRC) - -set(QtGui_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}") set(QtGui_include_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/ ${pyside_SOURCE_DIR} @@ -421,8 +434,7 @@ create_pyside_module(QtGui QtGui_deps QtGui_typesystem_path QtGui_SRC - "${CMAKE_CURRENT_BINARY_DIR}/typesystem_gui.xml" - QPYTEXTOBJECT_MOC) - + "" + ${CMAKE_CURRENT_BINARY_DIR}/typesystem_gui.xml) install(FILES ${pyside_SOURCE_DIR}/qpytextobject.h DESTINATION include/PySide/QtGui/) diff --git a/PySide/QtGui/glue/qapplication_init.cpp b/PySide/QtGui/glue/qapplication_init.cpp index 581e4dad..f2e972a6 100644 --- a/PySide/QtGui/glue/qapplication_init.cpp +++ b/PySide/QtGui/glue/qapplication_init.cpp @@ -5,39 +5,18 @@ static int QApplicationArgCount; static char** QApplicationArgValues; static const char QAPP_MACRO[] = "qApp"; -int Sbk_QApplication_Init(PyObject* self, PyObject* args, PyObject*) +bool QApplicationConstructorStart(PyObject* argv) { - if (Shiboken::Object::isUserType(self) && !Shiboken::ObjectType::canCallConstructor(self->ob_type, Shiboken::SbkType())) - return -1; - if (QApplication::instance()) { PyErr_SetString(PyExc_RuntimeError, "A QApplication instance already exists."); - return -1; - } - - int numArgs = PyTuple_GET_SIZE(args); - if (numArgs != 1) { - PyErr_BadArgument(); - return -1; - } - - if (!Shiboken::sequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QApplicationArgCount, &QApplicationArgValues, "PySideApp")) { - PyErr_BadArgument(); - return -1; + return false; } - SbkObject* sbkSelf = reinterpret_cast(self); - QApplicationWrapper* cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues); - Shiboken::Object::setCppPointer(sbkSelf, - Shiboken::SbkType(), - cptr); - Shiboken::Object::setValidCpp(sbkSelf, true); - Shiboken::Object::setHasCppWrapper(sbkSelf, true); - Shiboken::Object::releaseOwnership(sbkSelf); - Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr); - PySide::Signal::updateSourceObject(self); - cptr->metaObject(); + return Shiboken::sequenceToArgcArgv(argv, &QApplicationArgCount, &QApplicationArgValues, "PySideApp"); +} +void QApplicationConstructorEnd(PyObject* self) +{ // Verify if qApp is in main module PyObject* globalsDict = PyEval_GetGlobals(); if (globalsDict) { @@ -49,5 +28,23 @@ int Sbk_QApplication_Init(PyObject* self, PyObject* args, PyObject*) PyObject_SetAttrString(moduleQtGui, QAPP_MACRO, self); PySide::registerCleanupFunction(&PySide::destroyQCoreApplication); Py_INCREF(self); - return 1; +} + +static void QApplicationConstructor(PyObject* self, PyObject* argv, QApplicationWrapper** cptr) +{ + if (QApplicationConstructorStart(argv)) { + *cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues); + Shiboken::Object::releaseOwnership(reinterpret_cast(self)); + QApplicationConstructorEnd(self); + } +} + +template +static void QApplicationConstructor(PyObject* self, PyObject* argv, T extraArg, QApplicationWrapper** cptr) +{ + if (QApplicationConstructorStart(argv)) { + *cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues, extraArg); + Shiboken::Object::releaseOwnership(reinterpret_cast(self)); + QApplicationConstructorEnd(self); + } } diff --git a/PySide/QtGui/glue/qlayout_help_functions.cpp b/PySide/QtGui/glue/qlayout_help_functions.cpp new file mode 100644 index 00000000..b3660613 --- /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 8420cb3a..00000000 --- a/PySide/QtGui/glue/qlayout_help_functions.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef QLAYOUT_HELP_FUNCTIONS -#define QLAYOUT_HELP_FUNCTIONS - -void addLayoutOwnership(QLayout* layout, QLayoutItem* item); - -inline QByteArray retrieveObjectName(PyObject* obj) -{ - Shiboken::AutoDecRef objName(PyObject_Str(obj)); - return PyString_AsString(objName); -} - -inline void addLayoutOwnership(QLayout* layout, QWidget* widget) -{ - //transfer ownership to 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(widget)); - Shiboken::Object::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); - } else { - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(parent)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(widget)); - 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()) - 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) -{ - 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); -} - -#endif diff --git a/PySide/QtGui/glue/qmenu_glue.h b/PySide/QtGui/glue/qmenu_glue.cpp similarity index 88% rename from PySide/QtGui/glue/qmenu_glue.h rename to PySide/QtGui/glue/qmenu_glue.cpp index 94eab15e..0636dfab 100644 --- a/PySide/QtGui/glue/qmenu_glue.h +++ b/PySide/QtGui/glue/qmenu_glue.cpp @@ -1,4 +1,3 @@ - inline PyObject* addActionWithPyObject(QMenu* self, const QIcon& icon, const QString& text, PyObject* callback, const QKeySequence& shortcut) { QAction* act = new QAction(text, self); @@ -11,7 +10,7 @@ inline PyObject* addActionWithPyObject(QMenu* self, const QIcon& icon, const QSt self->addAction(act); - PyObject* pyAct = Shiboken::Converter::toPython(act); + PyObject* pyAct = %CONVERTTOPYTHON[QAction*](act); Shiboken::AutoDecRef result(PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, SIGNAL(triggered()), callback)); if (result.isNull()) { Py_DECREF(pyAct); diff --git a/PySide/QtGui/glue/qmenubar_glue.h b/PySide/QtGui/glue/qmenubar_glue.cpp similarity index 87% rename from PySide/QtGui/glue/qmenubar_glue.h rename to PySide/QtGui/glue/qmenubar_glue.cpp index 9568fa87..2326a76c 100644 --- a/PySide/QtGui/glue/qmenubar_glue.h +++ b/PySide/QtGui/glue/qmenubar_glue.cpp @@ -5,7 +5,7 @@ addActionWithPyObject(QMenuBar* self, const QString& text, PyObject* callback) self->addAction(act); - PyObject* pyAct = Shiboken::Converter::toPython(act); + PyObject* pyAct = %CONVERTTOPYTHON[QAction*](act); PyObject* result = PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, SIGNAL(triggered(bool)), callback); diff --git a/PySide/QtGui/glue/qtgui_qapp.cpp b/PySide/QtGui/glue/qtgui_qapp.cpp index f893f8e4..5148b579 100644 --- a/PySide/QtGui/glue/qtgui_qapp.cpp +++ b/PySide/QtGui/glue/qtgui_qapp.cpp @@ -1,4 +1,10 @@ // Init qApp macro to None. -Py_INCREF(Py_None); -PyModule_AddObject(module, "qApp", Py_None); +if (qApp) { + PyObject* pyApp = %CONVERTTOPYTHON[QApplication*](qApp); + Py_INCREF(pyApp); + PyModule_AddObject(module, "qApp", pyApp); +} else { + Py_INCREF(Py_None); + PyModule_AddObject(module, "qApp", Py_None); +} moduleQtGui = module; diff --git a/PySide/QtGui/glue/qwidget_glue.h b/PySide/QtGui/glue/qwidget_glue.cpp similarity index 80% rename from PySide/QtGui/glue/qwidget_glue.h rename to PySide/QtGui/glue/qwidget_glue.cpp index 9b20cb5b..cfa3f675 100644 --- a/PySide/QtGui/glue/qwidget_glue.h +++ b/PySide/QtGui/glue/qwidget_glue.cpp @@ -1,7 +1,7 @@ static QString retrieveObjectName(PyObject *obj) { Shiboken::AutoDecRef objName(PyObject_Str(obj)); - return QString(PyString_AsString(objName)); + return QString(Shiboken::String::toCString(objName)); } @@ -10,18 +10,18 @@ static QString retrieveObjectName(PyObject *obj) **/ static inline void qwidgetReparentLayout(QWidget *parent, QLayout *layout) { - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(parent)); + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](parent)); for (int i=0; i < layout->count(); i++) { QLayoutItem* item = layout->itemAt(i); - if (PyErr_Occurred()) + 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::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](w)); Shiboken::Object::setParent(pyParent, pyChild); } } else { @@ -31,7 +31,7 @@ static inline void qwidgetReparentLayout(QWidget *parent, QLayout *layout) } } - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(layout)); + 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); @@ -46,7 +46,7 @@ static inline void qwidgetSetLayout(QWidget *self, QLayout *layout) if (oldParent && oldParent != self) { if (oldParent->isWidgetType()) { // remove old parent policy - Shiboken::AutoDecRef pyLayout(Shiboken::Converter::toPython(layout)); + 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", diff --git a/PySide/QtGui/glue/wid_conversions.h b/PySide/QtGui/glue/wid_conversions.h deleted file mode 100644 index 9901218a..00000000 --- a/PySide/QtGui/glue/wid_conversions.h +++ /dev/null @@ -1,32 +0,0 @@ -namespace Shiboken { -template <> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return false; - } - - static bool isConvertible(PyObject* pyobj) - { - return PyCObject_Check(pyobj); - } - - static inline PyObject* toPython(void* cppobj) - { - // not supported - Q_ASSERT(true); - return 0; - } - - static PyObject* toPython(WId cppobj) - { - return PyCObject_FromVoidPtr(cppobj, 0); - } - - static WId toCpp(PyObject* pyobj) - { - return (WId) PyCObject_AsVoidPtr(pyobj); - } -}; -} diff --git a/PySide/QtGui/qpixmap_conversion.h b/PySide/QtGui/qpixmap_conversion.h deleted file mode 100644 index fc49af6b..00000000 --- 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 cf4b6744..552636af 100644 --- a/PySide/QtGui/typesystem_gui_common.xml +++ b/PySide/QtGui/typesystem_gui_common.xml @@ -22,11 +22,12 @@