diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2016-09-29 14:12:21 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-02-09 17:46:11 +0000 |
commit | 7314c53d31662ba2e13154f757ecc463d79bc5a8 (patch) | |
tree | 5abd9f37ad14a3099a752cfc637a9e1423172888 | |
parent | dee16fe491f9f92943874c7156115c5da68ec639 (diff) | |
download | qtbase-7314c53d31662ba2e13154f757ecc463d79bc5a8.tar.gz |
Add QDataStream streaming operator for QFlags
We're already using it, for example in qpaintengine_pic.cpp:502:
d->s << p << ti.text() << fnt << ti.renderFlags() << [...]
^
[ChangeLog][QtCore][QFlags] Added operator<< and operator>> for
streaming QFlags into and out of QDataStreams.
Change-Id: I33dc971f005a4848bb8ffffd1478e79d6102d1bc
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r-- | src/corelib/global/qflags.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qdatastream.h | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index 93dbedc930..feeb488acd 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -48,6 +48,8 @@ QT_BEGIN_NAMESPACE +class QDataStream; + class QFlag { int i; @@ -95,6 +97,8 @@ class QFlags struct Private; typedef int (Private::*Zero); + template <typename E> friend QDataStream &operator>>(QDataStream &, QFlags<E> &); + template <typename E> friend QDataStream &operator<<(QDataStream &, QFlags<E>); public: #if defined(Q_CC_MSVC) || defined(Q_QDOC) // see above for MSVC diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h index ecd55f71ae..db1bbfbd63 100644 --- a/src/corelib/io/qdatastream.h +++ b/src/corelib/io/qdatastream.h @@ -359,6 +359,14 @@ inline QDataStream &QDataStream::operator<<(quint32 i) inline QDataStream &QDataStream::operator<<(quint64 i) { return *this << qint64(i); } +template <typename Enum> +inline QDataStream &operator<<(QDataStream &s, QFlags<Enum> e) +{ return s << e.i; } + +template <typename Enum> +inline QDataStream &operator>>(QDataStream &s, QFlags<Enum> &e) +{ return s >> e.i; } + template <typename T> inline QDataStream &operator>>(QDataStream &s, QList<T> &l) { |