From 5778103f5c86dc7f95bd79eabc24de4021eb2734 Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Fri, 30 Nov 2018 15:07:27 +0100 Subject: Move code to snippets and templates There was still leftover code on the typesystems but not all could be translated to snippets, so it was replace by templates. Task-number: PYSIDE-834 Change-Id: I7dbe2f15171ce6a60137be970312dc80622219c9 Reviewed-by: Qt CI Bot Reviewed-by: Alexandru Croitor --- .../PySide2/QtCore/typesystem_core_common.xml | 75 ++-------------------- .../PySide2/QtGui/typesystem_gui_common.xml | 11 ++-- .../QtWebKitWidgets/typesystem_webkitwidgets.xml | 12 +--- .../QtWidgets/typesystem_widgets_common.xml | 27 ++------ sources/pyside2/PySide2/glue/qtcore.cpp | 47 ++++++++++++++ sources/pyside2/PySide2/templates/gui_common.xml | 21 ++++++ .../PySide2/templates/webkitwidgets_common.xml | 18 ++++++ .../pyside2/PySide2/templates/widgets_common.xml | 37 +++++++++++ 8 files changed, 143 insertions(+), 105 deletions(-) diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 25f5c3e65..c70049d8e 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -670,30 +670,7 @@ - - { // Avoid name clash - Shiboken::AutoDecRef regFunc((PyObject*)NULL); - Shiboken::AutoDecRef atexit(Shiboken::Module::import("atexit")); - if (atexit.isNull()) { - qWarning() << "Module atexit not found for registering __moduleShutdown"; - PyErr_Clear(); - }else{ - regFunc.reset(PyObject_GetAttrString(atexit, "register")); - if (regFunc.isNull()) { - qWarning() << "Function atexit.register not found for registering __moduleShutdown"; - PyErr_Clear(); - } - } - if (!atexit.isNull() && !regFunc.isNull()){ - 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()); - } - } - - + @@ -2224,56 +2201,24 @@ - - - QByteArray ba(1 + int(%2), char(0)); - %CPPSELF.%FUNCTION_NAME(ba.data(), int(%2)); - %PYARG_0 = Shiboken::String::fromCString(ba.constData()); - + - - %RETURN_TYPE %out = 0; - 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(1 + int(%2), char(0)); - %CPPSELF.%FUNCTION_NAME(ba.data(), int(%2)); - %PYARG_0 = Shiboken::String::fromCString(ba.constData()); - + - - %RETURN_TYPE %out = 0; - 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); - } - + @@ -2768,13 +2713,7 @@ - - - - QString &res = *%0; - %PYARG_0 = %CONVERTTOPYTHON[QString](res); - - + @@ -2804,7 +2743,7 @@ - + diff --git a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml index d7bdf0412..16bce9d30 100644 --- a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml +++ b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml @@ -412,17 +412,16 @@ - PyObject *%out = Shiboken::Buffer::newObject(%in, size); + - Py_ssize_t bufferLen; - char *%out = reinterpret_cast<char*>(Shiboken::Buffer::getPointer(%PYARG_1, &bufferLen)); + - uint %out = bufferLen; + @@ -584,13 +583,13 @@ - const uchar *%out = reinterpret_cast<const uchar*>(PyBytes_AS_STRING(%PYARG_1)); + - uint %out = static_cast<uint>(PyBytes_Size(%PYARG_1)); + diff --git a/sources/pyside2/PySide2/QtWebKitWidgets/typesystem_webkitwidgets.xml b/sources/pyside2/PySide2/QtWebKitWidgets/typesystem_webkitwidgets.xml index 27a4835e2..dfabff81d 100644 --- a/sources/pyside2/PySide2/QtWebKitWidgets/typesystem_webkitwidgets.xml +++ b/sources/pyside2/PySide2/QtWebKitWidgets/typesystem_webkitwidgets.xml @@ -185,22 +185,16 @@ - QString _local; - QString* %4 = &_local; + - Shiboken::AutoDecRef pyRes(PySequence_GetItem(%PYARG_0, 0)); - Shiboken::AutoDecRef pyStr(PySequence_GetItem(%PYARG_0, 1)); - %RETURN_TYPE %out = %CONVERTTOCPP[%RETURN_TYPE](pyRes); - *%4 = %CONVERTTOCPP[QString](pyStr); + - %PYARG_0 = PyTuple_New(2); - PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](%0)); - PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](*%4)); + diff --git a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml index 13cc6f7cf..dba6c268d 100644 --- a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml +++ b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml @@ -1479,46 +1479,29 @@ - int %out = PySequence_Size(%PYARG_1); + - int numItems = PySequence_Size(%PYARG_1); - Shiboken::AutoArrayPointer<QGraphicsItem*> %out(numItems); - for (int i=0; i < numItems; i++) { - %out[i] = %CONVERTTOCPP[QGraphicsItem*](PySequence_Fast_GET_ITEM(%PYARG_1, i)); - } + - Shiboken::AutoDecRef object(PyList_New(0)); - for (int i=0, max=numItems; i < max; i++) { - PyList_Append(object, %CONVERTTOPYTHON[QGraphicsItem*](%in[i])); - } - PyObject *%out = object.object(); + - Shiboken::AutoDecRef option_object(PyList_New(0)); - for (int i=0, max=numItems; i < max; i++) { - const QStyleOptionGraphicsItem* item = &%in[i]; - PyList_Append(option_object, %CONVERTTOPYTHON[QStyleOptionGraphicsItem](item)); - } - PyObject* %out = option_object.object(); + - int numOptions = PySequence_Size(%PYARG_2); - Shiboken::AutoArrayPointer<QStyleOptionGraphicsItem> %out(numOptions); - for (int i=0; i < numOptions; i++) { - %out[i] = %CONVERTTOCPP[QStyleOptionGraphicsItem](PySequence_Fast_GET_ITEM(%PYARG_1, i)); - } + diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 47895bdda..4c77e9e87 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -1493,6 +1493,53 @@ QT_END_NAMESPACE %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](_cpp_result); // @snippet stream-read-method +// @snippet return-qstring-ref +QString &res = *%0; +%PYARG_0 = %CONVERTTOPYTHON[QString](res); +// @snippet return-qstring-ref + +// @snippet return-readData +%RETURN_TYPE %0 = 0; +if (PyBytes_Check(%PYARG_0)) { + %0 = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %0); +} else if (Shiboken::String::check(%PYARG_0)) { + %0 = Shiboken::String::len((PyObject*)%PYARG_0); + memcpy(%1, Shiboken::String::toCString((PyObject*)%PYARG_0), %0); +} +// @snippet return-readData + +// @snippet qiodevice-readData +QByteArray ba(1 + int(%2), char(0)); +%CPPSELF.%FUNCTION_NAME(ba.data(), int(%2)); +%PYARG_0 = Shiboken::String::fromCString(ba.constData()); +// @snippet qiodevice-readData + +// @snippet qt-module-shutdown +{ // Avoid name clash + Shiboken::AutoDecRef regFunc((PyObject*)NULL); + Shiboken::AutoDecRef atexit(Shiboken::Module::import("atexit")); + if (atexit.isNull()) { + qWarning("Module atexit not found for registering __moduleShutdown"); + PyErr_Clear(); + }else{ + regFunc.reset(PyObject_GetAttrString(atexit, "register")); + if (regFunc.isNull()) { + qWarning("Function atexit.register not found for registering __moduleShutdown"); + PyErr_Clear(); + } + } + if (!atexit.isNull() && !regFunc.isNull()){ + 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()); + } +} +// @snippet qt-module-shutdown + + /********************************************************************* * CONVERSIONS ********************************************************************/ diff --git a/sources/pyside2/PySide2/templates/gui_common.xml b/sources/pyside2/PySide2/templates/gui_common.xml index 227d0a460..d25d50014 100644 --- a/sources/pyside2/PySide2/templates/gui_common.xml +++ b/sources/pyside2/PySide2/templates/gui_common.xml @@ -287,5 +287,26 @@ %PYARG_0 = %CONVERTTOPYTHON[%CPPSELF_TYPE](_tmp); + + + + + + + + + + diff --git a/sources/pyside2/PySide2/templates/webkitwidgets_common.xml b/sources/pyside2/PySide2/templates/webkitwidgets_common.xml index fa70c8de7..43e560c5f 100644 --- a/sources/pyside2/PySide2/templates/webkitwidgets_common.xml +++ b/sources/pyside2/PySide2/templates/webkitwidgets_common.xml @@ -52,4 +52,22 @@ } + + + + + + diff --git a/sources/pyside2/PySide2/templates/widgets_common.xml b/sources/pyside2/PySide2/templates/widgets_common.xml index b68739533..e63785bb2 100644 --- a/sources/pyside2/PySide2/templates/widgets_common.xml +++ b/sources/pyside2/PySide2/templates/widgets_common.xml @@ -51,4 +51,41 @@ Shiboken::Object::setParent(%PYSELF, $PYARG); + + + + + + + + + + -- cgit v1.2.3