From a009e250042609e2b05680c084b4f4a2768514db Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 9 May 2020 12:36:03 +0300 Subject: [PATCH] Fix (de)serialize enums into QDataStream. It is very important to use exactly the same way across all Qt versions we need to support. Otherwise, it will break interchange between Valentina versions built on different Qt versions. --- src/libs/vmisc/vdatastreamenum.h | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/libs/vmisc/vdatastreamenum.h b/src/libs/vmisc/vdatastreamenum.h index fde42eca4..2df8ccb54 100644 --- a/src/libs/vmisc/vdatastreamenum.h +++ b/src/libs/vmisc/vdatastreamenum.h @@ -34,26 +34,22 @@ // (de)serialize enums into QDataStream +// It is very important to use exactly the same way across all Qt versions we need to support. Otherwise, it will break +// interchange between Valentina versions built on different Qt versions. + #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) -//a function that can serialize any enum into QDataStream -//it stores the enum in a qint64 -template::value>::type> -inline QDataStream& operator<<(QDataStream& stream, const Enum& e) +template +typename std::enable_if::value, QDataStream &>::type& +operator<<(QDataStream &s, const T &t) { - return stream << static_cast(e); + return s << static_cast::type>(t); } -//a function that can deserialize any enum from QDataStream -//it reads the enum as if it was stored in qint64 -template::value>::type> -inline QDataStream& operator>>(QDataStream& stream, Enum& e) +template +typename std::enable_if::value, QDataStream &>::type& +operator>>(QDataStream &s, T &t) { - qint64 v; - stream >> v; - e = static_cast(v); - return stream; + return s >> reinterpret_cast::type &>(t); } #endif