diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2019-07-18 10:18:43 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2019-07-18 10:21:51 +0200 |
commit | 4646b8660721e5b8d06b06d714b4562e375f8c34 (patch) | |
tree | d12f0c1af2b6cdf486ff389607844a657a1b67c1 /sources/pyside2/PySide2 | |
parent | 97718de50e14f69048993df4e87dda1cadcc599a (diff) | |
parent | 295d9d7fb52505666a6dc9ac7b6fba2323814c48 (diff) |
Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: Ic2c43ef80769e3063dac771518c803861510f72e
Diffstat (limited to 'sources/pyside2/PySide2')
-rw-r--r-- | sources/pyside2/PySide2/QtCore/typesystem_core_common.xml | 11 | ||||
-rw-r--r-- | sources/pyside2/PySide2/glue/qtcore.cpp | 50 | ||||
-rw-r--r-- | sources/pyside2/PySide2/support/generate_pyi.py | 4 |
3 files changed, 60 insertions, 5 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 9f8d07733..9ffc7d376 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -2514,11 +2514,12 @@ <define-ownership class="target" owner="default"/> </modify-argument> </modify-function> - <modify-function signature="value(const QString&,const QVariant&)const"> - <inject-documentation mode="append" format="target"> - .. 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")) - </inject-documentation> - </modify-function> + <!-- PYSIDE-1010: + We remove the original implementation of value() to include the optional parameter --> + <modify-function signature="value(const QString&,const QVariant&)const" remove="all"/> + <add-function signature="value(const QString&, const QVariant& @defaultValue@ = 0, PyObject* @type@ = 0)" return-type="PyObject*"> + <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qsettings-value"/> + </add-function> </object-type> <object-type name="QEvent" polymorphic-id-expression="%1->type() == QEvent::None"> <enum-type name="Type"/> diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 930ad9349..3e1bab97b 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -56,6 +56,56 @@ bool py2kStrCheck(PyObject *obj) } // @snippet pystring-check +// @snippet qsettings-value +QVariant out = %CPPSELF.value(%1, %2); +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; + + } else { + %PYARG_0 = %CONVERTTOPYTHON[QVariant](out); + } + } else if (typeObj == &PyBytes_Type) { + QByteArray asByteArray = out.toByteArray(); + %PYARG_0 = PyBytes_FromString(asByteArray.data()); + } else if (typeObj == &PyUnicode_Type) { + QByteArray asByteArray = out.toByteArray(); + %PYARG_0 = PyUnicode_FromString(asByteArray.data()); +#ifdef IS_PY3K + } else if (typeObj == &PyLong_Type) { + float asFloat = out.toFloat(); + pyResult = PyLong_FromDouble(asFloat); +#else + } else if (typeObj == &PyInt_Type) { + float asFloat = out.toFloat(); + pyResult = PyInt_FromLong(long(asFloat)); +#endif + } else if (typeObj == &PyFloat_Type) { + float asFloat = out.toFloat(); + %PYARG_0 = PyFloat_FromDouble(asFloat); + } + // TODO: PyDict_Type and PyTuple_Type +} +else { + if (out == 0) + %PYARG_0 = Py_None; + else + %PYARG_0 = %CONVERTTOPYTHON[QVariant](out); +} + +// @snippet qsettings-value + // @snippet qvariant-conversion static const char *QVariant_resolveMetaType(PyTypeObject *type, int *typeId) { diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py index 294cdc91b..c732227f4 100644 --- a/sources/pyside2/PySide2/support/generate_pyi.py +++ b/sources/pyside2/PySide2/support/generate_pyi.py @@ -252,6 +252,10 @@ def generate_all_pyi(outpath, options): from PySide2.support.signature import inspect from PySide2.support.signature.lib.enum_sig import HintingEnumerator + # propagate USE_PEP563 to the mapping module. + # Perhaps this can be automated? + PySide2.support.signature.mapping.USE_PEP563 = USE_PEP563 + outpath = outpath or os.path.dirname(PySide2.__file__) name_list = PySide2.__all__ if options.modules == ["all"] else options.modules errors = ", ".join(set(name_list) - set(PySide2.__all__)) |