diff options
4 files changed, 26 insertions, 2 deletions
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index b58619c0d3..4089a7f030 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -203,9 +203,18 @@ ReturnedValue QQmlTypeWrapper::virtualGet(const Managed *m, PropertyKey id, cons const bool includeEnums = w->d()->mode == Heap::QQmlTypeWrapper::IncludeEnums; if (includeEnums && name->startsWithUpper()) { bool ok = false; - const int value = enumForSingleton(v4, name, qobjectSingleton, type, &ok); + int value = enumForSingleton(v4, name, qobjectSingleton, type, &ok); if (ok) return QV4::Value::fromInt32(value).asReturnedValue(); + + value = type.scopedEnumIndex(QQmlEnginePrivate::get(v4->qmlEngine()), name, &ok); + if (ok) { + Scoped<QQmlScopedEnumWrapper> enumWrapper(scope, v4->memoryManager->allocate<QQmlScopedEnumWrapper>()); + enumWrapper->d()->typePrivate = type.priv(); + QQmlType::refHandle(enumWrapper->d()->typePrivate); + enumWrapper->d()->scopeEnumIndex = value; + return enumWrapper.asReturnedValue(); + } } // check for property. diff --git a/tests/auto/qml/qqmllanguage/data/lib/org/qtproject/MixedModule/SingletonType.qml b/tests/auto/qml/qqmllanguage/data/lib/org/qtproject/MixedModule/SingletonType.qml index 2913ceca08..bf5a77576b 100644 --- a/tests/auto/qml/qqmllanguage/data/lib/org/qtproject/MixedModule/SingletonType.qml +++ b/tests/auto/qml/qqmllanguage/data/lib/org/qtproject/MixedModule/SingletonType.qml @@ -3,6 +3,11 @@ pragma Singleton Item { enum EnumInSingleton { - EnumValue = 42 + EnumValue = 42, + AnotherEnumValue + } + + enum AnotherEnumInSingleton { + AnotherEnumValue = 2 } } diff --git a/tests/auto/qml/qqmllanguage/data/usingTypeWithEnum.qml b/tests/auto/qml/qqmllanguage/data/usingTypeWithEnum.qml index 43e54bbf1d..79e8347330 100644 --- a/tests/auto/qml/qqmllanguage/data/usingTypeWithEnum.qml +++ b/tests/auto/qml/qqmllanguage/data/usingTypeWithEnum.qml @@ -7,4 +7,9 @@ QtObject { property int scopedEnumValue: TypeWithEnum.MyEnum.EnumValue3 property int enumValueFromSingleton: { var x = SingletonType.EnumValue; return x; } Component.onCompleted: enumValue2 = TypeWithEnum.EnumValue1 + + property int duplicatedEnumValueFromSingleton: SingletonType.AnotherEnumValue + property int scopedEnumValueFromSingleton1: SingletonType.EnumInSingleton.AnotherEnumValue + property int scopedEnumValueFromSingleton2: SingletonType.AnotherEnumInSingleton.AnotherEnumValue + property int scopedEnumValueFromSingleton3: { var x = SingletonType.AnotherEnumInSingleton.AnotherEnumValue; return x; } } diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 7a8de739f4..89856d6603 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -3860,6 +3860,11 @@ void tst_qqmllanguage::qmlEnums() QCOMPARE(o->property("enumValue2").toInt(), 0); QCOMPARE(o->property("scopedEnumValue").toInt(), 2); QCOMPARE(o->property("enumValueFromSingleton").toInt(), 42); + // while this next test verifies current duplication behavior, I'm not sure it should be codified + QCOMPARE(o->property("duplicatedEnumValueFromSingleton").toInt(), 2); + QCOMPARE(o->property("scopedEnumValueFromSingleton1").toInt(), 43); + QCOMPARE(o->property("scopedEnumValueFromSingleton2").toInt(), 2); + QCOMPARE(o->property("scopedEnumValueFromSingleton3").toInt(), 2); } } |