mirror of https://github.com/KLayout/klayout.git
Merge pull request #1369 from KLayout/issue-1357
Implemented fix for issue #1357 (RBA/pya binding for QObject#findChil…
This commit is contained in:
commit
fe0a3dd20e
|
|
@ -62,15 +62,56 @@ DECL
|
||||||
end
|
end
|
||||||
|
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
# Provides the definitions for QObject::findChild
|
# Provides the definitions for QObject::findChild and QObject::findChildren
|
||||||
|
|
||||||
def add_native_impl_QObject_findChild()
|
def add_native_impl_QObject_findChild()
|
||||||
|
|
||||||
# alternative implementation for QObject::findChild using QObject for T
|
# alternative implementation for QObject::findChild using QObject for T
|
||||||
add_native_impl("QObject", <<'CODE', <<'DECL')
|
add_native_impl("QObject", <<'CODE', <<'DECL')
|
||||||
QObject *find_child_impl (QObject *object, const QString &name) { return object->findChild<QObject *> (name); }
|
|
||||||
|
#if QT_VERSION < 0x50000
|
||||||
|
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
|
QObject *find_child_impl (QObject *object, const QString &name)
|
||||||
|
{
|
||||||
|
return object->findChild<QObject *> (name);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl (QObject *object, const QString &name)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (name);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl2 (QObject *object, const QRegExp &re)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (re);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
QObject *find_child_impl (QObject *object, const QString &name, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChild<QObject *> (name, options);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl (QObject *object, const QString &name, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (name, options);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl2 (QObject *object, const QRegularExpression &re, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (re, options);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
CODE
|
CODE
|
||||||
gsi::method_ext("findChild", &find_child_impl, "@brief Specialisation for findChild (uses QObject as T).")
|
#if QT_VERSION < 0x50000
|
||||||
|
gsi::method_ext("findChild", &find_child_impl, gsi::arg("name", QString(), "null"), "@brief Specialisation for findChild (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl, gsi::arg("name", QString(), "null"), "@brief Specialisation for findChildren (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl2, gsi::arg("re"), "@brief Specialisation for findChildren (uses QObject as T).")
|
||||||
|
#else
|
||||||
|
gsi::method_ext("findChild", &find_child_impl, gsi::arg("name", QString(), "null"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChild (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl, gsi::arg("name", QString(), "null"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChildren (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl2, gsi::arg("re"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChildren (uses QObject as T).")
|
||||||
|
#endif
|
||||||
DECL
|
DECL
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,40 @@ static void _call_smo (const qt_gsi::GenericStaticMethod *, gsi::SerialArgs &, g
|
||||||
ret.write<const QMetaObject &> (QObject::staticMetaObject);
|
ret.write<const QMetaObject &> (QObject::staticMetaObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *find_child_impl (QObject *object, const QString &name) { return object->findChild<QObject *> (name); }
|
|
||||||
|
#if QT_VERSION < 0x50000
|
||||||
|
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
|
QObject *find_child_impl (QObject *object, const QString &name)
|
||||||
|
{
|
||||||
|
return object->findChild<QObject *> (name);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl (QObject *object, const QString &name)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (name);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl2 (QObject *object, const QRegExp &re)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (re);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
QObject *find_child_impl (QObject *object, const QString &name, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChild<QObject *> (name, options);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl (QObject *object, const QString &name, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (name, options);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl2 (QObject *object, const QRegularExpression &re, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (re, options);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// bool QObject::blockSignals(bool b)
|
// bool QObject::blockSignals(bool b)
|
||||||
|
|
||||||
|
|
@ -757,7 +790,15 @@ static gsi::Methods methods_QObject () {
|
||||||
}
|
}
|
||||||
|
|
||||||
qt_gsi::QtNativeClass<QObject> decl_QObject ("QtCore", "QObject_Native",
|
qt_gsi::QtNativeClass<QObject> decl_QObject ("QtCore", "QObject_Native",
|
||||||
gsi::method_ext("findChild", &find_child_impl, "@brief Specialisation for findChild (uses QObject as T).")
|
#if QT_VERSION < 0x50000
|
||||||
|
gsi::method_ext("findChild", &find_child_impl, gsi::arg("name", QString(), "null"), "@brief Specialisation for findChild (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl, gsi::arg("name", QString(), "null"), "@brief Specialisation for findChildren (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl2, gsi::arg("re"), "@brief Specialisation for findChildren (uses QObject as T).")
|
||||||
|
#else
|
||||||
|
gsi::method_ext("findChild", &find_child_impl, gsi::arg("name", QString(), "null"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChild (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl, gsi::arg("name", QString(), "null"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChildren (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl2, gsi::arg("re"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChildren (uses QObject as T).")
|
||||||
|
#endif
|
||||||
+
|
+
|
||||||
methods_QObject (),
|
methods_QObject (),
|
||||||
"@hide\n@alias QObject");
|
"@hide\n@alias QObject");
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,40 @@ static void _call_smo (const qt_gsi::GenericStaticMethod *, gsi::SerialArgs &, g
|
||||||
ret.write<const QMetaObject &> (QObject::staticMetaObject);
|
ret.write<const QMetaObject &> (QObject::staticMetaObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *find_child_impl (QObject *object, const QString &name) { return object->findChild<QObject *> (name); }
|
|
||||||
|
#if QT_VERSION < 0x50000
|
||||||
|
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
|
QObject *find_child_impl (QObject *object, const QString &name)
|
||||||
|
{
|
||||||
|
return object->findChild<QObject *> (name);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl (QObject *object, const QString &name)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (name);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl2 (QObject *object, const QRegExp &re)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (re);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
QObject *find_child_impl (QObject *object, const QString &name, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChild<QObject *> (name, options);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl (QObject *object, const QString &name, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (name, options);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl2 (QObject *object, const QRegularExpression &re, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (re, options);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// bool QObject::blockSignals(bool b)
|
// bool QObject::blockSignals(bool b)
|
||||||
|
|
||||||
|
|
@ -813,7 +846,15 @@ static gsi::Methods methods_QObject () {
|
||||||
}
|
}
|
||||||
|
|
||||||
qt_gsi::QtNativeClass<QObject> decl_QObject ("QtCore", "QObject_Native",
|
qt_gsi::QtNativeClass<QObject> decl_QObject ("QtCore", "QObject_Native",
|
||||||
gsi::method_ext("findChild", &find_child_impl, "@brief Specialisation for findChild (uses QObject as T).")
|
#if QT_VERSION < 0x50000
|
||||||
|
gsi::method_ext("findChild", &find_child_impl, gsi::arg("name", QString(), "null"), "@brief Specialisation for findChild (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl, gsi::arg("name", QString(), "null"), "@brief Specialisation for findChildren (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl2, gsi::arg("re"), "@brief Specialisation for findChildren (uses QObject as T).")
|
||||||
|
#else
|
||||||
|
gsi::method_ext("findChild", &find_child_impl, gsi::arg("name", QString(), "null"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChild (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl, gsi::arg("name", QString(), "null"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChildren (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl2, gsi::arg("re"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChildren (uses QObject as T).")
|
||||||
|
#endif
|
||||||
+
|
+
|
||||||
methods_QObject (),
|
methods_QObject (),
|
||||||
"@hide\n@alias QObject");
|
"@hide\n@alias QObject");
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,40 @@ static void _call_smo (const qt_gsi::GenericStaticMethod *, gsi::SerialArgs &, g
|
||||||
ret.write<const QMetaObject &> (QObject::staticMetaObject);
|
ret.write<const QMetaObject &> (QObject::staticMetaObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *find_child_impl (QObject *object, const QString &name) { return object->findChild<QObject *> (name); }
|
|
||||||
|
#if QT_VERSION < 0x50000
|
||||||
|
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
|
QObject *find_child_impl (QObject *object, const QString &name)
|
||||||
|
{
|
||||||
|
return object->findChild<QObject *> (name);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl (QObject *object, const QString &name)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (name);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl2 (QObject *object, const QRegExp &re)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (re);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
QObject *find_child_impl (QObject *object, const QString &name, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChild<QObject *> (name, options);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl (QObject *object, const QString &name, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (name, options);
|
||||||
|
}
|
||||||
|
QList<QObject *> find_children_impl2 (QObject *object, const QRegularExpression &re, Qt::FindChildOptions options)
|
||||||
|
{
|
||||||
|
return object->findChildren<QObject *> (re, options);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// bool QObject::blockSignals(bool b)
|
// bool QObject::blockSignals(bool b)
|
||||||
|
|
||||||
|
|
@ -771,7 +804,15 @@ static gsi::Methods methods_QObject () {
|
||||||
}
|
}
|
||||||
|
|
||||||
qt_gsi::QtNativeClass<QObject> decl_QObject ("QtCore", "QObject_Native",
|
qt_gsi::QtNativeClass<QObject> decl_QObject ("QtCore", "QObject_Native",
|
||||||
gsi::method_ext("findChild", &find_child_impl, "@brief Specialisation for findChild (uses QObject as T).")
|
#if QT_VERSION < 0x50000
|
||||||
|
gsi::method_ext("findChild", &find_child_impl, gsi::arg("name", QString(), "null"), "@brief Specialisation for findChild (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl, gsi::arg("name", QString(), "null"), "@brief Specialisation for findChildren (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl2, gsi::arg("re"), "@brief Specialisation for findChildren (uses QObject as T).")
|
||||||
|
#else
|
||||||
|
gsi::method_ext("findChild", &find_child_impl, gsi::arg("name", QString(), "null"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChild (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl, gsi::arg("name", QString(), "null"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChildren (uses QObject as T).") +
|
||||||
|
gsi::method_ext("findChildren", &find_children_impl2, gsi::arg("re"), gsi::arg("options", Qt::FindChildrenRecursively, "Qt::FindChildrenRecursively"), "@brief Specialisation for findChildren (uses QObject as T).")
|
||||||
|
#endif
|
||||||
+
|
+
|
||||||
methods_QObject (),
|
methods_QObject (),
|
||||||
"@hide\n@alias QObject");
|
"@hide\n@alias QObject");
|
||||||
|
|
|
||||||
|
|
@ -767,6 +767,35 @@ class QtBinding_TestClass < TestBase
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_60
|
||||||
|
|
||||||
|
# findChild, findChildren
|
||||||
|
|
||||||
|
w = RBA::QWidget::new
|
||||||
|
w.objectName = "w"
|
||||||
|
w1 = RBA::QWidget::new(w)
|
||||||
|
w1.objectName = "w1"
|
||||||
|
w2 = RBA::QWidget::new(w1)
|
||||||
|
w2.objectName = "w2"
|
||||||
|
|
||||||
|
assert_equal(w.findChild.objectName, "w1")
|
||||||
|
assert_equal(w.findChild("w2").objectName, "w2")
|
||||||
|
|
||||||
|
assert_equal(w.findChildren().collect { |c| c.objectName }.join(","), "w1,w2")
|
||||||
|
assert_equal(w.findChildren("w2").collect { |c| c.objectName }.join(","), "w2")
|
||||||
|
|
||||||
|
begin
|
||||||
|
# Qt5++
|
||||||
|
re_cls = RBA::QRegularExpression
|
||||||
|
rescue => ex
|
||||||
|
# Qt4
|
||||||
|
re_cls = RBA::QRegExp
|
||||||
|
end
|
||||||
|
assert_equal(w.findChildren(re_cls::new("^.2$")).collect { |c| c.objectName }.join(","), "w2")
|
||||||
|
assert_equal(w.findChildren(re_cls::new("^w.$")).collect { |c| c.objectName }.join(","), "w1,w2")
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
load("test_epilogue.rb")
|
load("test_epilogue.rb")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue