@@ -270,17 +270,14 @@ QList<QObject*> PythonQtStdDecorators::findChildren(QObject* parent, PyObject* t
270270 return list;
271271}
272272
273- QObject* PythonQtStdDecorators::findChild (QObject* parent, const char * typeName, const QMetaObject* meta,
273+ QObject* PythonQtStdDecorators::findChild (const QObject* parent, const char * typeName, const QMetaObject* meta,
274274 const QString& name)
275275{
276276 const QObjectList& children = parent->children ();
277277
278- int i;
279- for (i = 0 ; i < children.size (); ++i) {
280- QObject* obj = children.at (i);
281-
278+ for (QObject* obj : children) {
282279 if (!obj)
283- return nullptr ;
280+ continue ;
284281
285282 // Skip if the name doesn't match.
286283 if (!name.isNull () && obj->objectName () != name)
@@ -290,69 +287,55 @@ QObject* PythonQtStdDecorators::findChild(QObject* parent, const char* typeName,
290287 return obj;
291288 }
292289
293- for (i = 0 ; i < children.size (); ++i) {
294- QObject* obj = findChild (children.at (i), typeName, meta, name);
290+ for (QObject* child : children) {
291+ if (child) {
292+ QObject* obj = findChild (child, typeName, meta, name);
295293
296- if (obj != nullptr )
297- return obj;
294+ if (obj != nullptr )
295+ return obj;
296+ }
298297 }
299298
300299 return nullptr ;
301300}
302301
303- int PythonQtStdDecorators::findChildren (QObject* parent, const char * typeName, const QMetaObject* meta,
302+ void PythonQtStdDecorators::findChildren (const QObject* parent, const char * typeName, const QMetaObject* meta,
304303 const QString& name, QList<QObject*>& list)
305304{
306305 const QObjectList& children = parent->children ();
307- int i;
308-
309- for (i = 0 ; i < children.size (); ++i) {
310- QObject* obj = children.at (i);
311306
307+ for (QObject* obj : children) {
312308 if (!obj)
313- return -1 ;
314-
315- // Skip if the name doesn't match.
316- if (!name.isNull () && obj->objectName () != name)
317309 continue ;
318310
319- if ((typeName && obj->inherits (typeName)) || (meta && meta->cast (obj))) {
320- list += obj;
311+ if (name.isNull () || obj->objectName () == name) {
312+ if ((typeName && obj->inherits (typeName)) || (meta && meta->cast (obj))) {
313+ list += obj;
314+ }
321315 }
322316
323- if (findChildren (obj, typeName, meta, name, list) < 0 )
324- return -1 ;
317+ findChildren (obj, typeName, meta, name, list);
325318 }
326-
327- return 0 ;
328319}
329320
330- int PythonQtStdDecorators::findChildren (QObject* parent, const char * typeName, const QMetaObject* meta,
321+ void PythonQtStdDecorators::findChildren (const QObject* parent, const char * typeName, const QMetaObject* meta,
331322 const QRegularExpression& regExp, QList<QObject*>& list)
332323{
333324 const QObjectList& children = parent->children ();
334- int i;
335-
336- for (i = 0 ; i < children.size (); ++i) {
337- QObject* obj = children.at (i);
338325
326+ for (QObject* obj : children) {
339327 if (!obj)
340- return -1 ;
341-
342- // Skip if the name doesn't match.
343- QRegularExpressionMatch match = regExp.match (obj->objectName ());
344- if (match.hasMatch () == false )
345328 continue ;
346329
347- if ((typeName && obj->inherits (typeName)) || (meta && meta->cast (obj))) {
348- list += obj;
330+ QRegularExpressionMatch match = regExp.match (obj->objectName ());
331+ if (match.hasMatch ()) {
332+ if ((typeName && obj->inherits (typeName)) || (meta && meta->cast (obj))) {
333+ list += obj;
334+ }
349335 }
350336
351- if (findChildren (obj, typeName, meta, regExp, list) < 0 )
352- return -1 ;
337+ findChildren (obj, typeName, meta, regExp, list);
353338 }
354-
355- return 0 ;
356339}
357340
358341const QMetaObject* PythonQtStdDecorators::metaObject (QObject* obj)
0 commit comments