OSDN Git Service

bye QDataStream versioning
authorIvailo Monev <xakepa10@gmail.com>
Tue, 18 Oct 2022 01:15:16 +0000 (04:15 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 18 Oct 2022 01:15:16 +0000 (04:15 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/io/qdatastream.cpp
src/core/io/qdatastream.h
tests/auto/qdatastream/tst_qdatastream.cpp

index a7bd200..7a26d84 100644 (file)
@@ -91,29 +91,13 @@ QT_BEGIN_NAMESPACE
     changed with setDevice(). If you've reached the end of the data
     (or if there is no I/O device set) atEnd() will return true.
 
-    \section1 Versioning
+    \section1 Compatibility
 
     QDataStream's binary format has evolved since Qt 1.0, and is
-    likely to continue evolving to reflect changes done in Qt. When
-    inputting or outputting complex types, it's very important to
-    make sure that the same version of the stream (version()) is used
-    for reading and writing. If you need both forward and backward
-    compatibility, you can hardcode the version number in the
-    application:
-
-    \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 2
-
-    If you are producing a new binary data format, such as a file
-    format for documents created by your application, you could use a
-    QDataStream to write the data in a portable format. Typically, you
-    would write a brief header containing a magic string and a version
-    number to give yourself room for future expansion. For example:
-
-    \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 3
-
-    Then read it in with:
-
-    \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 4
+    likely to continue evolving to reflect changes done in Katie.
+    If you need both forward and backward compatibility, you would
+    write a brief header containing a magic string and a version
+    number to give yourself room for future expansion.
 
     You can select which byte order to use when serializing data. The
     default setting is big endian (MSB first). Changing it to little
@@ -185,8 +169,7 @@ QT_BEGIN_NAMESPACE
 /*!
   \enum QDataStream::FloatingPointPrecision
 
-  The precision of floating point numbers used for reading/writing the data. This will only have
-  an effect if the version of the data stream is Qt_4_6 or higher.
+  The precision of floating point numbers used for reading/writing the data.
 
   \warning The floating point precision must be set to the same value on the object that writes
   and the object that reads the data stream.
@@ -245,7 +228,6 @@ QDataStream::QDataStream()
     owndev(false),
     noswap(QDataStream::HostEndian == QDataStream::BigEndian),
     byteorder(QDataStream::BigEndian),
-    ver(QDataStream::Qt_Default),
     q_status(QDataStream::Ok),
     floatingPrecision(QDataStream::DoublePrecision)
 {
@@ -268,7 +250,6 @@ QDataStream::QDataStream(QIODevice *device)
     owndev(false),
     noswap(QDataStream::HostEndian == QDataStream::BigEndian),
     byteorder(QDataStream::BigEndian),
-    ver(QDataStream::Qt_Default),
     q_status(QDataStream::Ok),
     floatingPrecision(QDataStream::DoublePrecision)
 {
@@ -293,7 +274,6 @@ QDataStream::QDataStream(QByteArray *a, QIODevice::OpenMode flags)
     owndev(true),
     noswap(QDataStream::HostEndian == QDataStream::BigEndian),
     byteorder(QDataStream::BigEndian),
-    ver(QDataStream::Qt_Default),
     q_status(QDataStream::Ok),
     floatingPrecision(QDataStream::DoublePrecision)
 {
@@ -318,7 +298,6 @@ QDataStream::QDataStream(const QByteArray &a)
     owndev(true),
     noswap(QDataStream::HostEndian == QDataStream::BigEndian),
     byteorder(QDataStream::BigEndian),
-    ver(QDataStream::Qt_Default),
     q_status(QDataStream::Ok),
     floatingPrecision(QDataStream::DoublePrecision)
 {
@@ -402,14 +381,10 @@ QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const
 }
 
 /*!
-    Sets the floating point precision of the data stream to \a precision. If the floating point precision is
-    DoublePrecision and the version of the data stream is Qt_4_6 or higher, all floating point
-    numbers will be written and read with 64-bit precision. If the floating point precision is
-    SinglePrecision and the version is Qt_4_6 or higher, all floating point numbers will be written
-    and read with 32-bit precision.
-
-    For versions prior to Qt_4_6, the precision of floating point numbers in the data stream depends
-    on the stream operator called.
+    Sets the floating point precision of the data stream to \a precision. If the floating point
+    precision is DoublePrecision, all floating point numbers will be written and read with 64-bit
+    precision. If the floating point precision is SinglePrecision, all floating point numbers will
+    be written and read with 32-bit precision.
 
     The default is DoublePrecision.
 
@@ -490,68 +465,6 @@ void QDataStream::setByteOrder(ByteOrder bo)
     noswap = (byteorder == QDataStream::HostEndian);
 }
 
-/*!
-    \enum QDataStream::Version
-
-    This enum provides symbolic synonyms for the data serialization
-    format version numbers.
-
-    \value Qt_4_6 Version 12 (Qt 4.6, Qt 4.7, Qt 4.8, Katie 4.9, Katie 4.10, Katie 4.11)
-    \value Qt_4_7 Same as Qt_4_6.
-    \value Qt_4_8 Same as Qt_4_6.
-    \value Qt_4_9 Same as Qt_4_6.
-    \value Qt_4_10 Same as Qt_4_6.
-    \value Qt_4_11 Same as Qt_4_6.
-    \value Qt_4_12 Version 13 (Katie 4.12)
-    \value Qt_Default
-
-    \sa setVersion(), version()
-*/
-
-/*!
-    \fn int QDataStream::version() const
-
-    Returns the version number of the data serialization format.
-
-    \sa setVersion(), Version
-*/
-
-/*!
-    \fn void QDataStream::setVersion(Version v)
-
-    Sets the version number of the data serialization format to \a v.
-
-    You don't \e have to set a version if you are using the current
-    version of Katie, but for your own custom binary formats we
-    recommend that you do; see \l{Versioning} in the Detailed
-    Description.
-
-    To accommodate new functionality, the datastream serialization
-    format of some Katie classes has changed in some versions of Katie.
-    If you want to read data that was created by an earlier version of
-    Katie, or write data that can be read by a program that was compiled
-    with an earlier version of Katie, use this function to modify the
-    serialization format used by QDataStream.
-
-    \table
-    \header \i Toolkit Version      \i QDataStream Version
-    \row    \i Qt 4.6               \i 12
-    \row    \i Qt 4.7               \i 12
-    \row    \i Qt 4.8               \i 12
-    \row    \i Katie 4.9            \i 12
-    \row    \i Katie 4.10           \i 12
-    \row    \i Katie 4.11           \i 12
-    \row    \i Katie 4.12           \i 13
-    \endtable
-
-    The \l Version enum provides symbolic constants for the different
-    versions of Katie. For example:
-
-    \snippet doc/src/snippets/code/src_corelib_io_qdatastream.cpp 5
-
-    \sa version(), Version
-*/
-
 /*****************************************************************************
   QDataStream read functions
  *****************************************************************************/
index 87582a7..e1e2f6f 100644 (file)
 
 #include <QtCore/qiodevice.h>
 
-
 QT_BEGIN_NAMESPACE
 
-
 class QByteArray;
 
 template <typename T> class QList;
@@ -40,21 +38,6 @@ template <class Key, class T> class QMap;
 class Q_CORE_EXPORT QDataStream
 {
 public:
-    enum Version {
-        Qt_4_6 = 12,
-        Qt_4_7 = Qt_4_6,
-        Qt_4_8 = Qt_4_7,
-        Qt_4_9 = Qt_4_8,
-        Qt_4_10 = Qt_4_9,
-        Qt_4_11 = Qt_4_10,
-        Qt_4_12 = 13,
-#if QT_VERSION > 0x041200
-#error Add the datastream version for this version
-        Qt_4_13 = Qt_4_12
-#endif
-        Qt_Default = Qt_4_12
-    };
-
     enum ByteOrder {
         BigEndian = Q_BIG_ENDIAN,
         LittleEndian = Q_LITTLE_ENDIAN,
@@ -94,9 +77,6 @@ public:
     ByteOrder byteOrder() const;
     void setByteOrder(ByteOrder);
 
-    Version version() const;
-    void setVersion(Version);
-
     QDataStream &operator>>(qint8 &i);
     QDataStream &operator>>(quint8 &i);
     QDataStream &operator>>(qint16 &i);
@@ -139,7 +119,6 @@ private:
     bool owndev;
     bool noswap;
     ByteOrder byteorder;
-    Version ver;
     DataStatus q_status;
     FloatingPointPrecision floatingPrecision;
 };
@@ -155,12 +134,6 @@ inline QIODevice *QDataStream::device() const
 inline QDataStream::ByteOrder QDataStream::byteOrder() const
 { return byteorder; }
 
-inline QDataStream::Version QDataStream::version() const
-{ return ver; }
-
-inline void QDataStream::setVersion(QDataStream::Version v)
-{ ver = v; }
-
 inline QDataStream &QDataStream::operator>>(quint8 &i)
 { return *this >> reinterpret_cast<qint8&>(i); }
 
index 46476a3..ea5cbe0 100644 (file)
@@ -136,9 +136,6 @@ private slots:
 
     void stream_QByteArray2();
 
-    void setVersion_data();
-    void setVersion();
-
     void skipRawData_data();
     void skipRawData();
 
@@ -236,33 +233,6 @@ private:
     QString svgFile;
 };
 
-static int NColorRoles[] = {
-    QPalette::NoRole,              // No Version
-    QPalette::NoRole,              // Qt_1_0
-    QPalette::HighlightedText + 1, // Qt_2_0
-    QPalette::HighlightedText + 1, // Qt_2_1
-    QPalette::LinkVisited + 1,     // Qt_3_0
-    QPalette::HighlightedText + 1, // Qt_3_1
-    QPalette::HighlightedText + 1, // Qt_3_3
-    QPalette::HighlightedText + 1, // Qt_4_0, Qt_4_1
-    QPalette::HighlightedText + 1, // Qt_4_2
-    QPalette::AlternateBase + 1,   // Qt_4_3
-    QPalette::ToolTipText + 1,     // Qt_4_4
-    QPalette::ToolTipText + 1,     // Qt_4_5
-    QPalette::ToolTipText + 1,     // Qt_4_6
-    QPalette::ToolTipText + 1,     // Qt_4_7
-    QPalette::ToolTipText + 1,     // Qt_4_8
-    QPalette::ToolTipText + 1,     // Qt_4_9
-    QPalette::ToolTipText + 1,     // Qt_4_10
-    QPalette::ToolTipText + 1,     // Qt_4_11
-    QPalette::ToolTipText + 1,     // Qt_4_12
-#if QT_VERSION > 0x041200
-#error Add the datastream color role for this version
-    QPalette::ToolTipText + 1,     // Qt_4_13
-#endif
-    0                              // add the correct value for Qt_4_13 here later
-};
-
 // Testing get/set functions
 void tst_QDataStream::getSetCheck()
 {
@@ -2115,99 +2085,6 @@ void tst_QDataStream::stream_QByteArray2()
     }
 }
 
-void tst_QDataStream::setVersion_data()
-{
-    QTest::addColumn<int>("vers");
-    QDataStream latest;
-
-    for (int vers = QDataStream::Qt_4_6; vers <= latest.version(); ++vers)
-        QTest::newRow(qPrintable(QString("v_%1").arg(vers))) << vers;
-
-
-}
-
-void tst_QDataStream::setVersion()
-{
-    QDataStream latest;
-    QFETCH(int, vers);
-
-    /*
-    Test QKeySequence.
-    */
-    QByteArray ba1;
-    {
-        QDataStream out(&ba1, QIODevice::WriteOnly);
-        out.setVersion(static_cast<QDataStream::Version>(vers));
-        out << QKeySequence(Qt::Key_A) << QKeySequence(Qt::Key_B, Qt::Key_C)
-                << (quint32)0xDEADBEEF;
-    }
-    {
-        QKeySequence keyseq1, keyseq2;
-        quint32 deadbeef;
-        QDataStream in(&ba1, QIODevice::ReadOnly);
-        in.setVersion(static_cast<QDataStream::Version>(vers));
-        in >> keyseq1 >> keyseq2 >> deadbeef;
-        QVERIFY(keyseq1 == QKeySequence(Qt::Key_A));
-        QVERIFY(keyseq2 == QKeySequence(Qt::Key_B, Qt::Key_C));
-        QVERIFY(deadbeef == 0xDEADBEEF);
-    }
-
-       /*
-    Test QPalette.
-    */
-
-
-       // revise the test if new color roles or color groups are added
-    QVERIFY(QPalette::NColorRoles == QPalette::ToolTipText + 1);
-    QVERIFY(QPalette::NColorGroups == 3);
-
-    QByteArray ba2;
-    QPalette pal1, pal2;
-    for (int grp = 0; grp < (int)QPalette::NColorGroups; ++grp) {
-        for (int role = 0; role < (int)QPalette::NColorRoles; ++role) {
-               // random stuff
-            pal1.setColor((QPalette::ColorGroup)grp, (QPalette::ColorRole)role,
-                           QColor(grp * 13, 255 - grp, role));
-            pal2.setColor((QPalette::ColorGroup)grp, (QPalette::ColorRole)role,
-                           QColor(role * 11, 254 - role, grp));
-        }
-    }
-
-    {
-        QDataStream out(&ba2, QIODevice::WriteOnly);
-        out.setVersion(static_cast<QDataStream::Version>(vers));
-        out << pal1 << pal2 << (quint32)0xCAFEBABE;
-    }
-    {
-        QPalette inPal1, inPal2;
-        quint32 cafebabe;
-        QDataStream in(&ba2, QIODevice::ReadOnly);
-        in.setVersion(static_cast<QDataStream::Version>(vers));
-        in >> inPal1 >> inPal2;
-        in >> cafebabe;
-
-        QCOMPARE(cafebabe, 0xCAFEBABE);
-
-        QCOMPARE(NColorRoles[latest.version()], (int)QPalette::NColorRoles);  //if this fails you need to update the NColorRoles  array
-
-        if (NColorRoles[vers] < QPalette::NColorRoles) {
-            QVERIFY(pal1 != inPal1);
-            QVERIFY(pal2 != inPal2);
-
-            for (int grp = 0; grp < (int)QPalette::NColorGroups; ++grp) {
-                for (int i = NColorRoles[vers]; i < QPalette::NColorRoles; ++i) {
-                    inPal1.setColor((QPalette::ColorGroup)grp, (QPalette::ColorRole)i,
-                                        pal1.color((QPalette::ColorGroup)grp, (QPalette::ColorRole)i));
-                    inPal2.setColor((QPalette::ColorGroup)grp, (QPalette::ColorRole)i,
-                                        pal2.color((QPalette::ColorGroup)grp, (QPalette::ColorRole)i));
-                }
-            }
-        }
-        QVERIFY(pal1 == inPal1);
-        QVERIFY(pal2 == inPal2);
-    }
-}
-
 class SequentialBuffer : public QBuffer
 {
 public: