diff --git a/src/PythonQtStdDecorators.cpp b/src/PythonQtStdDecorators.cpp index 25ba6b300..2668949c3 100644 --- a/src/PythonQtStdDecorators.cpp +++ b/src/PythonQtStdDecorators.cpp @@ -270,17 +270,14 @@ QList PythonQtStdDecorators::findChildren(QObject* parent, PyObject* t return list; } -QObject* PythonQtStdDecorators::findChild(QObject* parent, const char* typeName, const QMetaObject* meta, +QObject* PythonQtStdDecorators::findChild(const QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name) { const QObjectList& children = parent->children(); - int i; - for (i = 0; i < children.size(); ++i) { - QObject* obj = children.at(i); - + for (QObject* obj : children) { if (!obj) - return nullptr; + continue; // Skip if the name doesn't match. if (!name.isNull() && obj->objectName() != name) @@ -290,69 +287,55 @@ QObject* PythonQtStdDecorators::findChild(QObject* parent, const char* typeName, return obj; } - for (i = 0; i < children.size(); ++i) { - QObject* obj = findChild(children.at(i), typeName, meta, name); + for (QObject* child : children) { + if (child) { + QObject* obj = findChild(child, typeName, meta, name); - if (obj != nullptr) - return obj; + if (obj != nullptr) + return obj; + } } return nullptr; } -int PythonQtStdDecorators::findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, +void PythonQtStdDecorators::findChildren(const QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, QList& list) { const QObjectList& children = parent->children(); - int i; - - for (i = 0; i < children.size(); ++i) { - QObject* obj = children.at(i); + for (QObject* obj : children) { if (!obj) - return -1; - - // Skip if the name doesn't match. - if (!name.isNull() && obj->objectName() != name) continue; - if ((typeName && obj->inherits(typeName)) || (meta && meta->cast(obj))) { - list += obj; + if (name.isNull() || obj->objectName() == name) { + if ((typeName && obj->inherits(typeName)) || (meta && meta->cast(obj))) { + list += obj; + } } - if (findChildren(obj, typeName, meta, name, list) < 0) - return -1; + findChildren(obj, typeName, meta, name, list); } - - return 0; } -int PythonQtStdDecorators::findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, +void PythonQtStdDecorators::findChildren(const QObject* parent, const char* typeName, const QMetaObject* meta, const QRegularExpression& regExp, QList& list) { const QObjectList& children = parent->children(); - int i; - - for (i = 0; i < children.size(); ++i) { - QObject* obj = children.at(i); + for (QObject* obj : children) { if (!obj) - return -1; - - // Skip if the name doesn't match. - QRegularExpressionMatch match = regExp.match(obj->objectName()); - if (match.hasMatch() == false) continue; - if ((typeName && obj->inherits(typeName)) || (meta && meta->cast(obj))) { - list += obj; + QRegularExpressionMatch match = regExp.match(obj->objectName()); + if (match.hasMatch()) { + if ((typeName && obj->inherits(typeName)) || (meta && meta->cast(obj))) { + list += obj; + } } - if (findChildren(obj, typeName, meta, regExp, list) < 0) - return -1; + findChildren(obj, typeName, meta, regExp, list); } - - return 0; } const QMetaObject* PythonQtStdDecorators::metaObject(QObject* obj) diff --git a/src/PythonQtStdDecorators.h b/src/PythonQtStdDecorators.h index aa5771c74..47467e3ce 100644 --- a/src/PythonQtStdDecorators.h +++ b/src/PythonQtStdDecorators.h @@ -151,11 +151,11 @@ public Q_SLOTS: void static_QTimer_singleShot(int msec, PyObject* callable); private: - QObject* findChild(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name); - int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, - QList& list); - int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QRegularExpression& regExp, + QObject* findChild(const QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name); + void findChildren(const QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, QList& list); + void findChildren(const QObject* parent, const char* typeName, const QMetaObject* meta, + const QRegularExpression& regExp, QList& list); }; class PythonQtSingleShotTimer : public QTimer