diff options
author | Rainer Keller <Rainer.Keller@qt.io> | 2018-08-20 13:48:37 +0200 |
---|---|---|
committer | Rainer Keller <Rainer.Keller@qt.io> | 2018-08-21 11:43:36 +0000 |
commit | bb296168f426d7e646c0208427f25687f96e2693 (patch) | |
tree | f1683300d7b2aac946de627a87f8e69681a54b99 /tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | |
parent | b858833a262aeef005e4e3533194db7e6c280c4c (diff) |
Provide option to skip registration of enum classes unscoped
Enums classes are registered unscoped which leads to clashes in the following
cases:
1. Two different enums contain the same values
2. The name of an enum class is the same as an enum value
In the 2nd case you can not even access the scoped enum at all because it
will be overwritten by the primitive type.
Users can now add a class info to the meta type to disable the unscoped
registration which solves all clashes. The default is kept as is.
class MyClass : public QObject
{
Q_OBJECT
Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
public:
...
};
[ChangeLog][QtQml] Added option to disable unscoped registration of enum classes.
Change-Id: Ifa4197a14a252575e8a25ae56fb6ee479addf80b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp')
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 97727c1794..157fd500ad 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -34,6 +34,7 @@ #include <QtCore/qdebug.h> #include <QtCore/qfileinfo.h> #include <QtCore/qdir.h> +#include <QtCore/qscopeguard.h> #include <QSignalSpy> #include <QFont> #include <QQmlFileSelector> @@ -218,6 +219,8 @@ private slots: void lowercaseEnumCompileTime_data(); void lowercaseEnumCompileTime(); void scopedEnum(); + void scopedEnumsWithNameClash(); + void scopedEnumsWithResolvedNameClash(); void qmlEnums(); void literals_data(); void literals(); @@ -3793,6 +3796,40 @@ void tst_qqmllanguage::scopedEnum() QCOMPARE(o->property("noScope").toInt(), (int)MyTypeObject::MyScopedEnum::ScopedVal2); } +void tst_qqmllanguage::scopedEnumsWithNameClash() +{ + auto typeId = qmlRegisterUncreatableType<ScopedEnumsWithNameClash>("ScopedEnumsWithNameClashTest", 1, 0, "ScopedEnum", "Dummy reason"); + auto registryGuard = qScopeGuard([typeId]() { + qmlUnregisterType(typeId); + }); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("scopedEnumsWithNameClash.qml")); + + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "Previously registered enum will be overwritten due to name clash: ScopedEnumsWithNameClash.ScopedVal1"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "Previously registered enum will be overwritten due to name clash: ScopedEnumsWithNameClash.ScopedVal2"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "Previously registered enum will be overwritten due to name clash: ScopedEnumsWithNameClash.ScopedVal3"); + + QScopedPointer<QObject> obj(component.create()); + QVERIFY(obj != nullptr); + QVERIFY(obj->property("success").toBool()); +} + +void tst_qqmllanguage::scopedEnumsWithResolvedNameClash() +{ + auto typeId = qmlRegisterUncreatableType<ScopedEnumsWithResolvedNameClash>("ScopedEnumsWithResolvedNameClashTest", 1, 0, "ScopedEnum", "Dummy reason"); + auto registryGuard = qScopeGuard([typeId]() { + qmlUnregisterType(typeId); + }); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("scopedEnumsWithResolvedNameClash.qml")); + + QScopedPointer<QObject> obj(component.create()); + QVERIFY(obj != nullptr); + QVERIFY(obj->property("success").toBool()); +} + void tst_qqmllanguage::qmlEnums() { QQmlEngine engine; |