diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-04 12:34:17 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-04 12:42:35 +0100 |
commit | 1704567d7ad0d21dd3b588af7aad40cd244c1799 (patch) | |
tree | 932b42988e482f01125dcbf4d470e9a56107689a /sources/pyside2/PySide2/glue | |
parent | 1d77cd18510412242384c5b37a00efd5b6ce8a26 (diff) | |
parent | c98ef56544cd54661b61529829caf6a799a1a94f (diff) |
Merge "Merge remote-tracking branch 'origin/5.14' into 5.15"
Diffstat (limited to 'sources/pyside2/PySide2/glue')
-rw-r--r-- | sources/pyside2/PySide2/glue/qtcore.cpp | 49 | ||||
-rw-r--r-- | sources/pyside2/PySide2/glue/qtgui.cpp | 6 | ||||
-rw-r--r-- | sources/pyside2/PySide2/glue/qtmultimedia.cpp | 7 | ||||
-rw-r--r-- | sources/pyside2/PySide2/glue/qtuitools.cpp | 5 |
4 files changed, 47 insertions, 20 deletions
diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 93f7321aa..47b3dd6db 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -57,24 +57,39 @@ bool py2kStrCheck(PyObject *obj) // @snippet pystring-check // @snippet qsettings-value -QVariant out = %CPPSELF.value(%1, %2); +// If we enter the kwds, means that we have a defaultValue or +// at least a type. +// This avoids that we are passing '0' as defaultValue. +// defaultValue can also be passed as positional argument, +// not only as keyword. +QVariant out; +if (kwds || numArgs > 1) + out = %CPPSELF.value(%1, %2); +else + out = %CPPSELF.value(%1); + PyTypeObject *typeObj = reinterpret_cast<PyTypeObject*>(%PYARG_3); if (typeObj) { if (typeObj == &PyList_Type) { - QByteArrayList valuesList = out.toByteArray().split(','); - const int valuesSize = valuesList.size(); - if (valuesSize > 0) { - PyObject *list = PyList_New(valuesSize); - for (int i = 0; i < valuesSize; i++) { - PyObject *item = PyUnicode_FromString(valuesList[i].data()); - PyList_SET_ITEM(list, i, item); - Py_DECREF(item); - } - %PYARG_0 = list; + QByteArray out_ba = out.toByteArray(); + if (!out_ba.isEmpty()) { + QByteArrayList valuesList = out_ba.split(','); + const int valuesSize = valuesList.size(); + if (valuesSize > 0) { + PyObject *list = PyList_New(valuesSize); + for (int i = 0; i < valuesSize; i++) { + PyObject *item = PyUnicode_FromString(valuesList[i].data()); + PyList_SET_ITEM(list, i, item); + Py_DECREF(item); + } + %PYARG_0 = list; + } else { + %PYARG_0 = %CONVERTTOPYTHON[QVariant](out); + } } else { - %PYARG_0 = %CONVERTTOPYTHON[QVariant](out); + %PYARG_0 = PyList_New(0); } } else if (typeObj == &PyBytes_Type) { QByteArray asByteArray = out.toByteArray(); @@ -94,11 +109,13 @@ if (typeObj) { } else if (typeObj == &PyFloat_Type) { float asFloat = out.toFloat(); %PYARG_0 = PyFloat_FromDouble(asFloat); + } else if (typeObj == &PyBool_Type) { + %PYARG_0 = out.toBool() ? Py_True : Py_False; } // TODO: PyDict_Type and PyTuple_Type } else { - if (out == 0) + if (!out.isValid()) %PYARG_0 = Py_None; else %PYARG_0 = %CONVERTTOPYTHON[QVariant](out); @@ -308,7 +325,7 @@ PyModule_AddStringConstant(module, "__version__", qVersion()); // @snippet qobject-connect static bool isDecorator(PyObject *method, PyObject *self) { - Shiboken::AutoDecRef methodName(PyObject_GetAttrString(method, "__name__")); + Shiboken::AutoDecRef methodName(PyObject_GetAttr(method, Shiboken::PyMagicName::name())); if (!PyObject_HasAttr(self, methodName)) return true; Shiboken::AutoDecRef otherMethod(PyObject_GetAttr(self, methodName)); @@ -811,8 +828,8 @@ _findChildrenHelper(%CPPSELF, %2, reinterpret_cast<PyTypeObject *>(%PYARG_1), %P // @snippet qobject-tr QString result; if (QCoreApplication::instance()) { - PyObject *klass = PyObject_GetAttrString(%PYSELF, "__class__"); - PyObject *cname = PyObject_GetAttrString(klass, "__name__"); + PyObject *klass = PyObject_GetAttr(%PYSELF, Shiboken::PyMagicName::class_()); + PyObject *cname = PyObject_GetAttr(klass, Shiboken::PyMagicName::name()); result = QString(QCoreApplication::instance()->translate(Shiboken::String::toCString(cname), /* %1, %2, QCoreApplication::CodecForTr, %3)); */ %1, %2, %3)); diff --git a/sources/pyside2/PySide2/glue/qtgui.cpp b/sources/pyside2/PySide2/glue/qtgui.cpp index 5be8cc287..d2480e99e 100644 --- a/sources/pyside2/PySide2/glue/qtgui.cpp +++ b/sources/pyside2/PySide2/glue/qtgui.cpp @@ -455,10 +455,12 @@ QPoint p(%CPPSELF.%FUNCTION_NAME(%1)); // @snippet qmatrix-map-point // @snippet qmatrix4x4 -if (PySequence_Size(%PYARG_1) == 16) { +// PYSIDE-795: All PySequences can be made iterable with PySequence_Fast. +Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_1, "Can't turn into sequence")); +if (PySequence_Size(seq) == 16) { float values[16]; for (int i=0; i < 16; ++i) { - PyObject *pv = PySequence_Fast_GET_ITEM(%PYARG_1, i); + PyObject *pv = PySequence_Fast_GET_ITEM(seq.object(), i); values[i] = PyFloat_AsDouble(pv); } diff --git a/sources/pyside2/PySide2/glue/qtmultimedia.cpp b/sources/pyside2/PySide2/glue/qtmultimedia.cpp index 5a3f3a5e7..cbe1367cb 100644 --- a/sources/pyside2/PySide2/glue/qtmultimedia.cpp +++ b/sources/pyside2/PySide2/glue/qtmultimedia.cpp @@ -44,3 +44,10 @@ QObject * upcastedArg = %CONVERTTOCPP[QObject *](%PYARG_1); %CPPSELF.%FUNCTION_NAME(reinterpret_cast< %ARG1_TYPE >(upcastedArg)); %END_ALLOW_THREADS // @snippet upcast + +// @snippet qvideoframe-bits +%BEGIN_ALLOW_THREADS +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(); +%END_ALLOW_THREADS +%PYARG_0 = Shiboken::Buffer::newObject(%0, %CPPSELF.bytesPerLine() * %CPPSELF.height(), Shiboken::Buffer::ReadWrite); +// @snippet qvideoframe-bits diff --git a/sources/pyside2/PySide2/glue/qtuitools.cpp b/sources/pyside2/PySide2/glue/qtuitools.cpp index 552a9009c..00fc8e44a 100644 --- a/sources/pyside2/PySide2/glue/qtuitools.cpp +++ b/sources/pyside2/PySide2/glue/qtuitools.cpp @@ -54,9 +54,10 @@ static void createChildrenNameAttributes(PyObject *root, QObject *object) const QByteArray name = child->objectName().toLocal8Bit(); if (!name.isEmpty() && !name.startsWith("_") && !name.startsWith("qt_")) { - if (!PyObject_HasAttrString(root, name.constData())) { + Shiboken::AutoDecRef attrName(Py_BuildValue("s", name.constData())); + if (!PyObject_HasAttr(root, attrName)) { Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject *](child)); - PyObject_SetAttrString(root, name.constData(), pyChild); + PyObject_SetAttr(root, attrName, pyChild); } createChildrenNameAttributes(root, child); } |