summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Document QVariant::data/constDataVolker Hilsheimer2020-10-261-2/+12
| | | | | | | | | QMetaSequence refers to those members, and QMetaType operates on void*s, and documents such low-level APIs as well, so can't think of a reason why we should not document the QVariant getters as well. Change-Id: Id18de839bb0e4f5559b28bfca80eaabab1eb6479 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Whitespace cleanup in corelib/kernelAllan Sandfeld Jensen2020-10-241-13/+10
| | | | | Change-Id: If061ef0af5ced4384e20a82afcea3712fa7e45d7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix documentation for QVariantRef and QVariantPointerVolker Hilsheimer2020-10-231-10/+10
| | | | | Change-Id: I86b749ec14876df98d5d873cf2274facea49f0c5 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Deprecate QVariant::TypeLars Knoll2020-10-231-66/+58
| | | | | | | | | It's been obsolete for a long time already. Make sure the compiler now warns about it and remove all remaining uses in qtbase. Change-Id: I0ff80311184dba52d2ba5f4e2fabe0d47fdc59d7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Do not store non relocatable types in QVariants internal storageLars Knoll2020-10-231-1/+1
| | | | | | | | | | | This mostly reverts change 76e8e8e9c8093f093cb9f37d61d273f43398fefb. The reason is that storing non relocatable types inline in QVariants storage would implicitly make QVariant non relocatable. Fixes: QTBUG-87686 Change-Id: I2a09b1dcdd907d60085dccf17f987086dcba878c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix documentation for hidden friend operatorsVolker Hilsheimer2020-10-231-34/+11
| | | | | | | | At least for qdoc, hidden friends are class members. Change-Id: I6eaa21565937cd49c0905ee47b8b82b0c1765bc1 Reviewed-by: Topi Reiniö <topi.reinio@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* QMetaContainer: Consistently coerce typesUlf Hermann2020-10-191-0/+32
| | | | | | | | | | | | | | | The high-level iterable interfaces should coerce the types of most QVariants passed to the expected ones. To do this, move the type coercion code into qvariant.{h|cpp} so that it is available to the QVariantRef specializations. The exception are variants passed to the find() functions of associative iterables. Here, we should not coerce values we cannot convert to the default-constructed keys. Instead we return end() in such cases. Fixes: QTBUG-87687 Change-Id: I0bd4e5c4e4e270dd3bf36cb3fb115794828077f2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix "variable set but unused" in qvariant.cppUlf Hermann2020-10-161-1/+1
| | | | | | | ... how did that pass the CI? Change-Id: I84baaf3632df0410d1fb25f24fd22f65daae13af Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant::compare: handle numerical values and pointers as documentedv6.0.0-beta1Fabian Kosmale2020-10-151-9/+80
| | | | | | | | [ChangeLog][QtCore][QVariant] Comparing two QVariants containing floating point numbers for equality no longer uses fuzzy comparisons. Change-Id: Iaba40a66d8fa566a432547fa1a30d5ea191c7fc0 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* qDebug: Avoid implicit QVariant conversionFabian Kosmale2020-10-131-6/+6
| | | | | | | | | | | | | | | | | | | | | | | This commit restricts operator<<(QDebug lhs, QVariant rhs) to only work if rhs is actually of type QVariant (instead of any type convertible to QVariant). This is especially important as a) we check in QMetaType whether (slightly simplified) QDebug{} << std::declval<T>() is valid, and if so, register a function which simply uses the operator. b) In QVariant, we ask the metatype system for the contained types registered debug function and then use it. If a type now does not have its own operator<< for QDebug, but is implicitly convertible to QVariant containing itself, this would lead to an infinite recursion, when trying to use qDebug with that type. The registered function in a) would just convert the type to QVariant, and then ask the QVariant to print itself. Disallowing implicit conversions in qDebug in general was considered (i.e. adding template<typename T> operator<<(T) = delete in QDebug ), but discarded as it breaks too much code relying on conversions. Fixes: QTBUG-87122 Change-Id: Ib709297670cbc6cc307efd0dfd8e5b0279df9414 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add a QVariant::compare() methodLars Knoll2020-10-011-0/+27
| | | | | | | | | Add a method that allows comparing two variants. The method returns a std::optional, as comparing two variants of different type is not meaningful, or the types could not be comparable. Change-Id: If4ae838d671e051dda1b474f25a2f9dcf85dc265 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVariant: Change metatype in convert() even on failureFabian Kosmale2020-09-301-1/+1
| | | | | | | | | | | | | | The documentation of convert promised that “If the cast cannot be done, the variant is still changed to the requested type”. This was not the case so far, because we returned too early if canConvert returned false. This commit changes the behavior of the method to reflect its documentation. The documented behavior seems more useful than the alternative of not changing the metaType, at least for common use cases inside qtdeclarative. Change-Id: I09b5a5efb7344e76e93de278e35c7fb2b2f87dcd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix some qdoc warnings in QMetaType and QVariantVolker Hilsheimer2020-09-241-30/+18
| | | | | | | | Document new enum values, remove documentation for implicit members, fix parameters, and tie documentation to function definitions. Change-Id: I5f32d45be8709e5f614d099ddf21252e23e144f8 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Fix qdoc warning: use correct parameter type in QVariant c'torVolker Hilsheimer2020-09-231-2/+2
| | | | | Change-Id: Ic935c8ac22c6ac8955439353c9d36dd7ba46021c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix various qdoc warningsVolker Hilsheimer2020-09-221-4/+4
| | | | | | | Parameter types and names, missing enum values, and \since 6.0. Change-Id: I1b028fcf2ef0b57accb1ef7cebf17dab9f6d571e Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Fix some qdoc warnings: typos and qdoc syntaxVolker Hilsheimer2020-09-221-3/+3
| | | | | Change-Id: Idf5c1490330e0f2e5d4bcf920eb03fc9993b3c8a Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Fix a bug when streaming QVariants containing a QRegExpLars Knoll2020-09-211-4/+3
| | | | | | | | | | Fix a logic error. QRegExp is a UserType in Qt 6 and we need to check for it in the right place. Fixes an autotest failure in the qregexp autotest in qt5compat. Change-Id: I454cfcfd12b36f756b24b69a5412455db9dccbe7 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
* QMetaType: Allow registration of mutable views and register iterablesUlf Hermann2020-09-191-0/+27
| | | | | | | | | | | | | | | In order to modify a container through an iterable, we need the original container to be mutable. The iterable, then, is not a conversion of the container, but rather a view on the container. The concept may be extended to other types. In order to facilitate this, provide a set of methods in QMetaType and QVariant similar to the convert family. The new methods are non-const and expect the original value to stay available during the life time of the view. Change-Id: I363621033f7fc600edcea2acb786820ccba49c86 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Extend QSequentialIterable and add QAssociativeIterableUlf Hermann2020-09-191-342/+13
| | | | | | | | | And add mutable iterators. This requires some refactoring of the existing iterators. Task-number: QTBUG-81716 Change-Id: I61b3a3e8c0df5fd449679257a29d9f0c3d19c4f0 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Add QVariantRef, QVariantPointer, QVariantConstPointerUlf Hermann2020-09-141-0/+109
| | | | | Change-Id: Ia329265826ab2f76e77ac14bb8d8e415a1b41dd6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* 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>