summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-05-02 01:32:03 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-05-11 13:22:44 +0200
commitd2759e0e32c613b18123970ac15aa1f71949a5e7 (patch)
tree07e5123f8e3f44ca3d74cd7122ab0b9837d6ba79 /src
parent53049d60277e0168a6c9f514674f26f9c25df84b (diff)
QFlags: add operator& / &= overloads taking a QFlags object
It makes no sense to offer the "type-unsafe" operators taking a plain int, and not offer the ones taking a QFlags object. Using these operators has actually always worked by going through a conversion to int, but we're going to limit that possibility in the future. [ChangeLog][QtCore][QFlags] The operator& and operator&= now accept a QFlags object. Change-Id: Iee0845640014d35b646787e8bdb77854f180a9ef Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qflags.h2
-rw-r--r--src/corelib/global/qglobal.cpp14
2 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h
index 8fb6cb09a3..0b7f3f7d6c 100644
--- a/src/corelib/global/qflags.h
+++ b/src/corelib/global/qflags.h
@@ -117,6 +117,7 @@ public:
constexpr inline QFlags &operator&=(int mask) noexcept { i &= mask; return *this; }
constexpr inline QFlags &operator&=(uint mask) noexcept { i &= mask; return *this; }
+ constexpr inline QFlags &operator&=(QFlags mask) noexcept { i &= mask.i; return *this; }
constexpr inline QFlags &operator&=(Enum mask) noexcept { i &= Int(mask); return *this; }
constexpr inline QFlags &operator|=(QFlags other) noexcept { i |= other.i; return *this; }
constexpr inline QFlags &operator|=(Enum other) noexcept { i |= Int(other); return *this; }
@@ -131,6 +132,7 @@ public:
constexpr inline QFlags operator^(Enum other) const noexcept { return QFlags(QFlag(i ^ Int(other))); }
constexpr inline QFlags operator&(int mask) const noexcept { return QFlags(QFlag(i & mask)); }
constexpr inline QFlags operator&(uint mask) const noexcept { return QFlags(QFlag(i & mask)); }
+ constexpr inline QFlags operator&(QFlags other) const noexcept { return QFlags(QFlag(i & other.i)); }
constexpr inline QFlags operator&(Enum other) const noexcept { return QFlags(QFlag(i & Int(other))); }
constexpr inline QFlags operator~() const noexcept { return QFlags(QFlag(~i)); }
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 8753ac65f4..c1a6e7a268 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -378,6 +378,13 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
*/
/*!
+ \fn template <typename Enum> QFlags &QFlags<Enum>::operator&=(QFlags mask)
+ \since 6.2
+
+ \overload
+*/
+
+/*!
\fn template <typename Enum> QFlags &QFlags<Enum>::operator|=(QFlags other)
Performs a bitwise OR operation with \a other and stores the
@@ -467,6 +474,13 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
*/
/*!
+ \fn template <typename Enum> QFlags QFlags<Enum>::operator&(QFlags mask) const
+ \since 6.2
+
+ \overload
+*/
+
+/*!
\fn template <typename Enum> QFlags QFlags<Enum>::operator~() const
Returns a QFlags object that contains the bitwise negation of