86int QQmlCustomParser::evaluateEnum(
const QString &script,
bool *ok)
const
88 Q_ASSERT_X(ok,
"QQmlCustomParser::evaluateEnum",
"ok must not be a null pointer");
95 auto nextDot = [&](
int dot) {
96 const int nextDot = script.indexOf(u'.', dot + 1);
97 return (nextDot == script.size() - 1) ? -1 : nextDot;
100 int dot = nextDot(-1);
104 const QString scope = script.left(dot);
106 if (scope != QLatin1String(
"Qt")) {
107 if (imports.isNull())
110 QQmlTypeLoader *loader = typeLoader();
115 if (imports.isT1()) {
116 QQmlImportNamespace *ns =
nullptr;
120 bool recursionDetected =
false;
122 if (!imports.asT1()->resolveType(
123 loader, scope, &type,
nullptr, &ns,
nullptr,
124 QQmlType::AnyRegistrationType, &recursionDetected)) {
128 if (!type.isValid() && ns !=
nullptr) {
130 if (dot == -1 || !imports.asT1()->resolveType(
131 loader, script.left(dot), &type,
nullptr,
nullptr,
nullptr,
132 QQmlType::AnyRegistrationType, &recursionDetected)) {
138 const QQmlTypeNameCache::Result result
139 = imports.asT2()->query<QQmlImport::AllowRecursion>(scope, loader);
140 if (result.type.isValid()) {
142 }
else if (result.importNamespace) {
145 type = imports.asT2()->query<QQmlImport::AllowRecursion>(
146 script.left(dot), loader).type;
154 const int dot2 = nextDot(dot);
155 const bool dot2Valid = (dot2 != -1);
156 const QString enumValue = script.mid(dot2Valid ? dot2 + 1 : dot + 1);
157 const QString scopedEnumName = dot2Valid ? script.mid(dot + 1, dot2 - dot - 1) : QString();
162 const QUrl documentUrl = validator ? validator->documentSourceUrl() : QUrl();
163 if (documentUrl.isValid() && documentUrl == type.sourceUrl()) {
165 const QQmlPropertyCache::ConstPtr rootCache = validator->rootPropertyCache();
166 const int count = rootCache->qmlEnumCount();
167 for (
int ii = 0; ii < count; ++ii) {
168 const QQmlEnumData *enumData = rootCache->qmlEnum(ii);
169 if (!scopedEnumName.isEmpty() && scopedEnumName != enumData->name)
172 for (
int jj = 0; jj < enumData->values.size(); ++jj) {
173 const QQmlEnumValue value = enumData->values.at(jj);
174 if (value.namedValue == enumValue) {
183 if (!scopedEnumName.isEmpty())
184 return type.scopedEnumValue(loader, scopedEnumName, enumValue, ok);
186 return type.enumValue(loader, enumValue, ok);
189 const QString enumValue = script.mid(dot + 1);
190 const QMetaObject *mo = &Qt::staticMetaObject;
191 int i = mo->enumeratorCount();
193 int v = mo->enumerator(i).keyToValue(enumValue.toUtf8().constData(), ok);