QFlags: support enum classes in setFlag()
Unary ~ is not defined for enum classes, so we need a cast. Change-Id: I79d495ebcc24ab960da8dae3be08eb307a9de448 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
655cbb00a0
commit
3587a25238
@ -150,7 +150,7 @@ public:
|
||||
Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const Q_DECL_NOTHROW { return (i & Int(f)) == Int(f) && (Int(f) != 0 || i == Int(f) ); }
|
||||
Q_DECL_RELAXED_CONSTEXPR inline QFlags &setFlag(Enum f, bool on = true) Q_DECL_NOTHROW
|
||||
{
|
||||
return on ? (*this |= f) : (*this &= ~f);
|
||||
return on ? (*this |= f) : (*this &= ~Int(f));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -290,6 +290,18 @@ void tst_QFlags::testSetFlags()
|
||||
btn.setFlag(Qt::LeftButton, false);
|
||||
QVERIFY(!btn.testFlag(Qt::LeftButton));
|
||||
QVERIFY(!btn.testFlag(Qt::MidButton));
|
||||
|
||||
MyStrictFlags flags;
|
||||
flags.setFlag(MyStrictEnum::StrictOne);
|
||||
flags.setFlag(MyStrictEnum::StrictTwo, true);
|
||||
QVERIFY(flags.testFlag(MyStrictEnum::StrictOne));
|
||||
QVERIFY(flags.testFlag(MyStrictEnum::StrictTwo));
|
||||
QVERIFY(!flags.testFlag(MyStrictEnum::StrictFour));
|
||||
|
||||
flags.setFlag(MyStrictEnum::StrictTwo, false);
|
||||
QVERIFY(flags.testFlag(MyStrictEnum::StrictOne));
|
||||
QVERIFY(!flags.testFlag(MyStrictEnum::StrictTwo));
|
||||
QVERIFY(!flags.testFlag(MyStrictEnum::StrictFour));
|
||||
}
|
||||
|
||||
// (statically) check QTypeInfo for QFlags instantiations:
|
||||
|
Loading…
Reference in New Issue
Block a user