MCPcopy Create free account
hub / github.com/KDAB/GammaRay / metaEnum

Method metaEnum

core/enumutil.cpp:55–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55QMetaEnum EnumUtil::metaEnum(const QVariant &value, const char *typeName, const QMetaObject *metaObject)
56{
57 QByteArray fullTypeName(typeName);
58 if (fullTypeName.isEmpty())
59 fullTypeName = value.typeName();
60
61 // split class name and enum name
62 QByteArray className;
63 QByteArray enumTypeName(fullTypeName);
64 const int pos = enumTypeName.lastIndexOf("::");
65 bool isFlag = false;
66 if (pos >= 0) {
67 className = enumTypeName.left(pos);
68 enumTypeName = enumTypeName.mid(pos + 2);
69
70 // QVariant::typeName is no longer the flag name, but QFlags<Foo>...
71 if (className.startsWith("QFlags<")) {
72 className.remove(0, sizeof("QFlags<") - 1);
73 isFlag = true;
74 }
75
76 if (enumTypeName.endsWith(">")) {
77 enumTypeName.chop(1);
78 }
79 }
80
81 const QMetaObject *mo = &Qt::staticMetaObject;
82 int enumIndex = mo->indexOfEnumerator(enumTypeName);
83 if (enumIndex < 0 && metaObject) {
84 mo = metaObject;
85 enumIndex = mo->indexOfEnumerator(enumTypeName);
86 }
87 if (enumIndex < 0 && (mo = QMetaType::fromName(fullTypeName).metaObject())) {
88 enumIndex = mo->indexOfEnumerator(enumTypeName);
89 }
90 if (enumIndex < 0 && (mo = metaObjectForClass(className))) {
91 enumIndex = mo->indexOfEnumerator(enumTypeName);
92 }
93
94 // attempt to recover namespaces from semi-qualified type names
95 if (enumIndex < 0 && metaObject) {
96 QByteArray n(metaObject->className());
97 const int pos = n.lastIndexOf("::");
98 if (pos > 0) {
99 n = n.left(pos + 2) + fullTypeName;
100 return metaEnum(value, n, nullptr);
101 }
102 }
103
104 if (enumIndex < 0)
105 return {};
106
107 if (isFlag) {
108 return flagsFromEnumIndex(enumIndex, enumTypeName, mo);
109 }
110
111 return mo->enumerator(enumIndex);
112}

Callers

nothing calls this directly

Calls 8

metaObjectForClassFunction · 0.85
flagsFromEnumIndexFunction · 0.85
leftMethod · 0.80
isEmptyMethod · 0.45
typeNameMethod · 0.45
removeMethod · 0.45
metaObjectMethod · 0.45
classNameMethod · 0.45

Tested by

no test coverage detected