1 | // Copyright (C) 2019 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qqmlmetaobject_p.h" |
5 | |
6 | #include <private/qqmlengine_p.h> |
7 | #include <private/qqmlpropertycachemethodarguments_p.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | void QQmlMetaObject::resolveGadgetMethodOrPropertyIndex(QMetaObject::Call type, const QMetaObject **metaObject, int *index) |
12 | { |
13 | int offset; |
14 | |
15 | switch (type) { |
16 | case QMetaObject::ReadProperty: |
17 | case QMetaObject::WriteProperty: |
18 | case QMetaObject::ResetProperty: |
19 | offset = (*metaObject)->propertyOffset(); |
20 | while (*index < offset) { |
21 | *metaObject = (*metaObject)->superClass(); |
22 | offset = (*metaObject)->propertyOffset(); |
23 | } |
24 | break; |
25 | case QMetaObject::InvokeMetaMethod: |
26 | offset = (*metaObject)->methodOffset(); |
27 | while (*index < offset) { |
28 | *metaObject = (*metaObject)->superClass(); |
29 | offset = (*metaObject)->methodOffset(); |
30 | } |
31 | break; |
32 | default: |
33 | offset = 0; |
34 | Q_UNIMPLEMENTED(); |
35 | offset = INT_MAX; |
36 | } |
37 | |
38 | *index -= offset; |
39 | } |
40 | |
41 | QMetaType QQmlMetaObject::methodReturnType(const QQmlPropertyData &data, QByteArray *unknownTypeError) const |
42 | { |
43 | Q_ASSERT(_m && data.coreIndex() >= 0); |
44 | |
45 | QMetaType type = data.propType(); |
46 | if (!type.isValid()) { |
47 | // Find the return type name from the method info |
48 | type = _m->method(index: data.coreIndex()).returnMetaType(); |
49 | } |
50 | if (type.flags().testFlag(flag: QMetaType::IsEnumeration)) |
51 | type = type.underlyingType(); |
52 | if (type.isValid()) |
53 | return type; |
54 | else if (unknownTypeError) |
55 | *unknownTypeError = _m->method(index: data.coreIndex()).typeName(); |
56 | return QMetaType(); |
57 | } |
58 | |
59 | bool QQmlMetaObject::methodParameterTypes(int index, ArgTypeStorage *argStorage, |
60 | QByteArray *unknownTypeError) const |
61 | { |
62 | Q_ASSERT(_m && index >= 0); |
63 | |
64 | QMetaMethod m = _m->method(index); |
65 | return methodParameterTypes(method: m, argStorage, unknownTypeError); |
66 | } |
67 | |
68 | bool QQmlMetaObject::constructorParameterTypes(int index, ArgTypeStorage *dummy, |
69 | QByteArray *unknownTypeError) const |
70 | { |
71 | QMetaMethod m = _m->constructor(index); |
72 | return methodParameterTypes(method: m, argStorage: dummy, unknownTypeError); |
73 | } |
74 | |
75 | bool QQmlMetaObject::methodParameterTypes(const QMetaMethod &m, ArgTypeStorage *argStorage, |
76 | QByteArray *unknownTypeError) |
77 | { |
78 | Q_ASSERT(argStorage); |
79 | |
80 | int argc = m.parameterCount(); |
81 | argStorage->resize(sz: argc); |
82 | for (int ii = 0; ii < argc; ++ii) { |
83 | QMetaType type = m.parameterMetaType(index: ii); |
84 | // we treat enumerations as int |
85 | if (type.flags().testFlag(flag: QMetaType::IsEnumeration)) |
86 | type = type.underlyingType(); |
87 | if (!type.isValid()) { |
88 | if (unknownTypeError) |
89 | *unknownTypeError = m.parameterTypeName(index: ii); |
90 | return false; |
91 | } |
92 | argStorage->operator[](idx: ii) = type; |
93 | } |
94 | return true; |
95 | } |
96 | |
97 | QT_END_NAMESPACE |
98 | |