summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-05-03 01:20:55 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-05-15 17:34:01 +0200
commitc4947c1c4c0d518197329cf019b04cff4e676541 (patch)
treeed72cc1df4689fc2242f4b320513cafbdb1830b3 /src/corelib/global
parent78e6b54cdea325cd925603cbfa9e76c00db3db92 (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')
-rw-r--r--src/corelib/global/qflags.h5
-rw-r--r--src/corelib/global/qglobal.cpp38
2 files changed, 42 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));
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index d4a7750f98..bc2ae0ac22 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -510,6 +510,44 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
no bits set to 1 (that is, its value as a integer is 0), then this
function will return \c true if and only if this flags object also
has no bits set to 1.
+
+ \sa testAnyFlag()
+*/
+
+/*!
+ \fn template <typename Enum> bool QFlags<Enum>::testFlags(QFlags flags) const noexcept
+ \since 6.2
+
+ Returns \c true if this flags object matches the given \a flags.
+
+ If \a flags has any flags set, this flags object matches precisely
+ if all flags set in \a flags are also set in this flags object.
+ Otherwise, when \a flags has no flags set, this flags object only
+ matches if it also has no flags set.
+
+ \sa testAnyFlags()
+*/
+
+/*!
+ \fn template <typename Enum> bool QFlags<Enum>::testAnyFlag(Enum flag) const noexcept
+ \since 6.2
+
+ Returns \c true if \b any flag set in \a flag is also set in this
+ flags object, otherwise \c false. If \a flag has no flags set, the
+ return will always be \c false.
+
+ \sa testFlag()
+*/
+
+/*!
+ \fn template <typename Enum> bool QFlags<Enum>::testAnyFlags(QFlags flags) const noexcept
+ \since 6.2
+
+ Returns \c true if \b any flag set in \a flags is also set in this
+ flags object, otherwise \c false. If \a flags has no flags set, the
+ return will always be \c false.
+
+ \sa testFlags()
*/
/*!