aboutsummaryrefslogtreecommitdiffstats
path: root/PySide
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-03-22 18:08:17 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:54:05 -0300
commite360a53087975cac53975f00e747991b7eb818af (patch)
treeac1ca11d0d9e81623d98315b861b33e3365932ba /PySide
parentc1f507f87ad03651e899ad54199fe028b426515d (diff)
Fix bug 685 - "The second arg. of QObject.findChildren doesn't have a default value and doesn't support regexes."
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'PySide')
-rw-r--r--PySide/QtCore/glue/qobject_findchild.cpp21
-rw-r--r--PySide/QtCore/typesystem_core.xml12
2 files changed, 27 insertions, 6 deletions
diff --git a/PySide/QtCore/glue/qobject_findchild.cpp b/PySide/QtCore/glue/qobject_findchild.cpp
index 351aa69ab..669beac45 100644
--- a/PySide/QtCore/glue/qobject_findchild.cpp
+++ b/PySide/QtCore/glue/qobject_findchild.cpp
@@ -17,14 +17,23 @@ static QObject* _findChildHelper(const QObject* parent, const QString& name, PyT
return 0;
}
-static void _findChildrenHelper(const QObject* parent, const QString& name, PyTypeObject* desiredType, PyObject* result)
+static inline bool _findChildrenComparator(const QObject*& child, const QRegExp& name)
{
- foreach(QObject* child, parent->children()) {
+ return name.indexIn(child->objectName()) != -1;
+}
+
+static inline bool _findChildrenComparator(const QObject*& child, const QString& name)
+{
+ return name.isNull() || name == child->objectName();
+}
+
+template<typename T>
+static void _findChildrenHelper(const QObject* parent, const T& name, PyTypeObject* desiredType, PyObject* result)
+{
+ foreach(const QObject* child, parent->children()) {
Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject*](child));
- if (PyType_IsSubtype(pyChild->ob_type, desiredType)
- && (name.isNull() || name == child->objectName())) {
+ if (PyType_IsSubtype(pyChild->ob_type, desiredType) && _findChildrenComparator(child, name))
PyList_Append(result, pyChild);
- }
_findChildrenHelper(child, name, desiredType, result);
}
-} \ No newline at end of file
+}
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index b261a2ad1..7d2655e3b 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -1317,6 +1317,18 @@
<modify-argument index="return">
<parent index="this" action="add"/>
</modify-argument>
+ <modify-argument index="2">
+ <replace-default-expression with="QString()" />
+ </modify-argument>
+ </add-function>
+ <add-function signature="findChildren(PyTypeObject*, const QRegExp&amp;)" return-type="PySequence*" >
+ <inject-code class="target" position="beginning">
+ %PYARG_0 = PyList_New(0);
+ _findChildrenHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1, %PYARG_0);
+ </inject-code>
+ <modify-argument index="return">
+ <parent index="this" action="add"/>
+ </modify-argument>
</add-function>
<add-function signature="tr(const char *, const char *, int)" return-type="QString">