aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-06-24 11:17:15 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-06-26 17:55:23 +0200
commit6e5dddf736ac00ae3981b0ff89d12528d32d8f98 (patch)
tree07383a05b671bf08e19f33142ca331c445fca927 /sources
parentb2092a477ff0635c7185037f89361bc6b1c35a36 (diff)
Add QObject.findChildren(QRegularExpression)
Replacing the deprecated QRegExp version in Qt 6. Merge identical code snippets. Task-number: PYSIDE-904 Change-Id: Id6f5c39379c65cf71fb6352531173d0fd7f2ae5e Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/PySide2/QtCore/typesystem_core_common.xml10
-rw-r--r--sources/pyside2/PySide2/glue/qtcore.cpp14
-rw-r--r--sources/pyside2/tests/QtCore/qobject_parent_test.py7
3 files changed, 20 insertions, 11 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
index bac210ba7..5d8a1c9c7 100644
--- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
+++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
@@ -1723,7 +1723,7 @@
<inject-documentation format="target" mode="append">
Like the method *findChild*, the first parameter should be the child's type.
</inject-documentation>
- <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-findchildren-1"/>
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-findchildren"/>
<modify-argument index="return">
<parent index="this" action="add"/>
</modify-argument>
@@ -1732,7 +1732,13 @@
</modify-argument>
</add-function>
<add-function signature="findChildren(PyTypeObject*,const QRegExp&amp;)" return-type="PySequence*" >
- <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-findchildren-2"/>
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-findchildren"/>
+ <modify-argument index="return">
+ <parent index="this" action="add"/>
+ </modify-argument>
+ </add-function>
+ <add-function signature="findChildren(PyTypeObject*,const QRegularExpression&amp;)" return-type="PySequence*" >
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-findchildren"/>
<modify-argument index="return">
<parent index="this" action="add"/>
</modify-argument>
diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp
index f818dcffe..d76f2980e 100644
--- a/sources/pyside2/PySide2/glue/qtcore.cpp
+++ b/sources/pyside2/PySide2/glue/qtcore.cpp
@@ -806,6 +806,11 @@ static inline bool _findChildrenComparator(const QObject *&child, const QRegExp
return name.indexIn(child->objectName()) != -1;
}
+static inline bool _findChildrenComparator(const QObject *&child, const QRegularExpression &name)
+{
+ return name.match(child->objectName()).hasMatch();
+}
+
static inline bool _findChildrenComparator(const QObject *&child, const QString &name)
{
return name.isNull() || name == child->objectName();
@@ -828,15 +833,10 @@ QObject *child = _findChildHelper(%CPPSELF, %2, reinterpret_cast<PyTypeObject *>
%PYARG_0 = %CONVERTTOPYTHON[QObject *](child);
// @snippet qobject-findchild-2
-// @snippet qobject-findchildren-1
-%PYARG_0 = PyList_New(0);
-_findChildrenHelper(%CPPSELF, %2, reinterpret_cast<PyTypeObject *>(%PYARG_1), %PYARG_0);
-// @snippet qobject-findchildren-1
-
-// @snippet qobject-findchildren-2
+// @snippet qobject-findchildren
%PYARG_0 = PyList_New(0);
_findChildrenHelper(%CPPSELF, %2, reinterpret_cast<PyTypeObject *>(%PYARG_1), %PYARG_0);
-// @snippet qobject-findchildren-2
+// @snippet qobject-findchildren
// @snippet qobject-tr
QString result;
diff --git a/sources/pyside2/tests/QtCore/qobject_parent_test.py b/sources/pyside2/tests/QtCore/qobject_parent_test.py
index 7e98100a1..0a02fbc26 100644
--- a/sources/pyside2/tests/QtCore/qobject_parent_test.py
+++ b/sources/pyside2/tests/QtCore/qobject_parent_test.py
@@ -144,10 +144,13 @@ class ParentCase(unittest.TestCase):
res = parent.findChildren(QTimer)
self.assertEqual(len(res), 20)
- # test findChildre with a regex
- res = parent.findChildren(QObject, QRegExp("^fo+"))
+ # test findChildren with a QRegularExpression
+ res = parent.findChildren(QObject, QRegularExpression("^fo+"))
self.assertEqual(res, test_children)
+ # test findChildren with a QRegExp (deprecated)
+ res = parent.findChildren(QObject, QRegExp("^fo+"))
+ self.assertEqual(res, test_children)
def testParentEquality(self):
#QObject.parent() == parent