summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Remap QMetaType ids to create more space for builtin typesLars Knoll2020-09-121-22/+58
| | | | | | | | | | | We were starting to run out of space for builtin core types. Remap the type id's to create lots of additional space. We now reserve the first 64k id's for Qt, and have 16k id's for Qt Core. That should hopfully be enough for a while ;-) Fixes: QTBUG-85914 Change-Id: I0dab6bf23652e46a9557d9b38af7990b68c572b6 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Remove spurious const from QVariant::convert()'s first parameterEdward Welbourne2020-09-101-2/+2
| | | | | | | | As per ### Qt6 comment. Task-number: QTBUG-85700 Change-Id: I24292d9f2b8f7781032aa8df2a7a0c58ad4fb6c9 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Reimplement QSequentialIterable using QMetaSequenceUlf Hermann2020-09-031-306/+0
| | | | | Change-Id: Ie721a5f0caa697c4bf15a81f3762cf79d3c54f5a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix comparison of QVariants that contain pointers to QObjectsLars Knoll2020-08-291-0/+26
| | | | | | | | | | | Allow comparing variants of different types, if both types are pointers to related objects. Amends change 4a69cd7f72140c8f4c83f986b3366f7bd9ba69a3 Change-Id: Ib52b17781b0b7f60cfd5da42fce733faacfa0ae8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove the alignas() from QVariant::PrivateLars Knoll2020-08-261-1/+1
| | | | | | | | This was causing miscompilations with clang on macOS. As it's not really required, remove the alignment requirement. Change-Id: Iacef1af7f51990daddc73fe74449adc1a823aa33 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Rename QSequentialIterable::refUlf Hermann2020-08-241-14/+14
| | | | | | | | Follow the naming convention and remove workarounds in ctors. Change-Id: Ic7f9de074edab7db369803612a2a2a4ea3deaf57 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove private QSequentialIterable begin/end methodsUlf Hermann2020-08-241-12/+2
| | | | | | | | | Those are only used by the only friend of the class. As that one can already poke into QSequentialIteralble's privates, there is no point in exposing further methods in the public API. Change-Id: I368e7bcfc43c31f38a42a41a339ff3135d79417c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove QVariant(QDataStream) constructorLars Knoll2020-08-241-11/+0
| | | | | | | | | | | | | | | The constructor wasn't constructing a QVariant holding a QDataStream, bug loading the variant from the datastream. This is opposed to how QDataStream works in all other places, and also not in line with all other constructors for QVariant. [ChangeLog][QtCore][QVariant] Removed the QVariant(QDataStream) constructor. Use QVariant().load(datastream) instead. Change-Id: I6ac54e12166b9383c09c3940eef2516f896fd359 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clean up int based convert() APILars Knoll2020-08-241-7/+8
| | | | | | | Pass QMetaType instances instead. Change-Id: I07366cea566fdebf5bb793aa8087f8109216ec0c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Deprecate int based convert/canConvertLars Knoll2020-08-241-13/+43
| | | | | | | Better to provide the correct meta type to convert to. Change-Id: I8e0d46e4ba482186201c157e302c03874bd38e7b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Deprecate the static int based API in QMetaTypeLars Knoll2020-08-241-23/+14
| | | | | | | | | | | | | And remove one of the type id to name mapping that still existed in QMetaType. QMetaTypeInterface can provide that, so there's no need to have a second copy of the data. qMetaTypeTypeInternal() can still map all the names of all builtin types to ids. That functionality is for now still required by moc and can't be removed yet. Change-Id: Ib4f8e9c71e1e7d99d52da9e44477c9a1f1805e57 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove refcounting of QMetaTypeInterfaceLars Knoll2020-08-241-6/+0
| | | | | | | | | It's only used for dynamic types in DBUS and QML, where we control things good enough to be able to handle the lifetime of those interfaces there. Change-Id: Ia7f8970d17a85b195db85fcdc2d8f1febd8753f4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Cleanup qvariant_cast<>Lars Knoll2020-08-241-42/+30
| | | | | | | | | | Move the last functionality it had (casting between QObject derived types) over to QMetaType. Now qvariant_cast<> is nothing but a wrapper around QMetaType::convert(). Change-Id: Iab02b6b97c141d64052823646e18227d1eb403dd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move conversions to and from *Iterables into QMetaTypeLars Knoll2020-08-241-21/+0
| | | | | | | | Those were not yet supported by QMetaType. Change-Id: I9f85476049f200e35939ac58ef7e8b4e7cbe0b77 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Implement QMetaType::canConvert() and use it in QVariantLars Knoll2020-08-241-392/+4
| | | | | | | | | | | | | | | | | | | | Use the fact that we return the conversion function as a lambda to find out reliably whether a conversion between two types can be done. This requires some minor adjustments to our tests: * Nothing can convert to an unknown type and vice versa * Adjust results to the fact that we don't convert from char to QString anymore (where the old method was incorrect) * QStringList->QString requires some adjustments, as we only convert if the string list has exactly one element. For now we return true in canConvert(), but the conversion behavior in this case is something we should rethink, as it is very surprising. Change-Id: I3f5f87ee9cb99d690f5a7d13b13d6a6313d8038e Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Get rid of the old QVariant conversion codepathLars Knoll2020-08-241-55/+7
| | | | | | | All conversions do now happen through QMetaType::convert(). Change-Id: I70f7a883262087768acccf8361d34c0490ff2b43 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QJsonValue and QCborValue conversions to QMetaTypeLars Knoll2020-08-241-151/+0
| | | | | Change-Id: Id4796e0913c0c5b0abce0ea27bed0f7b41bc0cca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove some unused codeLars Knoll2020-08-241-12/+0
| | | | | Change-Id: I184c0e00562b9cc61e628457629633f8157333ad Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Finish porting number conversions to QMetaTypeLars Knoll2020-08-241-242/+0
| | | | | Change-Id: I2861c6fb5f8192a627ffb41f1455c703849cf945 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move enum conversions over into QMetaTypeLars Knoll2020-08-241-89/+0
| | | | | | | | Take the opportunity to properly handle the underlying type (size and signed vs unsigned). Change-Id: I0cb8cf40acac6de03c24ed3fe570db68268952c8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Start porting conversions over from QVariant to QMetaTypeLars Knoll2020-08-241-581/+13
| | | | | | | | | | This will ensure full symmetry in what QVariant and QMetaType support. With this done, QVariant will become simply a container that can hold any QMetaType with fully symmetric functionality between both. Change-Id: I796d4368a2bc0f08cf4f70f4465ed6a0e07bdd76 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Remove some dead codeLars Knoll2020-08-241-9/+0
| | | | | Change-Id: Ic1cd0a70b2412c0e4bfcc06bf5609f9d4590ae66 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Always try to conversions through QMetaTypeLars Knoll2020-08-241-21/+9
| | | | | | | | | Always ask QMetaType to convert first before trying the builtin code in QVariant. That way we can migrate conversions piece by piece to QMetaType. Change-Id: I4fd1bad3ef045d37f84f68e748a6357e0ee0c16c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use QVariant::Private::typeId()Lars Knoll2020-08-241-96/+96
| | | | | | | | Avoid some atomic operations by using this instead of type().id(). Change-Id: Ic664794908d3a9fc3686f954b582740b73c052c6 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Clean up QVariant::Private::DataLars Knoll2020-08-241-78/+65
| | | | | | | | | | | Remove all the internal members of the union. Instead replace it with raw storage (uchar[]) aligned to max_align_t. Place all accesses to the internal members with get<> methods for consistency. Change-Id: Icebf46b90c9375aa6ea0b5913b2132608e8c223d Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Get rid of the private v_cast<>() methodLars Knoll2020-08-241-186/+186
| | | | | | | Replace it with QVariant::Private::get<>(). Change-Id: I801742300d9b15f748bb91fcd6cfa176d2057271 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Use QMetaTypeModuleHelper as the interface to do type conversionsLars Knoll2020-08-241-76/+36
| | | | | | | | | | | | | | Move the type conversions from QVariant::Helper to QMetaType. Only do this for Qt Gui in a first step. This makes it possible to completely remove the Handler struct in QVariant, and now allows QMetaType to also convert Gui types. Moving the conversion of Core types into QMetaType will require further work. Change-Id: I061f789deca1b595d92bb29227eb54b8e71a3ee3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Get rid of the additional bool * parameter to the internal convert methodLars Knoll2020-08-241-65/+58
| | | | | | | That parameter is duplicating the return value, get rid of it. Change-Id: I8d6ecee8aca90aecaf08e6d0072d83e9a08ce3d6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Inline QVariant::constData()Lars Knoll2020-08-241-9/+2
| | | | | | | This should speed up quite some of the QVariant operations Change-Id: Ifae2df39e47e2e1ef1d9a947802bdd17fc66aa66 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Cleanup QVariant::PrivateSharedLars Knoll2020-08-241-23/+15
| | | | | | | | | | | | | Remove the additional indirection through ptr and replace it with an offset calculation. Get rid of PrivateSharedEx that was handling certain types differently. This also fixes the support for overaligned types, by using the alignment field from QMetaType to determine the alignment requirements. Change-Id: Icc6a78eb57f664c7747450578fe58dfee8f2863b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Always use the variants internal space if possibleLars Knoll2020-08-241-2/+1
| | | | | | | | | | There's no point in storing small types with an external refcount, even if they aren't movable. Simply copying the type should be faster in pretty much all cases, while this uses less memory. Change-Id: I127474f8e3c5fa042f530684f9d5bfccbba134ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Simplify the QVariant copy constructor and assignment operatorLars Knoll2020-08-241-5/+7
| | | | | Change-Id: Id517dfc220adf06c5852745c92cfbe5e9c2e94a3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Refactor Q*IterableLars Knoll2020-08-241-21/+33
| | | | | | | | | | | | Refactor the methods retrieving data in Q*Iterable so that we don't return pointers with unclear ownership. Instead, copy the data into a out pointer provided by the caller. This also means there is no need for the metatype flags anymore and we can remove those. Change-Id: I517de23a8ccfd608585ca00403aca0df2955f14b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Cleanups in the Iterable classesLars Knoll2020-08-241-6/+6
| | | | | | | Store a QMetaType, not a meta type id in the classes. Change-Id: If27a60512a46fa029cc914d65b8cad7f89d7f3b0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Get rid of the custom debug stream handling in QVariantLars Knoll2020-08-241-51/+4
| | | | | | | | Use the builtin support in QMetaType instead. Change-Id: Ifc0e88719a384aa7fb525652bada22b6f7ee1c45 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Automatically register data/debug stream operations in QMetaTypeLars Knoll2020-08-241-3/+4
| | | | | | | | | | | | | | | | | | | | | | And remove the old manual registration code for those operators. Add some special handling for long/ulong, as these types could be streamed as a QVariant so far, but are not directly streamable through QDataStream. [ChangeLog][QtCore][QMetaType] The QMetaType::registerStreamOperators() and QMetaType::registerDebugStreamOperator() methods have been removed. The streaming operators for a type are now automatically registered together with the type registration. This implies that the operators should be visible wherever the type is visible and being used. [ChangeLog][Behavior Incompatible Changes] Because the QDataStream and QDebug serialization operators are automatically registered with QMetaType, the declarations of those functions must be present at any point where the type is used with QMetaType and QVariant. Change-Id: I4a0732651b20319af4a8397ff90b848ca4580d99 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant::metaType(): Add missing \since Qt 6.0Marcel Krems2020-08-231-0/+2
| | | | | | | Amends a68e4f3b96a82a93898f381e8ddc7f50f9c89d40 Change-Id: Ice8f83e11e03db1d76e12ffd2b548a6b69684842 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix a number of qdoc warningsFriedemann Kleint2020-08-201-4/+4
| | | | | | | | | | | - Remove obsolete functions and enumeration values - Remove QObject * parameter from QMetaProperty accessors - Fix renamed enumerations in QSsl - Fix list items to be \li - Fix function signatures and variable names Change-Id: I37c7e6bf2c8ff92bc7b82620bae0a27796f866ab Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Remove QVariant(int type, void *data, ...) constructorLars Knoll2020-08-151-16/+1
| | | | | | | | It was marked internal anyway. Use the constructor taking a QMetaType instead. Change-Id: I15b9cd0911aac063a0f0fe0352fa2c84b7f7c691 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QVariant: remove docs for non-existent deprecated methodsEdward Welbourne2020-08-141-40/+0
| | | | | | | | This follows up on commit 3898c022a647b1c742042e586963e193da546c1e which removed the code but not the methods themselves. Change-Id: Ia2311921365fdc5fee1104dd3162d6f26e5bb091 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Restrict QVariant::isNull() behaviorLars Knoll2020-08-131-32/+18
| | | | | | | | | | | | | | | | | | | | | isNull() would forward to the contained type and check that type's isNull() method for some of the builtin types. Remove that behavior and only return true in isNull(), if the variant is invalid, doesn't contain data or contains a null pointer. In addition, implement more consistent behavior when constructing a QVariant using the internal API taking a copy from a void *. isNull() should return true in both cases. This mainly changes behavior for some corner cases and when using our internal API. [ChangeLog][Important Behavior Changes] QVariant::isNull() no longer returns true when the variant contains an object of some type with an isNull() method, that returns true for the object; QVariant::isNull() now only returns true when the variant contains no object or a null pointer. Change-Id: I3125041c4f8f8618a04aa375aa0a56b19c02dcf5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Restrict comparison of variantsLars Knoll2020-08-131-38/+82
| | | | | | | | | | | | | | | | | | | | | Comparing two variants will not try to convert the types of the variant anymore. Exceptions are when both types are numeric types or one type is numeric and the other one a QString. The exceptions are there to keep compatibility with C++ and to not completely break QSettings (which needs automatic conversions from QString to numeric types). [ChangeLog][Important Behavior Changes] Comparing two variants in Qt 6 will not try attempt any type conversions before comparing the variants anymore. Instead variants of different type will not compare equal, with two exceptions: If both types are numeric types they will get compared according to C++ type promotion rules. If one type is a QString and the other type a numeric type, a conversion from the string to the numeric tpye will be attempted. Fixes: QTBUG-84636 Change-Id: I0cdd0b7259a525a41679fb6761f1e37e1d5b257f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use the new support for comparisons in QMetaType for QVariantLars Knoll2020-08-131-42/+9
| | | | | | | | | | | | | | Remove the compare method in the QVariant::Handler struct. Rely on the generic support provided by QMetaType instead. [ChangeLog][Important Behavior Changes][QVariant] QVariant will now use builtin support in QMetaType to compare its content. This implies a behavioral change for some graphical types like QPixmap, QImage and QIcon that will never compare equal in Qt 6 (as they do not have a comparison operator). Change-Id: I30a6e7116c89124d11ed9052537cecc23f78116e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Long Live QMap as a refcounted std::map!Giuseppe D'Angelo2020-08-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... and QMultiMap as std::multimap. Just use the implementation from the STL; we can't really claim that our code is much better than STL's, or does things any differently (de facto they're both red-black trees). Decouple QMultiMap from QMap, by making it NOT inherit from QMap any longer. This completes the deprecation started in 5.15: QMap now does not store duplicated keys any more. Something to establish is where to put the QExplictlySharedDataPointer replcement that is in there as an ad-hoc solution. There's a number of patches in-flight by Marc that try to introduce the same (or very similar) functionality. Miscellanea changes to the Q(Multi)Map code itself: * consistently use size_type instead of int; * pass iterators by value; * drop QT_STRICT_ITERATORS; * iterators implictly convert to const_iterators, and APIs take const_iterators; * iterators are just bidirectional and not random access; * added noexcept where it makes sense; * "inline" dropped (churn); * qMapLessThanKey dropped (undocumented, 0 hits in Qt, 1 hit in KDE); * operator== on Q(Multi)Map requires operator== on the key type (we're checking for equality, not equivalence!). Very few breakages occur in qtbase. [ChangeLog][Potentially Source-Incompatible Changes] QMap does not support multiple equivalent keys any more. Any related functionality has been removed from QMap, following the deprecation that happened in Qt 5.15. Use QMultiMap for this use case. [ChangeLog][Potentially Source-Incompatible Changes] QMap and QMultiMap iterators random-access API have been removed. Note that the iterators have always been just bidirectional; moving an iterator by N positions can still be achieved using std::next or std::advance, at the same cost as before (O(N)). [ChangeLog][Potentially Source-Incompatible Changes] QMultiMap does not inherit from QMap any more. Amongst other things, this means that iterators on a QMultiMap now belong to the QMultiMap class (and not to the QMap class); new Java iterators have been added. Change-Id: I5a0fe9b020f92c21b37065a1defff783b5d2b7a9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QVariant::setValue(): enable move semanticsGiuseppe D'Angelo2020-07-131-1/+13
| | | | | | | | | | | | Given we optimize for the case where the new value is of the same type of the one already stored in the variant, enable move assignment for that case. As a drive-by, avoid a path to detach() for data() if we know we're detached. Change-Id: I9abbdc10637ce77ebb747b49d83e1ef914d997bb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Automatically register comparison operators in QMetaTypeFabian Kosmale2020-07-081-22/+4
| | | | | | | | | | | | | | | | | This removes the fully manual registration of comparison operators in QMetaType and replaces it with an automatic registration through Q_DECLARE_METATYPE(). [ChangeLog][QMetaType] The QMetaType::registerComparator() and QMetaType::registerEqualsComparator() have been removed. Q_DECLARE_METATYPE() now automatically registers any operator==() and/or operator<() for a type visible where it is used on that type, as part of declaring its meta-type. Change-Id: I3df451b652b735c093533838bf32f3cc785439f8 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Port Q_STATIC_ASSERT(_X) to static_assertGiuseppe D'Angelo2020-06-191-1/+1
| | | | | | | | | | | | | | | | | There is no reason for keep using our macro now that we have C++17. The macro itself is left in for the moment being, as well as its detection logic, because it's needed for C code (not everything supports C11 yet). A few more cleanups will arrive in the next few patches. Note that this is a mere search/replace; some places were using double braces to work around the presence of commas in a macro, no attempt has been done to fix those. tst_qglobal had just some minor changes to keep testing the macro. Change-Id: I1c1c397d9f3e63db3338842bf350c9069ea57639 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove some dead codeLars Knoll2020-06-171-16/+0
| | | | | Change-Id: I4e3906d5e6313014b207aa7bc63a0ff5e21b0261 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Warn about constructing QMetaTypes/QVariants with invalid type idsLars Knoll2020-06-161-3/+0
| | | | | | | | | | | Warn about using an invalid type id in all cases. So far, only some constructors of QVariant would warn. Move the warning over to the place where we map a typeid to a QMetaTypeInterface to catch all cases. Change-Id: I4cd48a2b5d6c597dbf2afbeae9b811cd0819b768 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove unused argument from methodLars Knoll2020-06-061-31/+31
| | | | | | Task-number: QTBUG-84635 Change-Id: I9a1789e0481977e9fa26a915ff3bc776d0a37e75 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>