summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals@canonical.com>2013-05-08 18:02:02 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-09 12:17:59 +0200
commit95cab90b1023a824017b6d22f62987ba9742b6b3 (patch)
treecbdcaf3ad1c6d609fabd8950765061da13681ea1 /src/corelib
parentf7eea69a2a322e156594cf5608bbbb97b4d364c1 (diff)
Make QFlags enum flags (C++11 strict enums) friendly
Change-Id: I9ccb3e4d281a545ca1845db4f6aa7ac6c04e8621 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qflags.h15
-rw-r--r--src/corelib/global/qglobal.cpp6
-rw-r--r--src/corelib/io/qdebug.h2
3 files changed, 15 insertions, 8 deletions
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h
index 6332e2d761..5b7edbafa6 100644
--- a/src/corelib/global/qflags.h
+++ b/src/corelib/global/qflags.h
@@ -97,31 +97,32 @@ public:
inline QFlags(const QFlags &other);
inline QFlags &operator=(const QFlags &other);
#endif
- Q_DECL_CONSTEXPR inline QFlags(Enum f) : i(f) {}
+ Q_DECL_CONSTEXPR inline QFlags(Enum f) : i(Int(f)) {}
Q_DECL_CONSTEXPR inline QFlags(Zero = 0) : i(0) {}
Q_DECL_CONSTEXPR inline QFlags(QFlag f) : i(f) {}
inline QFlags &operator&=(int mask) { i &= mask; return *this; }
inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
+ inline QFlags &operator&=(Enum mask) { i &= Int(mask); return *this; }
inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
- inline QFlags &operator|=(Enum f) { i |= f; return *this; }
+ inline QFlags &operator|=(Enum f) { i |= Int(f); return *this; }
inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
- inline QFlags &operator^=(Enum f) { i ^= f; return *this; }
+ inline QFlags &operator^=(Enum f) { i ^= Int(f); return *this; }
Q_DECL_CONSTEXPR inline operator Int() const { return i; }
Q_DECL_CONSTEXPR inline QFlags operator|(QFlags f) const { return QFlags(Enum(i | f.i)); }
- Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const { return QFlags(Enum(i | f)); }
+ Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const { return QFlags(Enum(i | Int(f))); }
Q_DECL_CONSTEXPR inline QFlags operator^(QFlags f) const { return QFlags(Enum(i ^ f.i)); }
- Q_DECL_CONSTEXPR inline QFlags operator^(Enum f) const { return QFlags(Enum(i ^ f)); }
+ Q_DECL_CONSTEXPR inline QFlags operator^(Enum f) const { return QFlags(Enum(i ^ Int(f))); }
Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const { return QFlags(Enum(i & mask)); }
Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const { return QFlags(Enum(i & mask)); }
- Q_DECL_CONSTEXPR inline QFlags operator&(Enum f) const { return QFlags(Enum(i & f)); }
+ Q_DECL_CONSTEXPR inline QFlags operator&(Enum f) const { return QFlags(Enum(i & Int(f))); }
Q_DECL_CONSTEXPR inline QFlags operator~() const { return QFlags(Enum(~i)); }
Q_DECL_CONSTEXPR inline bool operator!() const { return !i; }
- Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == Int(f) ); }
+ Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const { return (i & Int(f)) == Int(f) && (Int(f) != 0 || i == Int(f) ); }
private:
Int i;
};
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 4134dd6700..4598f60d5e 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -240,6 +240,12 @@ Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);
*/
/*!
+ \fn QFlags &QFlags::operator&=(Enum mask)
+
+ \overload
+*/
+
+/*!
\fn QFlags &QFlags::operator|=(QFlags other)
Performs a bitwise OR operation with \a other and stores the
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index ce72fcd26d..9ed5f6e951 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -280,7 +280,7 @@ inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
debug.nospace() << '|';
else
needSeparator = true;
- debug.nospace() << "0x" << QByteArray::number(T(1 << i), 16).constData();
+ debug.nospace() << "0x" << QByteArray::number(typename QFlags<T>::Int(1) << i, 16).constData();
}
}
debug << ')';