summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetaobject.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-11-30 14:53:38 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-11-30 17:16:22 +0100
commit5082b84b386a94cbbe6814c383bb6bac795ed648 (patch)
tree900dea29dd41880c9057b34b5371dd984e2fde2b /src/corelib/kernel/qmetaobject.cpp
parent405244fe301ac18d20aae245ba2faafaec74e453 (diff)
QMetaObjectPrivate: Add firstMethod
QMetaObject::indexfOfMethod returns the method corresponding to a specific signature. In QML, we however only want any of the methods with a given name (and do overload resolution at a later point). For this usecase this patch introduces the internal QMetaObject::firstMethod function. Change-Id: Ie3820354edffb273c4cbe1399201a955ebe79344 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
-rw-r--r--src/corelib/kernel/qmetaobject.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index fe6b4075ef..bdd2af1a2e 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -590,6 +590,24 @@ bool QMetaObjectPrivate::methodMatch(const QMetaObject *m, const QMetaMethod &me
return true;
}
+/*!
+ \internal
+ Returns the first method with name \a name found in \a baseObject
+ */
+QMetaMethod QMetaObjectPrivate::firstMethod(const QMetaObject *baseObject, QByteArrayView name)
+{
+ for (const QMetaObject *currentObject = baseObject; currentObject; currentObject = currentObject->superClass()) {
+ const int start = priv(currentObject->d.data)->methodCount - 1;
+ const int end = 0;
+ for (int i = start; i >= end; --i) {
+ auto candidate = QMetaMethod::fromRelativeMethodIndex(currentObject, i);
+ if (name == candidate.name())
+ return candidate;
+ }
+ }
+ return QMetaMethod{};
+}
+
/**
* \internal
* helper function for indexOf{Method,Slot,Signal}, returns the relative index of the method within