summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
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
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')
-rw-r--r--src/corelib/kernel/qmetaobject.cpp18
-rw-r--r--src/corelib/kernel/qmetaobject_p.h1
2 files changed, 19 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
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h
index efc1eafc8f..dbd82ba27b 100644
--- a/src/corelib/kernel/qmetaobject_p.h
+++ b/src/corelib/kernel/qmetaobject_p.h
@@ -253,6 +253,7 @@ struct QMetaObjectPrivate
static bool methodMatch(const QMetaObject *m, const QMetaMethod &method,
const QByteArray &name, int argc,
const QArgumentType *types);
+ Q_CORE_EXPORT static QMetaMethod firstMethod(const QMetaObject *baseObject, QByteArrayView name);
};