85int QQmlCustomParser::evaluateEnum(
const QString &script,
bool *ok)
const
87 Q_ASSERT_X(ok,
"QQmlCustomParser::evaluateEnum",
"ok must not be a null pointer");
94 auto nextDot = [&](
int dot) {
95 const int nextDot = script.indexOf(u'.', dot + 1);
96 return (nextDot == script.size() - 1) ? -1 : nextDot;
99 int dot = nextDot(-1);
103 const QString scope = script.left(dot);
105 if (scope != QLatin1String(
"Qt")) {
106 if (imports.isNull())
109 QQmlTypeLoader *loader = typeLoader();
114 if (imports.isT1()) {
115 QQmlImportNamespace *ns =
nullptr;
119 bool recursionDetected =
false;
121 if (!imports.asT1()->resolveType(
122 loader, scope, &type,
nullptr, &ns,
nullptr,
123 QQmlType::AnyRegistrationType, &recursionDetected)) {
127 if (!type.isValid() && ns !=
nullptr) {
129 if (dot == -1 || !imports.asT1()->resolveType(
130 loader, script.left(dot), &type,
nullptr,
nullptr,
nullptr,
131 QQmlType::AnyRegistrationType, &recursionDetected)) {
137 const QQmlTypeNameCache::Result result
138 = imports.asT2()->query<QQmlImport::AllowRecursion>(scope, loader);
139 if (result.type.isValid()) {
141 }
else if (result.importNamespace) {
144 type = imports.asT2()->query<QQmlImport::AllowRecursion>(
145 script.left(dot), loader).type;
153 const int dot2 = nextDot(dot);
154 const bool dot2Valid = (dot2 != -1);
155 const QString enumValue = script.mid(dot2Valid ? dot2 + 1 : dot + 1);
156 const QString scopedEnumName = dot2Valid ? script.mid(dot + 1, dot2 - dot - 1) : QString();
161 const QUrl documentUrl = validator ? validator->documentSourceUrl() : QUrl();
162 if (documentUrl.isValid() && documentUrl == type.sourceUrl()) {
164 const QQmlPropertyCache::ConstPtr rootCache = validator->rootPropertyCache();
165 const int count = rootCache->qmlEnumCount();
166 for (
int ii = 0; ii < count; ++ii) {
167 const QQmlEnumData *enumData = rootCache->qmlEnum(ii);
168 if (!scopedEnumName.isEmpty() && scopedEnumName != enumData->name)
171 for (
int jj = 0; jj < enumData->values.size(); ++jj) {
172 const QQmlEnumValue value = enumData->values.at(jj);
173 if (value.namedValue == enumValue) {
182 if (!scopedEnumName.isEmpty())
183 return type.scopedEnumValue(loader, scopedEnumName, enumValue, ok);
185 return type.enumValue(loader, enumValue, ok);
188 const QString enumValue = script.mid(dot + 1);
189 const QMetaObject *mo = &Qt::staticMetaObject;
190 int i = mo->enumeratorCount();
192 int v = mo->enumerator(i).keyToValue(enumValue.toUtf8().constData(), ok);