diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-06-22 09:43:05 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-08-24 10:13:39 +0200 |
commit | 1b7a098803a43355abf62e099267d4a122645e07 (patch) | |
tree | bd8f744e81250042d3e86c1c942be89e8e292f31 /src/qml/qml | |
parent | ae36d94c2f385e272ae25fcd0fe780edb70cf7d9 (diff) |
Unify "variant" and "var" properties in QML
variant and var properties differ in two important ways:
- variant properties trigger "magic" string conversions:
variant v1: "red" // contains a QColor
var v2: "red" // contains a string
- variant properties behave differently for value types: they create
copies, instead of references.
However, as variant properties were marked as obsolete and this
behavior was effetively undocumented, it should be safe to give "variant"
"var semantics".
With this change, we can also avoid doing magic conversions when storing
data in QVariant properties of QObjects/QGadgets
Change-Id: I549b1beb98e6af9639c1ee81f316bda513d5ff65
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertycachecreator.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertycachecreator_p.h | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlstringconverters.cpp | 16 | ||||
-rw-r--r-- | src/qml/qml/qqmlstringconverters_p.h | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlvmemetaobject.cpp | 6 |
6 files changed, 1 insertions, 30 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 11d3dd7b5d..5eb885c2e0 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -423,9 +423,7 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const QV4::ScopedString s(scope, v4->newString(stringValue)); _vmeMetaObject->setVMEProperty(property->coreIndex(), s); } else { - // ### Qt 6: Doing the conversion here where we don't know the eventual target type is rather strange - // and caused for instance QTBUG-78943 - QVariant value = QQmlStringConverters::variantFromString(stringValue); + QVariant value = stringValue; property->writeProperty(_qobject, &value, propertyWriteFlags); } } diff --git a/src/qml/qml/qqmlpropertycachecreator.cpp b/src/qml/qml/qqmlpropertycachecreator.cpp index 777a698231..144d7e59b4 100644 --- a/src/qml/qml/qqmlpropertycachecreator.cpp +++ b/src/qml/qml/qqmlpropertycachecreator.cpp @@ -50,7 +50,6 @@ int QQmlPropertyCacheCreatorBase::metaTypeForPropertyType(QV4::CompiledData::Bui { switch (type) { case QV4::CompiledData::BuiltinType::Var: return QMetaType::QVariant; - case QV4::CompiledData::BuiltinType::Variant: return QMetaType::QVariant; case QV4::CompiledData::BuiltinType::Int: return QMetaType::Int; case QV4::CompiledData::BuiltinType::Bool: return QMetaType::Bool; case QV4::CompiledData::BuiltinType::Real: return QMetaType::Double; diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index b98ebebed3..5c9e806a4e 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -544,9 +544,6 @@ inline QQmlError QQmlPropertyCacheCreator<ObjectContainer>::createMetaObject(int if (type != QV4::CompiledData::BuiltinType::InvalidBuiltin) { propertyType = metaTypeForPropertyType(type); - - if (type == QV4::CompiledData::BuiltinType::Variant) - propertyFlags.type = QQmlPropertyData::Flags::QVariantType; } else { Q_ASSERT(!p->isBuiltinType); diff --git a/src/qml/qml/qqmlstringconverters.cpp b/src/qml/qml/qqmlstringconverters.cpp index ba52519eb0..bf291f0549 100644 --- a/src/qml/qml/qqmlstringconverters.cpp +++ b/src/qml/qml/qqmlstringconverters.cpp @@ -48,22 +48,6 @@ QT_BEGIN_NAMESPACE -QVariant QQmlStringConverters::variantFromString(const QString &s) -{ - if (s.isEmpty()) - return QVariant(s); - - bool ok = false; - QRectF r = rectFFromString(s, &ok); - if (ok) return QVariant(r); - QPointF p = pointFFromString(s, &ok); - if (ok) return QVariant(p); - QSizeF sz = sizeFFromString(s, &ok); - if (ok) return QVariant(sz); - - return QQml_valueTypeProvider()->createVariantFromString(s); -} - QVariant QQmlStringConverters::variantFromString(const QString &s, int preferredType, bool *ok) { switch (preferredType) { diff --git a/src/qml/qml/qqmlstringconverters_p.h b/src/qml/qml/qqmlstringconverters_p.h index 215f0c0aaf..d64eb714fd 100644 --- a/src/qml/qml/qqmlstringconverters_p.h +++ b/src/qml/qml/qqmlstringconverters_p.h @@ -66,7 +66,6 @@ class QByteArray; namespace QQmlStringConverters { - Q_QML_PRIVATE_EXPORT QVariant variantFromString(const QString &); Q_QML_PRIVATE_EXPORT QVariant variantFromString(const QString &, int preferredType, bool *ok = nullptr); Q_QML_PRIVATE_EXPORT QVariant colorFromString(const QString &, bool *ok = nullptr); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index fbfc387cc6..b946027b8d 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -734,9 +734,6 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * case QV4::CompiledData::BuiltinType::Point: *reinterpret_cast<QPointF *>(a[0]) = readPropertyAsPointF(id); break; - case QV4::CompiledData::BuiltinType::Variant: - *reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id); - break; case QV4::CompiledData::BuiltinType::Font: case QV4::CompiledData::BuiltinType::Time: case QV4::CompiledData::BuiltinType::Color: @@ -842,9 +839,6 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * needActivate = *reinterpret_cast<QPointF *>(a[0]) != readPropertyAsPointF(id); writeProperty(id, *reinterpret_cast<QPointF *>(a[0])); break; - case QV4::CompiledData::BuiltinType::Variant: - writeProperty(id, *reinterpret_cast<QVariant *>(a[0])); - break; case QV4::CompiledData::BuiltinType::Font: case QV4::CompiledData::BuiltinType::Time: case QV4::CompiledData::BuiltinType::Color: |