diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-05-03 01:20:55 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-05-15 17:34:01 +0200 |
commit | c4947c1c4c0d518197329cf019b04cff4e676541 (patch) | |
tree | ed72cc1df4689fc2242f4b320513cafbdb1830b3 /src/corelib/global/qflags.h | |
parent | 78e6b54cdea325cd925603cbfa9e76c00db3db92 (diff) |
QFlags: add test(Any)Flag(s)
QFlags was lacking a named function for testing whether a QFlags object
contains _any_ of the bits set by a given enumerator/other QFlags.
Drive-by, add testFlags taking a QFlags, not just an object of the
enumeration; and simplify the implementation of testFlags to more
closely follow what its documentation says it does.
[ChangeLog][QtCore][QFlags] The testFlags, testAnyFlag and
testAnyFlags functions have been added.
Change-Id: Ie8688c8b0dd393d34d32bc7786cdcee3eba24d1c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qflags.h')
-rw-r--r-- | src/corelib/global/qflags.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index c6ecb1ea47..ab46af2d8e 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -145,7 +145,10 @@ public: constexpr inline bool operator!() const noexcept { return !i; } - constexpr inline bool testFlag(Enum flag) const noexcept { return (i & Int(flag)) == Int(flag) && (Int(flag) != 0 || i == Int(0) ); } + constexpr inline bool testFlag(Enum flag) const noexcept { return testFlags(flag); } + constexpr inline bool testFlags(QFlags flags) const noexcept { return flags.i ? ((i & flags.i) == flags.i) : i == Int(0); } + constexpr inline bool testAnyFlag(Enum flag) const noexcept { return testAnyFlags(flag); } + constexpr inline bool testAnyFlags(QFlags flags) const noexcept { return (i & flags.i) != Int(0); } constexpr inline QFlags &setFlag(Enum flag, bool on = true) noexcept { return on ? (*this |= flag) : (*this &= ~QFlags(flag)); |