feat: implement findChild* methods
C++ / fmt (pull_request) Canceled after 0s
C++ / build (pull_request) Canceled after 0s
C++ / clang-tidy (pull_request) Canceled after 0s
JS/TS / fmt (pull_request) Canceled after 0s
JS/TS / lint (pull_request) Canceled after 0s
Python / static (pull_request) Canceled after 0s
Python / verify (pull_request) Canceled after 0s
Rust / build (pull_request) Canceled after 0s
Rust / fmt (pull_request) Canceled after 0s
Rust / clippy (pull_request) Canceled after 0s
C++ / fmt (pull_request) Canceled after 0s
C++ / build (pull_request) Canceled after 0s
C++ / clang-tidy (pull_request) Canceled after 0s
JS/TS / fmt (pull_request) Canceled after 0s
JS/TS / lint (pull_request) Canceled after 0s
Python / static (pull_request) Canceled after 0s
Python / verify (pull_request) Canceled after 0s
Rust / build (pull_request) Canceled after 0s
Rust / fmt (pull_request) Canceled after 0s
Rust / clippy (pull_request) Canceled after 0s
This commit is contained in:
@@ -214,6 +214,74 @@ QString ZUtils::enumToString(
|
||||
return QString::fromUtf8(key);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename Predicate>
|
||||
QQuickItem* findChildDfs(QQuickItem* root, Predicate&& match) {
|
||||
const auto children = root->childItems();
|
||||
for (QQuickItem* const child : children) {
|
||||
if (match(child)) {
|
||||
return child;
|
||||
}
|
||||
if (QQuickItem* const found = findChildDfs(child, match)) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename Predicate>
|
||||
void findChildrenDfs(
|
||||
QQuickItem* root, Predicate&& match, QList<QQuickItem*>& out) {
|
||||
const auto children = root->childItems();
|
||||
for (QQuickItem* const child : children) {
|
||||
if (match(child)) {
|
||||
out.append(child);
|
||||
}
|
||||
findChildrenDfs(child, match, out);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
QQuickItem* ZUtils::findChild(QQuickItem* root, const QString& name) {
|
||||
if (!root) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return findChildDfs(root, [&name](const QQuickItem* item) {
|
||||
return item->objectName() == name;
|
||||
});
|
||||
}
|
||||
|
||||
QList<QQuickItem*> ZUtils::findChildren(QQuickItem* root, const QString& name) {
|
||||
QList<QQuickItem*> children;
|
||||
if (root) {
|
||||
findChildrenDfs(
|
||||
root,
|
||||
[&name](const QQuickItem* item) {
|
||||
return item->objectName() == name;
|
||||
},
|
||||
children);
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
QList<QQuickItem*> ZUtils::findChildrenMatching(
|
||||
QQuickItem* root, const QString& pattern) {
|
||||
QList<QQuickItem*> children;
|
||||
if (root) {
|
||||
const QRegularExpression re(pattern);
|
||||
findChildrenDfs(
|
||||
root,
|
||||
[&re](const QQuickItem* item) {
|
||||
return re.match(item->objectName()).hasMatch();
|
||||
},
|
||||
children);
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
#ifndef ZSHELL_VERSION
|
||||
#define ZSHELL_VERSION ""
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user