summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qdatastream.h
Commit message (Collapse)AuthorAgeFilesLines
* Bootstrap: remove QDataStreamThiago Macieira2024-03-131-1/+1
| | | | | | | | | | | It was only used by the cmake_automoc_parser so it would write a 64-bit in big-endian format. So bypass QDataStream and write it native endianness. Change-Id: I01ec3c774d9943adb903fffd17b79c78e56db4cf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
* QDataStream: make the public-ish private members smaller in Qt 7Thiago Macieira2024-03-121-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | pahole says: class QScopedPointer<QDataStreamPrivate> d; /* 0 8 */ class QIODevice * dev; /* 8 8 */ bool owndev; /* 16 1 */ bool noswap; /* 17 1 */ quint8 fpPrecision; /* 18 1 */ quint8 q_status; /* 19 1 */ enum ByteOrder byteorder; /* 20 4 */ int ver; /* 24 4 */ quint16 transactionDepth; /* 28 2 */ /* size: 32, cachelines: 1, members: 10 */ Which is unnecessary overhead. The previous commit took care of byteorder for Qt 7; this one reduces the size a bit more, to 16 bytes on 32-bit systems and 24 on 64-bit ones. After this, pahole says for the bootstrap library: class QScopedPointer<QDataStreamPrivate> d; /* 0 8 */ class QIODevice * dev; /* 8 8 */ bool owndev; /* 16 1 */ bool noswap; /* 17 1 */ quint8 fpPrecision; /* 18 1 */ quint8 q_status; /* 19 1 */ enum Version ver; /* 20 1 */ /* XXX 1 byte hole, try to pack */ quint16 transactionDepth; /* 22 2 */ /* size: 24, cachelines: 1, members: 9 */ Further packing isn't possible, because of the alignment at 64-bit for this class. Change-Id: I50e2158aeade4256ad1dfffd17b29b80237a8c5b Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QDataStream: don't store the byteorder member in Qt 7Thiago Macieira2024-03-121-1/+7
| | | | | | | | | | | It's redundant with the noswap member: we swap if the stream byte order is the opposite of the CPU's and don't swap if it is the same. That the default is to swap is another reason why people should stop using QDataStream (though CBOR also stores numbers in big-endian). Change-Id: I50e2158aeade4256ad1dfffd17b29adc2b698ead Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QDataStream: use NSDMIThiago Macieira2024-03-121-6/+6
| | | | | | | | Just a little clean-up to avoid repetition. Change-Id: I50e2158aeade4256ad1dfffd17b29a5b36c71ddc Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: Move trasactionDepth to the main classThiago Macieira2024-03-121-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The q_status member has too much space dedicated to it: 32 bits. So we can shrink it to a mere 8 bits and move it up to the 1-byte padding hole and repurpose the space it used to use. This only works because the q_status member was not accessed by any inline function before Qt 6.8 (see commit fc23fa459c5924bf1cc4564c7bce1fd59d7c972b). After this, pahole says: class QScopedPointer<QDataStreamPrivate> d; /* 0 8 */ class QIODevice * dev; /* 8 8 */ bool owndev; /* 16 1 */ bool noswap; /* 17 1 */ quint8 fpPrecision; /* 18 1 */ quint8 q_status; /* 19 1 */ enum ByteOrder byteorder; /* 20 4 */ int ver; /* 24 4 */ quint16 transactionDepth; /* 28 2 */ /* size: 32, cachelines: 1, members: 10 */ That leaves 16 bits of tail padding unused, so reduces the maximum number of nested transactions to 65536. That is to support a Qt 7 layout in an upcoming commit. Change-Id: I50e2158aeade4256ad1dfffd17b29d75fd13f472 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QDataStream: inline floatingPointPrecision()Thiago Macieira2024-03-121-0/+7
| | | | | | | | | | | | | | | | | | | | | | There is a 2-byte padding in all architectures between the noswap member and byteorder, because the latter requires a 32-bit alignment. So we can use this space to store this little-used field and avoid one more reason for QDataStreamPrivate. Now: class QScopedPointer<QDataStreamPrivate> d; /* 0 8 */ class QIODevice * dev; /* 8 8 */ bool owndev; /* 16 1 */ bool noswap; /* 17 1 */ quint8 fpPrecision; /* 18 1 */ /* XXX 1 byte hole, try to pack */ enum ByteOrder byteorder; /* 20 4 */ int ver; /* 24 4 */ enum Status q_status; /* 28 4 */ /* size: 32, cachelines: 1, members: 9 */ Change-Id: I50e2158aeade4256ad1dfffd17b29c2c5db02c12 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QDataStream: code tidiesGiuseppe D'Angelo2024-02-281-1/+1
| | | | | | | | | | | | | | | As spotted in the code review, remove_cv here is useless. Since T is passed by value, template type deduction will strip cv-ref for us. (Also: in general we don't support users specifying template type parameters except where authorized, but here they can't, as this is an operator.) Amends 3823e310e39426043dc7f0529a6fba33fe4d49f0 Change-Id: I5b5db38a4dcf4f1179d748cf0bb1b62a9896f5a6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: Turn QDataStreamSizes enum into static contexpr quint32Øystein Heskestad2024-02-231-7/+8
| | | | | | | | | | The special sizes NullCode and ExtendedSize does not need to be part of an enum. Turning them into constants removes the need for some casts. Task-number: QTBUG-119952 Pick-to: 6.7 Change-Id: Ie7835c52f4642ab907b91f0eceac2ea7650e81da Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QDataStream: reimplement and constrain operator<<(bool)Giuseppe D'Angelo2024-02-201-3/+11
| | | | | | | | | | | | | | | | | Instead of offering it as a plain overload, make it a template and constrain the argument to be precisely bool. This removes the danger of accidentally streaming things that are convertible to bool, such as pointers, by, indeed, converting them to bool. This allows us to remove the deleted overloads for pointers to objects and pointers to members. The existing operator<<(bool) is exported, hence I moved it into removed_api.cpp. Since the implementation required private QDataStream APIs, I've just "inlined" the implementation that simply routed through the operator<<(qint8) overload. Change-Id: I3c0a9811bf5c9e734e28514b37bcaaddb09ada25 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: also disable streaming of member pointersGiuseppe D'Angelo2024-02-161-0/+2
| | | | | | | | | 2fd4a86dc5547d6ff3f512bd33ccf6e10d159ff4 disabled the streaming of pointer with QDataStream, as they would otherwise accidentally select the `bool` overload. Do the same for member pointers. Change-Id: I4910953a2856957518b4e51bdc4a0c26d75addab Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: inline status()Marc Mutz2024-02-121-0/+8
| | | | | | | | | | | | | The implementation is trivial, and unchanged since the beginning of the public project history, so I'd venture that it's safe to commit to it not changing until Qt 7 at this point. The reason to make it inline is that a good stream operator implementation should be checking the stream state quite often, so we shouldn't make that an expensive DLL entry point. Change-Id: Iba8cbfbaf02326c86ab95be17b603cd2e785f78c Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Deprecate QDataStream::readBytes(char *&, uint &) instead of removing itIvan Solovev2024-02-071-1/+4
| | | | | | | | | | | | | | | | | | | | | | We cannot remove the overload using QT_REMOVED_SINCE, because a qint64 lvalue in the new overload will not bind to an uint& parameter, so the old code would not compile. Deprecate the old overload, and add a unit-test that makes sure that it still behaves correctly. This commit also introduces the new deprecation macros that are required to do the deprecation in Qt 6.11. Amends fd48ce0b73c74dafd5db27bc1f2752ef665df7ef Found in 6.7 API review Pick-to: 6.7 Change-Id: I02893bfbe040df736f8e746384e0261a0f0041d3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: use SizeLimitExceeded status in write operationsIvan Solovev2024-02-071-10/+16
| | | | | | | | | | | | | | | | | | | | | | Set this status when the stream tries to write more data than the current serialization format supports. Update the methods that write containers to return early if they fail to write the container size, and do not try to serialize the elements. Convert the manual tst_manualqdatastream test into a data-driven test, allowing us to specify various stream versions. Adjust the test code to check that the SizeLimitExceeded status is set when the stream version is <= Qt_6_6. Amends fd48ce0b73c74dafd5db27bc1f2752ef665df7ef Found in 6.7 API review Pick-to: 6.7 Change-Id: If4c62ea53ac9bccd423f00f0f03afd6ba6bdc4f5 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: use qint64 to represent size while reading and writingIvan Solovev2024-02-071-8/+6
| | | | | | | | | | | | Do that to avoid narrowing at the call site on 32-bit platforms. Amends fd48ce0b73c74dafd5db27bc1f2752ef665df7ef Found in 6.7 API review Pick-to: 6.7 Change-Id: I31142399385521d973b2ed3789745569e44d5d63 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* StreamStateSaver: disable copy/moveMarc Mutz2024-02-021-0/+1
| | | | | | | | | | | | The class has a user-defined destructor, so it mustn't be copied or moved (which here is the same as copying). Amends 3c93286f08a80b6e1821d7d63d361742b25c6578. Pick-to: 6.7 6.6 6.5 Change-Id: I1b23588309654f34aedc0269e1d1c9511ddda2bb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QDataStream: add a new SizeLimitExceeded status codeIvan Solovev2024-01-261-4/+5
| | | | | | | | | | | | | | | | | | This status is supposed to be used when the stream tries to read or write more data than it is supported by the current platform. For example, reading more than 2 GiB of data on a 32-bit platform will result into this status, but it will work fine on a 64-bit platform. This patch uses the new status in read operations. Amends fd48ce0b73c74dafd5db27bc1f2752ef665df7ef Found in 6.7 API review Pick-to: 6.7 Change-Id: I675b1ee25fafba174ce8f94c3470dbb7893d6d9e Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: add missing #include <iterator>Thiago Macieira2024-01-101-0/+2
| | | | | | | | | | | | For std::distance() and std::next(). Amends 003c29511de5979fba526acd62f2a4c7c356b982. Pick-to: 6.2 6.5 6.6 6.7 Task-number: QTBUG-114583 Change-Id: I6e2677aad2ab45759db2fffd17a7318d396cbc4d Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Bump version to 6.8.0Jani Heikkinen2023-12-111-2/+3
| | | | | Change-Id: I407e6fd7a766450bb6fe00da7f6ebbd49496e5cd Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
* Add support for containers > 4 Gi elements in QDataStreamØystein Heskestad2023-10-231-19/+99
| | | | | | | | | | | | The format is changed from 6.7 to support more than UINT32_MAX - 1 elements. The format used to have a quint32 size. Now if the size is larger or equal to 0xfffffffe (2^32 -2) the old size is an extend value 0xfffffffe followed by one quint64 with the actual value. The 32 bit size with all bits set is still used as null value. Fixes: QTBUG-105034 Change-Id: I62188be170fe779022ad58ab84a54b1eaf46e5d9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: prevent accidental streaming of pointersGiuseppe D'Angelo2023-09-171-0/+1
| | | | | | | | | | | | | | | | It doesn't make sense to stream a pointer, but it can happen by accident because ds << ptr will select the operator<<(bool) overload. Disable the out-stream operator for pointers by having a better match. Reading a pointer from a QDataStream doesn't work, as a pointer can't bind to e.g. a bool non-const reference. [ChangeLog][QtCore][QDataStream] Streaming of arbitrary pointers using QDataStream has been disabled. Note that such streaming happened through the streaming operator for bool. Change-Id: I4c98a33b52aae85e441f5a096efd404fbbf1e95f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Bump version to 6.7.0Jani Heikkinen2023-06-121-2/+3
| | | | | Change-Id: I69954ccc5cfb44e7bf02b8fcab18e9320e7e8748 Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
* Shoehorn AccentColor into QPalette and keep existing 64bit resolve maskAxel Spoerl2023-05-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is necessary to add an AccentColor role to QPalette. QPalette currently has 21 color roles and 3 color groups, which require 63 bits to resolve. The resolve mask is implemented with a qint64, which doesn't provide spare bits for another color role. The color role NoRole is used as a default value, marking that a role has not (yet) been defined. The enum value does not represent a valid brush, even though it can theoretically be stored in QPalette's shared data. This patch adds the enum value AccentColor to QPalette::ColorRole, increasing the available color roles to 22. To keep the resolve mask at 63 bits, AccentColor is mapped to NoRole in static constexpr bitPosition. As the enum range would exceed 64 bits without this tweak, 3 additional bits are substracted in the respective static assertion. With NoRole having no bit in the resolve mask, the following adaptions have been implemented: - QPalette::resolve() is adapted to explicitly ignore NoRole. - QPalette::isBrushSet() always returns false for NoRole. - tst_QPalette::setAllPossibleBrushes() to verify the latter - operator== ignores NoRole (documentation updated) AccentColor is added in tst_QPalette::roleValues and enum documentation is adapted. In QPalette's default constructor, the AccentColor brush is defaulting to the Highlight brush, it this is available. Otherwise it is made 30% darker or lighter than the Base brush, depending on dark/light mode heuristics. QPalette's data stram functions have been extended from QDataStream Version Qt_6_6. If earlier versions are de-serialised, the AccentColor defaults to Highlight. An autotest function dataStream() has been added to tst_QPalette. The QDataStream Version Qt_6_6 has been bumped to 21. tst_QDataStream has been adapted to the new version and the new color Role. Change-Id: I98bbf9de95fb83bda921e9614a0db3a3c0ebdf75 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Bump version to 6.6.0Jani Heikkinen2022-12-141-2/+3
| | | | | Change-Id: I957e8a980542f16d3a3b493b41406bbeb884c2dc Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
* Replace usages of Q_CLANG_QDOC with Q_QDOCLuca Di Sera2022-10-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | To allow the user to customize the C++ code that QDoc sees, so as to be able to work-around some limitations on QDoc itself, QDoc defines two symbols: Q_QDOC and Q_CLANG_QDOC, both of which are "true" during an entire execution of QDoc. At a certain point in time, QDoc allowed the user the choice between a custom C++ parser and a Clang based one. The Q_QDOC symbol would always be defined while the Q_CLANG_QDOC symbol would be defined only when the Clang based parser was chosen. In more recent times, QDoc always uses a Clang based parser, such that both Q_CLANG_QDOC and Q_QDOC are always defined, making them equivalent. To avoid using different symbols, and the possible confusion and fragmentation that derives from it, all usages of Q_CLANG_QDOC are now replaced by the equivalent usages of Q_QDOC. Change-Id: I5810abb9ad1016a4c5bbea99acd03381b8514b3f Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Bump version to 6.5.0Jani Heikkinen2022-06-061-2/+3
| | | | | Change-Id: I83a4f915a914bdc18f6706bb902f3e3b13da074f Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QDataStream: make qfloat16 streaming a non-memberMarc Mutz2022-03-141-2/+6
| | | | | | | | | | | | | | | | Remove the member function from the API and re-add it as a hidden friend on qfloat16, where it will be a complete type. [ChangeLog][QtCore][Potentially Souce-Incompatible Changes] The qfloat16 QDataStream operators are now hidden friends and only found by argument-dependent lookup. Previously, these were member functions on QDataStream. Fixes: QTBUG-93499 Pick-to: 6.3 Change-Id: Ib3d4df7a3fe3a9d0938f3be8b70b50fef0416262 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Bump version to 6.4.0Jani Heikkinen2022-01-311-2/+3
| | | | | Change-Id: Ie0e2133d6c9125b901364c979c60b6efd585f026 Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
* QDataStream: remove pointless guard around std::pair operatorsMarc Mutz2021-11-041-2/+0
| | | | | | | | | | | The code is already in 'ifndef QT_NO_DATASTREAM'. Well, the condition is a bit more complicated, which makes this nested guard even more wrong. Amends 55150f0f0bac0a6343da60d8128fc4216b57db2b. Change-Id: I1c8f35ebc0355185244c8bf098d000b7c5c543d5 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix docs for comparison/debug/data stream operators of Qt containersSona Kurazyan2021-10-181-0/+48
| | | | | | | | | | | | | | Because of the constraints on comparison, debug and data stream operators, the return types for them look weird in docs. Conditionally use the actual return types, in case if Q_CLANG_QDOC is defined. Also add the docs of debug stream operators for types for which they were misssing. Task-number: QTBUG-97247 Pick-to: 6.2 Change-Id: I57f2c52bd3af805c7eeebb602c47de1e95ee09bd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Convert all QT_VERSION checks to compare against QT_VERSION_CHECK()Edward Welbourne2021-09-231-2/+2
| | | | | | | The result is generally more readable. Change-Id: I507f67954ecd38516de1b7a6f8244c233ee45ddf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDataStream: Add reminders to remove operators for qfloat16Ievgenii Meshcheriakov2021-09-141-0/+2
| | | | | | | | | | | | | Having I/O operators defined for incomplete types causes hard to diagnose problems when types with template conversion operators are used as arguments to signals or slots. Removing qfloat16 operators is not possible before Qt 7 because of backward compatibility. Task-number: QTBUG-93499 Change-Id: Ifa296bb58c45a06abf79dbe5666a666adaa8eab9 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Adjust src/corelib/serialization/qdatastream.[h/cpp] for 6.3.0Shawn Rutledge2021-09-141-2/+3
| | | | | Change-Id: I9809d6122c6d3c5ad5753d52679f4ac67a17e3d4 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Fix compilation for recursive Qt containersSona Kurazyan2021-09-071-12/+19
| | | | | | | | | | | | | | | | | | | | The operator checks cause compilation errors when trying to check for their existence for recursive containers. This happens because of trying to check for the operators on the template parameter type(s), that inherit from the container itself, which leads to compilation errors. Introduced alternative versions of the operator checks (with _container suffix), that first check if the container is recursive, i.e. any of its template parameter types inherits from the given container, and skips the operator check, if that's the case. The fix is done for all Qt container types that had the problem, except for QVarLengthArray and QContiguousCache, which don't compile with recursive parameter types for unrelated reasons. Fixes: QTBUG-91707 Pick-to: 6.2 6.1 Change-Id: Ia1e7240b4ce240c1c44f00ca680717d182df7550 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Bump the version of QDataStreamFriedemann Kleint2021-02-181-2/+3
| | | | | | | Amends f731802ba82ad260e155783e0427fb3f6ebd99fe. Change-Id: I1ba758ef4c9d80fbc11ecc78e0480f57c95007e2 Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
* Bump versionPaul Wicking2021-01-111-2/+3
| | | | | | | | | CMake edition. Also update default compiled version. Task-number: QTQAINFRA-4126 Change-Id: Ia6f535f553e73bd6b00e2e20752f4961af21ede5 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Long live QKeyCombination!Giuseppe D'Angelo2020-09-031-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | C++20 via P1120 is deprecating arithmetic operations between unrelated enumeration types, and GCC 10 is already complaining. Hence, these operations might become illegal in C++23 or C++26 at the latest. A case of this that affects Qt is in key combinations: a QKeySequence can be constructed by summing / ORing modifiers and a key, for instance: Qt::CTRL + Qt::Key_A Qt::SHIFT | Qt::CTRL | Qt::Key_G (recommended, see below) The problem is that the modifiers and the key belong to different enumerations (and there's 2 enumerations for the modifier, and one for the key). To solve this: add a dedicated class to represent a combination of keys, and operators between those enumerations to build instances of this class. I would've simply defined operator|, but again docs and pre-existing code use operator+ as well, so added both to at least tackle simple cases (modifier + key). Multiple modifiers create a problem: operator+ between them yields int, not the corresponding flags type (because operator+ is not overloaded for this use case): Qt::CTRL + Qt::SHIFT + Qt::Key_A \__________________/ / int / \______________/ int Not only this loses track of the datatypes involved, but it would also then "add" the key (with NO warnings, now its int + enum, so it's not mixing enums!) and yielding int again. I don't want to special-case this; the point of the class is that int is the wrong datatype. Everything works just fine when using operator| instead: Qt::CTRL | Qt::SHIFT | Qt::Key_A \__________________/ / Qt::Modifiers / \______________/ QKeyCombination So I'm defining operator+ so that the simple cases still work, but also deprecating it. Port some code around Qt to the new class. In certain cases, it's a huge win for clarity. In some others, I've just added the necessary casts to make it still compile without warnings, without attempting refactorings. [ChangeLog][QtCore][QKeyCombination] New class to represent a combination of a key and zero or more modifiers, to be used when defining shortcuts or similar. [ChangeLog][Potentially Source-Incompatible Changes] A keyboard modifier (such as Qt::CTRL, Qt::AltModifier, etc.) should be combined with a key (such as Qt::Key_A, Qt::Key_F1, etc.) by using operator|, not operator+. The result is now an object of type QKeyCombination, that stores the key and the modifiers. Change-Id: I657a3a328232f059023fff69c5031ee31cc91dd6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Remove deprecated QDataStream::unsetDevice()Edward Welbourne2020-08-281-4/+0
| | | | | | | Deprecated since 5.13. Change-Id: I9f8f58fb92bc12d32eab5b0ae8611611fe2481e5 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Disentangle QIODevice dependenciesLars Knoll2020-08-151-5/+5
| | | | | | | | | | | | | | | | | Move the QIODevice::OpenMode enum into a base class, so that we can remove the full QIODevice (and thus QObject) dependency from qdatastream.h and qtextstream.h. This is required so that we can include QDataStream in qmetatype.h without getting circular dependencies. As a nice side effect, QDataStream and QTextStream can now inherit QIODeviceBase and provide the OpenMode enum directly in their class scope. Change-Id: Ifa68b7b1d8d95687ed032f6c9206f92e63bfacdf Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Add overload for char to QDataStreamLars Knoll2020-08-151-0/+8
| | | | | | | | | This is a distinct types in C++, and should be supported out of the box in QDataStream. This is also required so we do find a data stream operator for the types when searching for it using template magic. Change-Id: Iea57780621e2aab7ed253f1cc896bebada43b9f0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove friend declarations that aren't requiredLars Knoll2020-08-151-2/+7
| | | | | | | | | | | | Those are problematic as they are also interpreted as forward declarations of methods that are defined inline in qdatastream.h and might never get instantiated. This can lead to problems if template code checks for the existence of the method. Change-Id: I4550a6bc70ebd7edc57fe0420b89b453195971d0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Small cleanupLars Knoll2020-08-151-2/+2
| | | | | | Change-Id: I3badb73bee8cb88992254c6f11ae292e21d4a6d7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Constrain the data stream operators for containersLars Knoll2020-08-151-14/+21
| | | | | | | | | | | Check that we can successfully instantiate the data stream operator for a container before we actually try. This is required so we can automate registration of debug stream operators with QMetaType. Change-Id: Ib100a5242470d7fc8067058cc4d81af2fa9354b0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use QList instead of QVector in corelibJarek Kobus2020-06-251-2/+2
| | | | | | | | | | Applied to headers only. Source file to be changed separately. Omitted statemachine for now to avoid conflicts. Omitted qmetatype.h for now - to be handled later. Task-number: QTBUG-84469 Change-Id: I317376037a62467c313467d92955ad0b7473aa97 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Long live std::pair!Giuseppe D'Angelo2020-06-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make QPair an alias for std::pair, and qMakePair just a forwarder towards std::make_pair. Why? Fundamentally to ditch a bunch of NIH code; gain for free structured bindings, std::tuple and std::reference_wrapper compatibility, and so on. Breakages: * Some that code manually forward declares QPair. We don't care about it (<QContainerFwd> is the proper way). * Some code that overloads on std::pair and QPair. Luckily it's mostly centralized: debug, metatypes, testing macros. Just remove the QPair overload. * Usages of qMakePair forcing the template type parameters. There are a handful of these in qtbase, but only one was actually broken. * std::pair is NOT (and will never likely be) trivially copiable. This is agreed to be a mistake done by practically all implementations in C++11, can can't be fixed without breaking ABI. Some code using QPair assuming it's trivially copiable may break; exactly one occurrence was in qtbase. * QMetaType logic extracts the type names in two different ways, one by looking at the source code string (e.g. extracted by moc) and one via some ad-hoc reflection in C++. We need to make "QPair" (as spelled in the source code) be the same as "std::pair" (gathered via reflection, which will see through the alias) when compared. The way it's already done e.g. for QList is by actually replacing the moc-extracted name with the name of the actual type used in C++; do the same here. On libc++, std::pair is actually in an inline namespace -- i.e. std::__1::pair; the reflection will extract and store "std::__1::pair" so we need an ad-hoc fix to QMetaType. [ChangeLog][QtCore][QPair] QPair is now an alias to std::pair, and does not exist as a class in Qt any more. This may break code such as functions overloaded for both QPair and std::pair. Usually, the overload taking a QPair can be safely discarded, leaving only the one taking a std::pair. QPair API has not changed, and qMakePair is still available for compatibility (although new code is encouraged to use std::pair and std::make_pair directly instead). Change-Id: I7725c751bf23946cde577b1406e86a336c0a3dcf Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QMetaType: Support char16_t and char32_tFabian Kosmale2020-05-151-0/+5
| | | | | Change-Id: Ieec6d4bc64967d875ea12b31638aab05bc682ea3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Bump the datastream version for Qt 6Jarek Kobus2020-02-281-7/+1
| | | | | | | We don't support obsoleted QMatrix type anymore. Change-Id: Id412510aa1ad08d6e89a73da3317152e6dfa8f57 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Separate streaming of QHash and QMultiHash/QMap and QMultiMapLars Knoll2020-02-031-17/+39
| | | | | | | | | | Those classes will not have relations anymore in Qt6, so they need separate streaming operators. Writing of multi maps/hashes requires some additional care so that restoring keeps the order of how iteme have been inserted. Change-Id: If41d0c5c24962764a2cb81bd2de9e2fadf1a2b63 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Merge remote-tracking branch 'origin/5.15' into devLiang Qi2020-01-041-0/+3
|\ | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/tools/qvector.h Make QVector(DataPointer dd) public to be able to properly merge 5b4b437b30b320e2cd7c9a566999a39772e5d431 from 5.15 into dev. src/widgets/kernel/qapplication.cpp tests/auto/tools/moc/allmocs_baseline_in.json Done-With: Christian Ehrlicher <ch.ehrlicher@gmx.de> Change-Id: I929ba7c036d570382d0454c2c75f6f0d96ddbc01
| * Qt 6: Deprecate QHash::insertMultiLars Knoll2019-12-121-0/+3
| | | | | | | | | | | | | | | | | | [ChangeLog][QtCore][QHash] insertMulti(), unite() and values(const Key &key) are now deprecated. Please use QMultiHash instead. Change-Id: Ic14907fd5fd38d585708e2dcf2c0200d221ebb25 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>