aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-02 10:52:18 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-30 08:21:03 +0000
commit0f922f604297a2022527f04a696da121396ddc0a (patch)
tree5a40599046ff6ab940aff6d639530237ce08c4d8 /sources/pyside2
parent7af97fa4136d66bbad6c7907de6e7bd823de2e43 (diff)
Add QStringView/QByteArrayView
View types as function parameters cannot be converted in the standard way shiboken does it: QStringView cppArg0; pythonToCpp(pyArg, &cppArg0); since they reference some other data. Introduce a new "viewOn" member to type system entry for them. It causes the function arguments to be replaced by their viewed-on types (stringview->string) via metatype. Add a test in libsample and a test for QUuid::fromString(QStringView). Test returning QStringView via QRegularExpressionMatch::capturedView(). Task-number: QTBUG-84319 Task-number: PYSIDE-1339 Task-number: PYSIDE-904 Task-number: PYSIDE-487 Change-Id: Iddb4ea268a54928d290e29012e2738772fae83f0 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2')
-rw-r--r--sources/pyside2/PySide2/QtCore/typesystem_core_common.xml13
-rw-r--r--sources/pyside2/PySide2/glue/qtcore.cpp4
-rw-r--r--sources/pyside2/tests/QtCore/qregularexpression_test.py1
-rw-r--r--sources/pyside2/tests/QtCore/quuid_test.py3
4 files changed, 20 insertions, 1 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
index 2cbfe638b..46e3c6fe6 100644
--- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
+++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
@@ -253,6 +253,13 @@
</conversion-rule>
</primitive-type>
+ <primitive-type name="QStringView" target-lang-api-name="PyUnicode" view-on="QString">
+ <include file-name="QStringView" location="global"/>
+ <conversion-rule>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pyunicode"/>
+ </conversion-rule>
+ </primitive-type>
+
<primitive-type name="QChar">
<conversion-rule>
<native-to-target file="../glue/qtcore.cpp" snippet="return-pyunicode-qchar"/>
@@ -2022,6 +2029,12 @@
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qbytearray-msetitem"/>
</add-function>
</value-type>
+ <primitive-type name="QByteArrayView" view-on="QByteArray" since="6.0">
+ <conversion-rule>
+ <native-to-target file="../glue/qtcore.cpp" snippet="return-pybytes"/>
+ </conversion-rule>
+ </primitive-type>
+
<value-type name="QTextBoundaryFinder">
<enum-type name="BoundaryReason" flags="BoundaryReasons"/>
<enum-type name="BoundaryType"/>
diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp
index 45e0e8c25..eb8d6dff4 100644
--- a/sources/pyside2/PySide2/glue/qtcore.cpp
+++ b/sources/pyside2/PySide2/glue/qtcore.cpp
@@ -1839,6 +1839,10 @@ int usec = PyDateTime_TIME_GET_MICROSECOND(%in);
return PyBool_FromLong((bool)%in);
// @snippet return-pybool
+// @snippet return-pybytes
+return PyBytes_FromStringAndSize(%in.constData(), %in.size());
+// @snippet return-pybytes
+
// @snippet return-pylong
return PyLong_FromLong(%in);
// @snippet return-pylong
diff --git a/sources/pyside2/tests/QtCore/qregularexpression_test.py b/sources/pyside2/tests/QtCore/qregularexpression_test.py
index fb2e9c24c..50c755d0e 100644
--- a/sources/pyside2/tests/QtCore/qregularexpression_test.py
+++ b/sources/pyside2/tests/QtCore/qregularexpression_test.py
@@ -48,6 +48,7 @@ class QRegularExpressionTest(unittest.TestCase):
match = re.match('word1 word2 word3')
self.assertTrue(match.isValid())
self.assertEqual(match.captured(1), 'word2')
+ self.assertEqual(match.capturedView(1), 'word2')
def testMatchIterator(self):
re = QRegularExpression('(\w+)')
diff --git a/sources/pyside2/tests/QtCore/quuid_test.py b/sources/pyside2/tests/QtCore/quuid_test.py
index da34429f9..ecb4a9562 100644
--- a/sources/pyside2/tests/QtCore/quuid_test.py
+++ b/sources/pyside2/tests/QtCore/quuid_test.py
@@ -43,7 +43,8 @@ from PySide2.QtCore import QUuid
class QUuidTest(unittest.TestCase):
def testFromString(self):
uuidString = '{fc69b59e-cc34-4436-a43c-ee95d128b8c5}'
- uuid = QUuid(uuidString)
+# testing overload QUUid::fromString(QStringView)
+ uuid = QUuid.fromString(uuidString)
self.assertTrue(not uuid.isNull())
self.assertEqual(uuid.toString(), uuidString)