Add QMetaEnum::isScoped to be able to destinguish C++11 enum class
Change-Id: I67b1dbd069fa57bd60e50690abb5d876edc0d1d2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
b27065014f
commit
c5a4b093d0
@ -2557,9 +2557,19 @@ int QMetaEnum::value(int index) const
|
||||
*/
|
||||
bool QMetaEnum::isFlag() const
|
||||
{
|
||||
return mobj && mobj->d.data[handle + 1];
|
||||
return mobj && mobj->d.data[handle + 1] & EnumIsFlag;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.8
|
||||
|
||||
Returns \c true if this enumerator is declared as a C++11 enum class;
|
||||
otherwise returns false.
|
||||
*/
|
||||
bool QMetaEnum::isScoped() const
|
||||
{
|
||||
return mobj && mobj->d.data[handle + 1] & EnumIsScoped;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the scope this enumerator was declared in.
|
||||
|
@ -210,6 +210,7 @@ public:
|
||||
|
||||
const char *name() const;
|
||||
bool isFlag() const;
|
||||
bool isScoped() const;
|
||||
|
||||
int keyCount() const;
|
||||
const char *key(int index) const;
|
||||
|
@ -114,6 +114,11 @@ enum MetaDataFlags {
|
||||
TypeNameIndexMask = 0x7FFFFFFF
|
||||
};
|
||||
|
||||
enum EnumFlags {
|
||||
EnumIsFlag = 0x1,
|
||||
EnumIsScoped = 0x2
|
||||
};
|
||||
|
||||
extern int qMetaTypeTypeInternal(const char *);
|
||||
|
||||
class QArgumentType
|
||||
|
@ -878,9 +878,14 @@ void Generator::generateEnums(int index)
|
||||
int i;
|
||||
for (i = 0; i < cdef->enumList.count(); ++i) {
|
||||
const EnumDef &e = cdef->enumList.at(i);
|
||||
int flags = 0;
|
||||
if (cdef->enumDeclarations.value(e.name))
|
||||
flags |= EnumIsFlag;
|
||||
if (e.isEnumClass)
|
||||
flags |= EnumIsScoped;
|
||||
fprintf(out, " %4d, 0x%.1x, %4d, %4d,\n",
|
||||
stridx(e.name),
|
||||
cdef->enumDeclarations.value(e.name) ? 1 : 0,
|
||||
flags,
|
||||
e.values.count(),
|
||||
index);
|
||||
index += e.values.count() * 2;
|
||||
|
@ -2094,18 +2094,19 @@ void tst_Moc::cxx11Enums_data()
|
||||
QTest::addColumn<const QMetaObject *>("meta");
|
||||
QTest::addColumn<QByteArray>("enumName");
|
||||
QTest::addColumn<char>("prefix");
|
||||
QTest::addColumn<bool>("isScoped");
|
||||
|
||||
const QMetaObject *meta1 = &CXX11Enums::staticMetaObject;
|
||||
const QMetaObject *meta2 = &CXX11Enums2::staticMetaObject;
|
||||
|
||||
QTest::newRow("EnumClass") << meta1 << QByteArray("EnumClass") << 'A';
|
||||
QTest::newRow("EnumClass 2") << meta2 << QByteArray("EnumClass") << 'A';
|
||||
QTest::newRow("TypedEnum") << meta1 << QByteArray("TypedEnum") << 'B';
|
||||
QTest::newRow("TypedEnum 2") << meta2 << QByteArray("TypedEnum") << 'B';
|
||||
QTest::newRow("TypedEnumClass") << meta1 << QByteArray("TypedEnumClass") << 'C';
|
||||
QTest::newRow("TypedEnumClass 2") << meta2 << QByteArray("TypedEnumClass") << 'C';
|
||||
QTest::newRow("NormalEnum") << meta1 << QByteArray("NormalEnum") << 'D';
|
||||
QTest::newRow("NormalEnum 2") << meta2 << QByteArray("NormalEnum") << 'D';
|
||||
QTest::newRow("EnumClass") << meta1 << QByteArray("EnumClass") << 'A' << true;
|
||||
QTest::newRow("EnumClass 2") << meta2 << QByteArray("EnumClass") << 'A' << true;
|
||||
QTest::newRow("TypedEnum") << meta1 << QByteArray("TypedEnum") << 'B' << false;
|
||||
QTest::newRow("TypedEnum 2") << meta2 << QByteArray("TypedEnum") << 'B' << false;
|
||||
QTest::newRow("TypedEnumClass") << meta1 << QByteArray("TypedEnumClass") << 'C' << true;
|
||||
QTest::newRow("TypedEnumClass 2") << meta2 << QByteArray("TypedEnumClass") << 'C' << true;
|
||||
QTest::newRow("NormalEnum") << meta1 << QByteArray("NormalEnum") << 'D' << false;
|
||||
QTest::newRow("NormalEnum 2") << meta2 << QByteArray("NormalEnum") << 'D' << false;
|
||||
}
|
||||
|
||||
void tst_Moc::cxx11Enums()
|
||||
@ -2115,6 +2116,7 @@ void tst_Moc::cxx11Enums()
|
||||
|
||||
QFETCH(QByteArray, enumName);
|
||||
QFETCH(char, prefix);
|
||||
QFETCH(bool, isScoped);
|
||||
|
||||
int idx;
|
||||
idx = meta->indexOfEnumerator(enumName);
|
||||
@ -2128,6 +2130,7 @@ void tst_Moc::cxx11Enums()
|
||||
QCOMPARE(meta->enumerator(idx).keyToValue(v), i);
|
||||
QCOMPARE(meta->enumerator(idx).valueToKey(i), v.constData());
|
||||
}
|
||||
QCOMPARE(meta->enumerator(idx).isScoped(), isScoped);
|
||||
}
|
||||
|
||||
void tst_Moc::returnRefs()
|
||||
|
Loading…
Reference in New Issue
Block a user