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/testtypes.h | |
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/testtypes.h')
-rw-r--r-- | tests/auto/qml/qqmllanguage/testtypes.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h index 3219701f9d..d890668655 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.h +++ b/tests/auto/qml/qqmllanguage/testtypes.h @@ -1384,6 +1384,30 @@ private: QObjectList m_list; }; +class ScopedEnumsWithNameClash +{ + Q_GADGET + Q_ENUMS(ScopedEnum) + Q_ENUMS(OtherScopedEnum) + +public: + enum class ScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3, OtherScopedEnum }; + enum class OtherScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3 }; +}; + +class ScopedEnumsWithResolvedNameClash +{ + Q_GADGET + Q_ENUMS(ScopedEnum) + Q_ENUMS(OtherScopedEnum) + Q_CLASSINFO("RegisterEnumClassesUnscoped", "false") + +public: + enum class ScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3, OtherScopedEnum }; + enum class OtherScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3 }; +}; + + void registerTypes(); #endif // TESTTYPES_H |