summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-11-29 09:29:48 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-11-29 14:36:49 +0000
commit36a9cd48344c8cfb776dea78c60e7d6760711197 (patch)
treed698778c95c8c891e01f683a1dd52dceb0d9026e
parent6007f0785a0107204c522e466f82bd817fcf60f9 (diff)
Move add-conversion and native-to-target code
Now we are able to include snippets for the previously mentioned typesystem's tags, so this patch removes the current C/C++ code from the typesystems. Task-number: PYSIDE-834 Change-Id: I2929020fa1dc0859db780dffb12fa292627697b0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--sources/pyside2/PySide2/QtCore/typesystem_core_common.xml315
-rw-r--r--sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml8
-rw-r--r--sources/pyside2/PySide2/glue/qtcore.cpp279
-rw-r--r--sources/pyside2/PySide2/glue/qtgui.cpp22
-rw-r--r--sources/pyside2/PySide2/glue/qtwidgets.cpp12
5 files changed, 361 insertions, 275 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
index 8aade34a..ca9a56c6 100644
--- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
+++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
@@ -206,13 +206,9 @@
<primitive-type name="bool" target-lang-api-name="PyBool">
<conversion-rule>
- <native-to-target>
- return PyBool_FromLong((bool)%in);
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pybool"/>
<target-to-native>
- <add-conversion type="PyBool">
- %out = %OUTTYPE(%in == Py_True);
- </add-conversion>
+ <add-conversion type="PyBool" file="../glue/qtcore.cpp" snippet="conversion-pybool"/>
</target-to-native>
</conversion-rule>
</primitive-type>
@@ -220,37 +216,25 @@
<!-- Qt5: add the new pointer-ish types -->
<primitive-type name="qintptr" target-lang-api-name="PyLong">
<conversion-rule>
- <native-to-target>
- return PyLong_FromLong(%in);
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pylong"/>
<target-to-native>
- <add-conversion type="PyLong">
- %out = %OUTTYPE(PyLong_AsLong(%in));
- </add-conversion>
+ <add-conversion type="PyLong" file="../glue/qtcore.cpp" snippet="conversion-pylong"/>
</target-to-native>
</conversion-rule>
</primitive-type>
<primitive-type name="quintptr" target-lang-api-name="PyLong">
<conversion-rule>
- <native-to-target>
- return PyLong_FromUnsignedLong(%in);
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pylong-unsigned"/>
<target-to-native>
- <add-conversion type="PyLong">
- %out = %OUTTYPE(PyLong_AsUnsignedLong(%in));
- </add-conversion>
+ <add-conversion type="PyLong" file="../glue/qtcore.cpp" snippet="conversion-pylong-unsigned"/>
</target-to-native>
</conversion-rule>
</primitive-type>
<primitive-type name="qptrdiff" target-lang-api-name="PyLong">
<conversion-rule>
- <native-to-target>
- return PyLong_FromLong(%in);
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pylong"/>
<target-to-native>
- <add-conversion type="PyLong">
- %out = %OUTTYPE(PyLong_AsLong(%in));
- </add-conversion>
+ <add-conversion type="PyLong" file="../glue/qtcore.cpp" snippet="conversion-pylong"/>
</target-to-native>
</conversion-rule>
</primitive-type>
@@ -260,201 +244,61 @@
<primitive-type name="QString" target-lang-api-name="PyUnicode">
<include file-name="QString" location="global"/>
<conversion-rule>
- <native-to-target>
- QByteArray ba = %in.toUtf8();
- PyObject *%out = PyUnicode_FromStringAndSize(ba.constData(), ba.size());
- return %out;
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pyunicode"/>
<target-to-native>
- <add-conversion type="PyUnicode">
- #ifndef Py_LIMITED_API
- 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((const ushort*)unicode, PyUnicode_GET_SIZE(%in));
- # endif
- #else
- wchar_t *temp = PyUnicode_AsWideCharString(%in, NULL);
- %out = QString::fromWCharArray(temp);
- PyMem_Free(temp);
- #endif
- </add-conversion>
- <add-conversion type="PyString" check="py2kStrCheck(%in)">
- #ifndef IS_PY3K
- const char* str = %CONVERTTOCPP[const char*](%in);
- %out = %OUTTYPE(str);
- #endif
- </add-conversion>
- <add-conversion type="Py_None">
- %out = %OUTTYPE();
- </add-conversion>
+ <add-conversion type="PyUnicode" file="../glue/qtcore.cpp" snippet="conversion-pyunicode"/>
+ <add-conversion type="PyString" check="py2kStrCheck(%in)" file="../glue/qtcore.cpp" snippet="conversion-pystring"/>
+ <add-conversion type="Py_None" file="../glue/qtcore.cpp" snippet="conversion-pynone"/>
</target-to-native>
</conversion-rule>
</primitive-type>
<primitive-type name="QStringRef">
<conversion-rule>
- <native-to-target>
- 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;
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pyunicode-qstringref"/>
</conversion-rule>
</primitive-type>
<primitive-type name="QChar">
<conversion-rule>
- <native-to-target>
- wchar_t c = (wchar_t)%in.unicode();
- return PyUnicode_FromWideChar(&amp;c, 1);
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pyunicode-qchar"/>
<target-to-native>
- <add-conversion type="PyString" check="Shiboken::String::checkChar(%in)">
- char c = %CONVERTTOCPP[char](%in);
- %out = %OUTTYPE(c);
- </add-conversion>
- <add-conversion type="PyInt">
- int i = %CONVERTTOCPP[int](%in);
- %out = %OUTTYPE(i);
- </add-conversion>
- <add-conversion type="Py_None">
- %out = %OUTTYPE();
- </add-conversion>
+ <add-conversion type="PyString" check="Shiboken::String::checkChar(%in)" file="../glue/qtcore.cpp" snippet="conversion-pystring-char"/>
+ <add-conversion type="PyInt" file="../glue/qtcore.cpp" snippet="conversion-pyint"/>
+ <add-conversion type="Py_None" file="../glue/qtcore.cpp" snippet="conversion-pynone"/>
</target-to-native>
</conversion-rule>
</primitive-type>
<primitive-type name="QVariant" target-lang-api-name="PyObject">
<conversion-rule>
- <native-to-target>
- if (!%in.isValid())
- Py_RETURN_NONE;
-
- if (qstrcmp(%in.typeName(), "QVariantList") == 0) {
- QList&lt;QVariant&gt; var = %in.value&lt;QVariantList&gt;();
- return %CONVERTTOPYTHON[QList&lt;QVariant&gt;](var);
- }
-
- if (qstrcmp(%in.typeName(), "QStringList") == 0) {
- QStringList var = %in.value&lt;QStringList&gt;();
- return %CONVERTTOPYTHON[QList&lt;QString&gt;](var);
- }
-
- if (qstrcmp(%in.typeName(), "QVariantMap") == 0) {
- QMap&lt;QString, QVariant&gt; var = %in.value&lt;QVariantMap&gt;();
- return %CONVERTTOPYTHON[QMap&lt;QString, QVariant&gt;](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;
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-qvariant"/>
<target-to-native>
- <add-conversion type="PyBool">
- %out = %OUTTYPE(%in == Py_True);
- </add-conversion>
- <add-conversion type="Py_None">
- %out = %OUTTYPE();
- </add-conversion>
- <add-conversion type="QString" check="Shiboken::String::check(%in)">
- QString in = %CONVERTTOCPP[QString](%in);
- %out = %OUTTYPE(in);
- </add-conversion>
- <add-conversion type="QByteArray">
- QByteArray in = %CONVERTTOCPP[QByteArray](%in);
- %out = %OUTTYPE(in);
- </add-conversion>
- <add-conversion type="PyFloat" check="PyFloat_CheckExact(%in)">
- double in = %CONVERTTOCPP[double](%in);
- %out = %OUTTYPE(in);
- </add-conversion>
+ <add-conversion type="PyBool" file="../glue/qtcore.cpp" snippet="conversion-pybool"/>
+ <add-conversion type="Py_None" file="../glue/qtcore.cpp" snippet="conversion-pynone"/>
+ <add-conversion type="QString" check="Shiboken::String::check(%in)" file="../glue/qtcore.cpp" snippet="conversion-qstring"/>
+ <add-conversion type="QByteArray" file="../glue/qtcore.cpp" snippet="conversion-qbytearray"/>
+ <add-conversion type="PyFloat" check="PyFloat_CheckExact(%in)" file="../glue/qtcore.cpp" snippet="conversion-pyfloat"/>
<!-- Using PyLong instead of PyInt to support Python2 and 3-->
- <add-conversion type="PyInt" check="PyInt_CheckExact(%in)">
- qlonglong in = %CONVERTTOCPP[qlonglong](%in);
- %out = %OUTTYPE(in);
- </add-conversion>
- <add-conversion type="PyLong" check="PyLong_CheckExact(%in)">
- qlonglong in = %CONVERTTOCPP[qlonglong](%in);
- %out = %OUTTYPE(in);
- </add-conversion>
- <add-conversion type="SbkEnumType">
- int in = %CONVERTTOCPP[int](%in);
- %out = %OUTTYPE(in);
- </add-conversion>
- <add-conversion type="SbkObject">
- // a class supported by QVariant?
- int typeCode;
- const char *typeName = QVariant_resolveMetaType(Py_TYPE(%in), &amp;typeCode);
- if (!typeCode || !typeName)
- return;
- QVariant var(typeCode, (void*)0);
- Shiboken::Conversions::SpecificConverter converter(typeName);
- converter.toCpp(pyIn, var.data());
- %out = var;
- </add-conversion>
- <add-conversion type="PyDict" check="PyDict_CheckExact(%in)">
- QVariant ret = QVariant_convertToVariantMap(%in);
- %out = ret.isValid() ? ret : QVariant::fromValue(PySide::PyObjectWrapper(%in));
- </add-conversion>
- <add-conversion type="PyList" check="PyList_Check(%in)">
- QVariant ret = QVariant_convertToVariantList(%in);
- %out = ret.isValid() ? ret : QVariant::fromValue(PySide::PyObjectWrapper(%in));
- </add-conversion>
- <add-conversion type="PyObject">
- // Is a shiboken type not known by Qt
- %out = QVariant::fromValue(PySide::PyObjectWrapper(%in));
- </add-conversion>
+ <add-conversion type="PyInt" check="PyInt_CheckExact(%in)" file="../glue/qtcore.cpp" snippet="conversion-qlonglong"/>
+ <add-conversion type="PyLong" check="PyLong_CheckExact(%in)" file="../glue/qtcore.cpp" snippet="conversion-qlonglong"/>
+ <add-conversion type="SbkEnumType" file="../glue/qtcore.cpp" snippet="conversion-pyint"/>
+ <add-conversion type="SbkObject" file="../glue/qtcore.cpp" snippet="conversion-sbkobject"/>
+ <add-conversion type="PyDict" check="PyDict_CheckExact(%in)" file="../glue/qtcore.cpp" snippet="conversion-pydict"/>
+ <add-conversion type="PyList" check="PyList_Check(%in)" file="../glue/qtcore.cpp" snippet="conversion-pylist"/>
+ <add-conversion type="PyObject" file="../glue/qtcore.cpp" snippet="conversion-pyobject"/>
</target-to-native>
</conversion-rule>
</primitive-type>
<inject-code class="native" position="beginning" file="../glue/qtcore.cpp" snippet="qvariant-conversion"/>
<primitive-type name="QVariant::Type" default-constructor="QVariant::Invalid">
<conversion-rule>
- <native-to-target>
- const char *typeName = QVariant::typeToName(%in);
- PyObject *%out;
- PyTypeObject *pyType = nullptr;
- if (typeName)
- pyType = Shiboken::Conversions::getPythonTypeObject(typeName);
- %out = pyType ? (reinterpret_cast&lt;PyObject*&gt;(pyType)) : Py_None;
- Py_INCREF(%out);
- return %out;
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-qvariant-type"/>
<target-to-native>
- <add-conversion type="Py_None">
- %out = QVariant::Invalid;
- </add-conversion>
- <add-conversion type="PyTypeObject">
- const char *typeName;
- if (Shiboken::String::checkType(reinterpret_cast&lt;PyTypeObject *&gt;(%in)))
- typeName = "QString";
- else if (%in == reinterpret_cast&lt;PyObject*&gt;(&amp;PyFloat_Type))
- typeName = "double"; // float is a UserType in QVariant.
- else if (%in == reinterpret_cast&lt;PyObject*&gt;(&amp;PyLong_Type))
- typeName = "int"; // long is a UserType in QVariant.
- else if (Py_TYPE(%in) == SbkObjectType_TypeF())
- typeName = Shiboken::ObjectType::getOriginalName((SbkObjectType*)%in);
- else
- typeName = reinterpret_cast&lt;PyTypeObject *&gt;(%in)->tp_name;
- %out = QVariant::nameToType(typeName);
- </add-conversion>
- <add-conversion type="PyString" check="Shiboken::String::check(%in)">
- %out = QVariant::nameToType(Shiboken::String::toCString(%in));
- </add-conversion>
- <add-conversion type="PyDict" check="PyDict_Check(%in) &amp;&amp; QVariantType_checkAllStringKeys(%in)">
- %out = QVariant::nameToType("QVariantMap");
- </add-conversion>
- <add-conversion type="PySequence">
- %out = QVariantType_isStringList(%in) ? QVariant::StringList : QVariant::List;
- </add-conversion>
+ <add-conversion type="Py_None" file="../glue/qtcore.cpp" snippet="conversion-qvariant-invalid"/>
+ <add-conversion type="PyTypeObject" file="../glue/qtcore.cpp" snippet="conversion-qvariant-pytypeobject"/>
+ <add-conversion type="PyString" check="Shiboken::String::check(%in)" file="../glue/qtcore.cpp" snippet="conversion-qvariant-pystring"/>
+ <add-conversion type="PyDict" check="PyDict_Check(%in) &amp;&amp; QVariantType_checkAllStringKeys(%in)" file="../glue/qtcore.cpp" snippet="conversion-qvariant-pydict"/>
+ <add-conversion type="PySequence" file="../glue/qtcore.cpp" snippet="conversion-qvariant-pysequence"/>
</target-to-native>
</conversion-rule>
</primitive-type>
@@ -515,22 +359,9 @@
<primitive-type name="QJsonObject">
<conversion-rule>
- <native-to-target>
- // The QVariantMap returned by QJsonObject seems to cause a segfault, so
- // using QJsonObject.toVariantMap() won't work.
- // Wrapping it in a QJsonValue first allows it to work
- QJsonValue val(%in);
- QVariant ret = val.toVariant();
-
- return %CONVERTTOPYTHON[QVariant](ret);
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-qjsonobject"/>
<target-to-native>
- <add-conversion type="PyDict">
- QVariant dict = QVariant_convertToVariantMap(%in);
- QJsonValue val = QJsonValue::fromVariant(dict);
-
- %out = val.toObject();
- </add-conversion>
+ <add-conversion type="PyDict" file="../glue/qtcore.cpp" snippet="conversion-qjsonobject-pydict"/>
</target-to-native>
</conversion-rule>
</primitive-type>
@@ -683,17 +514,9 @@
<container-type name="QPair" type="pair">
<include file-name="QPair" location="global"/>
<conversion-rule>
- <native-to-target>
- 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;
- </native-to-target>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-qpair"/>
<target-to-native>
- <add-conversion type="PySequence">
- %out.first = %CONVERTTOCPP[%OUTTYPE_0](PySequence_Fast_GET_ITEM(%in, 0));
- %out.second = %CONVERTTOCPP[%OUTTYPE_1](PySequence_Fast_GET_ITEM(%in, 1));
- </add-conversion>
+ <add-conversion type="PySequence" file="../glue/qtcore.cpp" snippet="conversion-qpair-pysequence"/>
</target-to-native>
</conversion-rule>
</container-type>
@@ -995,15 +818,8 @@
</inject-code>
<conversion-rule>
<target-to-native>
- <add-conversion type="Py_None">
- %out = %OUTTYPE();
- </add-conversion>
- <add-conversion type="PyDate" check="PyDateTime_ImportAndCheck(%in)">
- int day = PyDateTime_GET_DAY(%in);
- int month = PyDateTime_GET_MONTH(%in);
- int year = PyDateTime_GET_YEAR(%in);
- %out = %OUTTYPE(year, month, day);
- </add-conversion>
+ <add-conversion type="Py_None" file="../glue/qtcore.cpp" snippet="conversion-pynone"/>
+ <add-conversion type="PyDate" check="PyDateTime_ImportAndCheck(%in)" file="../glue/qtcore.cpp" snippet="conversion-qdate-pydate"/>
</target-to-native>
</conversion-rule>
<extra-includes>
@@ -1063,19 +879,8 @@
</inject-code>
<conversion-rule>
<target-to-native>
- <add-conversion type="Py_None">
- %out = %OUTTYPE();
- </add-conversion>
- <add-conversion type="PyDateTime" check="PyDateTime_ImportAndCheck(%in)">
- 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));
- </add-conversion>
+ <add-conversion type="Py_None" file="../glue/qtcore.cpp" snippet="conversion-pynone"/>
+ <add-conversion type="PyDateTime" check="PyDateTime_ImportAndCheck(%in)" file="../glue/qtcore.cpp" snippet="conversion-qdatetime-pydatetime"/>
</target-to-native>
</conversion-rule>
<extra-includes>
@@ -1398,16 +1203,8 @@
</inject-code>
<conversion-rule>
<target-to-native>
- <add-conversion type="Py_None">
- %out = %OUTTYPE();
- </add-conversion>
- <add-conversion type="PyTime" check="PyDateTime_ImportAndCheck(%in)">
- 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);
- </add-conversion>
+ <add-conversion type="Py_None" file="../glue/qtcore.cpp" snippet="conversion-pynone"/>
+ <add-conversion type="PyTime" check="PyDateTime_ImportAndCheck(%in)" file="../glue/qtcore.cpp" snippet="conversion-qtime-pytime"/>
</target-to-native>
</conversion-rule>
@@ -2045,22 +1842,10 @@
<enum-type name="Base64Option" flags="Base64Options" since="5.2"/>
<conversion-rule>
<target-to-native>
- <add-conversion type="Py_None">
- %out = %OUTTYPE();
- </add-conversion>
- <add-conversion type="PyBytes">
- #ifdef IS_PY3K
- %out = %OUTTYPE(PyBytes_AS_STRING(%in), PyBytes_GET_SIZE(%in));
- #else
- %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in));
- #endif
- </add-conversion>
- <add-conversion type="PyByteArray">
- %out = %OUTTYPE(PyByteArray_AsString(%in), PyByteArray_Size(%in));
- </add-conversion>
- <add-conversion type="PyString" check="Shiboken::String::check(%in) &amp;&amp; !PyUnicode_Check(%in)">
- %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in));
- </add-conversion>
+ <add-conversion type="Py_None" file="../glue/qtcore.cpp" snippet="conversion-pynone"/>
+ <add-conversion type="PyBytes" file="../glue/qtcore.cpp" snippet="conversion-qbytearray-pybytes"/>
+ <add-conversion type="PyByteArray" file="../glue/qtcore.cpp" snippet="conversion-qbytearray-pybytearray"/>
+ <add-conversion type="PyString" check="Shiboken::String::check(%in) &amp;&amp; !PyUnicode_Check(%in)" file="../glue/qtcore.cpp" snippet="conversion-qbytearray-pystring"/>
</target-to-native>
</conversion-rule>
diff --git a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml
index 090b7a4e..f417b8e7 100644
--- a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml
+++ b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml
@@ -203,13 +203,9 @@
<primitive-type name="WId" target-lang-api-name="PyLong">
<conversion-rule>
- <native-to-target>
- return PyLong_FromVoidPtr(reinterpret_cast&lt;void *&gt;(%in));
- </native-to-target>
+ <native-to-target file="../glue/qtgui.cpp" snippet="return-pylong-voidptr"/>
<target-to-native>
- <add-conversion type="PyLong">
- %out = reinterpret_cast&lt;%OUTTYPE&gt;(PyLong_AsVoidPtr(%in));
- </add-conversion>
+ <add-conversion type="PyLong" file="../glue/qtgui.cpp" snippet="conversion-pylong"/>
</target-to-native>
</conversion-rule>
</primitive-type>
diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp
index 084004ce..73b9476d 100644
--- a/sources/pyside2/PySide2/glue/qtcore.cpp
+++ b/sources/pyside2/PySide2/glue/qtcore.cpp
@@ -37,6 +37,10 @@
**
****************************************************************************/
+/*********************************************************************
+ * INJECT CODE
+ ********************************************************************/
+
// @snippet include-pyside
#include <pyside.h>
// @snippet include-pyside
@@ -1034,3 +1038,278 @@ QT_END_NAMESPACE
(*%CPPSELF) >> _cpp_result;
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](_cpp_result);
// @snippet stream-read-method
+
+/*********************************************************************
+ * CONVERSIONS
+ ********************************************************************/
+
+// @snippet conversion-pybool
+%out = %OUTTYPE(%in == Py_True);
+// @snippet conversion-pybool
+
+// @snippet conversion-pylong
+%out = %OUTTYPE(PyLong_AsLong(%in));
+// @snippet conversion-pylong
+
+// @snippet conversion-pylong-unsigned
+%out = %OUTTYPE(PyLong_AsUnsignedLong(%in));
+// @snippet conversion-pylong-unsigned
+
+// @snippet conversion-pyunicode
+#ifndef Py_LIMITED_API
+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((const ushort*)unicode, PyUnicode_GET_SIZE(%in));
+# endif
+#else
+wchar_t *temp = PyUnicode_AsWideCharString(%in, NULL);
+%out = QString::fromWCharArray(temp);
+PyMem_Free(temp);
+#endif
+// @snippet conversion-pyunicode
+
+// @snippet conversion-pystring
+#ifndef IS_PY3K
+const char* str = %CONVERTTOCPP[const char*](%in);
+%out = %OUTTYPE(str);
+#endif
+// @snippet conversion-pystring
+
+// @snippet conversion-pynone
+%out = %OUTTYPE();
+// @snippet conversion-pynone
+
+// @snippet conversion-pystring-char
+char c = %CONVERTTOCPP[char](%in);
+%out = %OUTTYPE(c);
+// @snippet conversion-pystring-char
+
+// @snippet conversion-pyint
+int i = %CONVERTTOCPP[int](%in);
+%out = %OUTTYPE(i);
+// @snippet conversion-pyint
+
+// @snippet conversion-qlonglong
+qlonglong in = %CONVERTTOCPP[qlonglong](%in);
+%out = %OUTTYPE(in);
+// @snippet conversion-qlonglong
+
+// @snippet conversion-qstring
+QString in = %CONVERTTOCPP[QString](%in);
+%out = %OUTTYPE(in);
+// @snippet conversion-qstring
+
+// @snippet conversion-qbytearray
+QByteArray in = %CONVERTTOCPP[QByteArray](%in);
+%out = %OUTTYPE(in);
+// @snippet conversion-qbytearray
+
+// @snippet conversion-pyfloat
+double in = %CONVERTTOCPP[double](%in);
+%out = %OUTTYPE(in);
+// @snippet conversion-pyfloat
+
+// @snippet conversion-sbkobject
+// a class supported by QVariant?
+int typeCode;
+const char *typeName = QVariant_resolveMetaType(Py_TYPE(%in), &typeCode);
+if (!typeCode || !typeName)
+ return;
+QVariant var(typeCode, (void*)0);
+Shiboken::Conversions::SpecificConverter converter(typeName);
+converter.toCpp(pyIn, var.data());
+%out = var;
+// @snippet conversion-sbkobject
+
+// @snippet conversion-pydict
+QVariant ret = QVariant_convertToVariantMap(%in);
+%out = ret.isValid() ? ret : QVariant::fromValue(PySide::PyObjectWrapper(%in));
+// @snippet conversion-pydict
+
+// @snippet conversion-pylist
+QVariant ret = QVariant_convertToVariantList(%in);
+%out = ret.isValid() ? ret : QVariant::fromValue(PySide::PyObjectWrapper(%in));
+// @snippet conversion-pylist
+
+// @snippet conversion-pyobject
+// Is a shiboken type not known by Qt
+%out = QVariant::fromValue(PySide::PyObjectWrapper(%in));
+// @snippet conversion-pyobject
+
+// @snippet conversion-qvariant-invalid
+%out = QVariant::Invalid;
+// @snippet conversion-qvariant-invalid
+
+// @snippet conversion-qvariant-pytypeobject
+const char *typeName;
+if (Shiboken::String::checkType(reinterpret_cast<PyTypeObject *>(%in)))
+ typeName = "QString";
+else if (%in == reinterpret_cast<PyObject*>(&PyFloat_Type))
+ typeName = "double"; // float is a UserType in QVariant.
+else if (%in == reinterpret_cast<PyObject*>(&PyLong_Type))
+ typeName = "int"; // long is a UserType in QVariant.
+else if (Py_TYPE(%in) == SbkObjectType_TypeF())
+ typeName = Shiboken::ObjectType::getOriginalName((SbkObjectType*)%in);
+else
+ typeName = reinterpret_cast<PyTypeObject *>(%in)->tp_name;
+%out = QVariant::nameToType(typeName);
+// @snippet conversion-qvariant-pytypeobject
+
+// @snippet conversion-qvariant-pystring
+%out = QVariant::nameToType(Shiboken::String::toCString(%in));
+// @snippet conversion-qvariant-pystring
+
+// @snippet conversion-qvariant-pydict
+%out = QVariant::nameToType("QVariantMap");
+// @snippet conversion-qvariant-pydict
+
+// @snippet conversion-qvariant-pysequence
+%out = QVariantType_isStringList(%in) ? QVariant::StringList : QVariant::List;
+// @snippet conversion-qvariant-pysequence
+
+// @snippet conversion-qjsonobject-pydict
+QVariant dict = QVariant_convertToVariantMap(%in);
+QJsonValue val = QJsonValue::fromVariant(dict);
+%out = val.toObject();
+// @snippet conversion-qjsonobject-pydict
+
+// @snippet conversion-qpair-pysequence
+%out.first = %CONVERTTOCPP[%OUTTYPE_0](PySequence_Fast_GET_ITEM(%in, 0));
+%out.second = %CONVERTTOCPP[%OUTTYPE_1](PySequence_Fast_GET_ITEM(%in, 1));
+// @snippet conversion-qpair-pysequence
+
+// @snippet conversion-qdate-pydate
+int day = PyDateTime_GET_DAY(%in);
+int month = PyDateTime_GET_MONTH(%in);
+int year = PyDateTime_GET_YEAR(%in);
+%out = %OUTTYPE(year, month, day);
+// @snippet conversion-qdate-pydate
+
+// @snippet conversion-qdatetime-pydatetime
+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));
+// @snippet conversion-qdatetime-pydatetime
+
+// @snippet conversion-qtime-pytime
+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);
+// @snippet conversion-qtime-pytime
+
+// @snippet conversion-qbytearray-pybytes
+#ifdef IS_PY3K
+%out = %OUTTYPE(PyBytes_AS_STRING(%in), PyBytes_GET_SIZE(%in));
+#else
+%out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in));
+#endif
+// @snippet conversion-qbytearray-pybytes
+
+// @snippet conversion-qbytearray-pybytearray
+%out = %OUTTYPE(PyByteArray_AsString(%in), PyByteArray_Size(%in));
+// @snippet conversion-qbytearray-pybytearray
+
+// @snippet conversion-qbytearray-pystring
+%out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in));
+// @snippet conversion-qbytearray-pystring
+
+/*********************************************************************
+ * NATIVE TO TARGET CONVERSIONS
+ ********************************************************************/
+
+// @snippet return-pybool
+return PyBool_FromLong((bool)%in);
+// @snippet return-pybool
+
+// @snippet return-pylong
+return PyLong_FromLong(%in);
+// @snippet return-pylong
+
+// @snippet return-pylong-unsigned
+return PyLong_FromUnsignedLong(%in);
+// @snippet return-pylong-unsigned
+
+// @snippet return-pyunicode
+QByteArray ba = %in.toUtf8();
+return PyUnicode_FromStringAndSize(ba.constData(), ba.size());
+// @snippet return-pyunicode
+
+// @snippet return-pyunicode-qstringref
+ const int N = %in.length();
+ wchar_t *str = new wchar_t[N];
+ %in.toString().toWCharArray(str);
+ PyObject *%out = PyUnicode_FromWideChar(str, N);
+ delete[] str;
+ return %out;
+// @snippet return-pyunicode-qstringref
+
+// @snippet return-pyunicode-qchar
+wchar_t c = (wchar_t)%in.unicode();
+return PyUnicode_FromWideChar(&c, 1);
+// @snippet return-pyunicode-qchar
+
+// @snippet return-qvariant
+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;
+// @snippet return-qvariant
+
+// @snippet return-qvariant-type
+const char *typeName = QVariant::typeToName(%in);
+PyObject *%out;
+PyTypeObject *pyType = nullptr;
+if (typeName)
+ pyType = Shiboken::Conversions::getPythonTypeObject(typeName);
+%out = pyType ? (reinterpret_cast<PyObject*>(pyType)) : Py_None;
+Py_INCREF(%out);
+return %out;
+// @snippet return-qvariant-type
+
+// @snippet return-qjsonobject
+// The QVariantMap returned by QJsonObject seems to cause a segfault, so
+// using QJsonObject.toVariantMap() won't work.
+// Wrapping it in a QJsonValue first allows it to work
+QJsonValue val(%in);
+QVariant ret = val.toVariant();
+
+return %CONVERTTOPYTHON[QVariant](ret);
+// @snippet return-qjsonobject
+
+// @snippet return-qpair
+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;
+// @snippet return-qpair
diff --git a/sources/pyside2/PySide2/glue/qtgui.cpp b/sources/pyside2/PySide2/glue/qtgui.cpp
index b308d7ff..759d0a85 100644
--- a/sources/pyside2/PySide2/glue/qtgui.cpp
+++ b/sources/pyside2/PySide2/glue/qtgui.cpp
@@ -37,6 +37,10 @@
**
****************************************************************************/
+/*********************************************************************
+ * INJECT CODE
+ ********************************************************************/
+
// @snippet qtransform-quadtoquad
QTransform _result;
if (QTransform::quadToQuad(%1, %2, _result)) {
@@ -492,8 +496,18 @@ if (!PyTuple_SetItem(empty, 0, PyList_New(0))) {
}
// @snippet qguiapplication-2
-// @snippet qtransform-quadtoquad
-// @snippet qtransform-quadtoquad
+/*********************************************************************
+ * CONVERSIONS
+ ********************************************************************/
-// @snippet qtransform-quadtosquare
-// @snippet qtransform-quadtosquare
+// @snippet conversion-pylong
+%out = reinterpret_cast<%OUTTYPE>(PyLong_AsVoidPtr(%in));
+// @snippet conversion-pylong
+
+/*********************************************************************
+ * NATIVE TO TARGET CONVERSIONS
+ ********************************************************************/
+
+// @snippet return-pylong-voidptr
+return PyLong_FromVoidPtr(reinterpret_cast<void *>(%in));
+// @snippet return-pylong-voidptr
diff --git a/sources/pyside2/PySide2/glue/qtwidgets.cpp b/sources/pyside2/PySide2/glue/qtwidgets.cpp
index 2a8a8af0..7ec0ca26 100644
--- a/sources/pyside2/PySide2/glue/qtwidgets.cpp
+++ b/sources/pyside2/PySide2/glue/qtwidgets.cpp
@@ -37,6 +37,10 @@
**
****************************************************************************/
+/*********************************************************************
+ * INJECT CODE
+ ********************************************************************/
+
// @snippet qtreewidgetitemiterator-next
if (**%CPPSELF) {
QTreeWidgetItemIterator *%0 = new QTreeWidgetItemIterator((*%CPPSELF)++);
@@ -391,3 +395,11 @@ if (_old)
%CPPSELF.%FUNCTION_NAME(%1);
Shiboken::Object::setParent(%PYSELF, %PYARG_1);
// @snippet qgraphicsproxywidget-setwidget
+
+/*********************************************************************
+ * CONVERSIONS
+ ********************************************************************/
+
+/*********************************************************************
+ * NATIVE TO TARGET CONVERSIONS
+ ********************************************************************/