aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-06-22 09:43:05 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-08-24 10:13:39 +0200
commit1b7a098803a43355abf62e099267d4a122645e07 (patch)
treebd8f744e81250042d3e86c1c942be89e8e292f31 /src/qml
parentae36d94c2f385e272ae25fcd0fe780edb70cf7d9 (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')
-rw-r--r--src/qml/common/qv4compileddata_p.h4
-rw-r--r--src/qml/compiler/qqmlirbuilder.cpp2
-rw-r--r--src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc95
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp4
-rw-r--r--src/qml/qml/qqmlpropertycachecreator.cpp1
-rw-r--r--src/qml/qml/qqmlpropertycachecreator_p.h3
-rw-r--r--src/qml/qml/qqmlstringconverters.cpp16
-rw-r--r--src/qml/qml/qqmlstringconverters_p.h1
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp6
9 files changed, 4 insertions, 128 deletions
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h
index 8c4aa1b12e..d46fd58bc8 100644
--- a/src/qml/common/qv4compileddata_p.h
+++ b/src/qml/common/qv4compileddata_p.h
@@ -78,7 +78,7 @@ QT_BEGIN_NAMESPACE
// Also change the comment behind the number to describe the latest change. This has the added
// benefit that if another patch changes the version too, it will result in a merge conflict, and
// not get removed silently.
-#define QV4_DATA_STRUCTURE_VERSION 0x30// support additional required property features
+#define QV4_DATA_STRUCTURE_VERSION 0x31// removed builtin variant type
class QIODevice;
class QQmlTypeNameCache;
@@ -247,7 +247,7 @@ struct Block
static_assert(sizeof(Block) == 12, "Block structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
enum class BuiltinType : unsigned int {
- Var = 0, Variant, Int, Bool, Real, String, Url, Color,
+ Var = 0, Int, Bool, Real, String, Url, Color,
Font, Time, Date, DateTime, Rect, Point, Size,
Vector2D, Vector3D, Vector4D, Matrix4x4, Quaternion, InvalidBuiltin
};
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp
index 8ea97ab956..cadfda0cc3 100644
--- a/src/qml/compiler/qqmlirbuilder.cpp
+++ b/src/qml/compiler/qqmlirbuilder.cpp
@@ -154,7 +154,7 @@ QV4::CompiledData::BuiltinType Parameter::stringToBuiltinType(const QString &typ
{ "vector4d", strlen("vector4d"), QV4::CompiledData::BuiltinType::Vector4D },
{ "quaternion", strlen("quaternion"), QV4::CompiledData::BuiltinType::Quaternion },
{ "matrix4x4", strlen("matrix4x4"), QV4::CompiledData::BuiltinType::Matrix4x4 },
- { "variant", strlen("variant"), QV4::CompiledData::BuiltinType::Variant },
+ { "variant", strlen("variant"), QV4::CompiledData::BuiltinType::Var },
{ "var", strlen("var"), QV4::CompiledData::BuiltinType::Var }
};
static const int propTypeNameToTypesCount = sizeof(propTypeNameToTypes) /
diff --git a/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc b/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
index ae3337f838..5716f6c386 100644
--- a/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
+++ b/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
@@ -513,101 +513,6 @@ property is only invoked when the property is reassigned to a different object v
*/
/*!
- \obsolete
- \qmlbasictype variant
- \ingroup qmlbasictypes
- \brief a generic property type.
-
- The \c variant type is a generic property type. It is obsolete and exists only to
- support old applications; new applications should use \l var type
- properties instead.
-
- A variant type property can hold any of the \l {QML Basic Types}{basic type}
- values:
-
- \qml
- Item {
- property variant aNumber: 100
- property variant aString: "Hello world!"
- property variant aBool: false
- }
- \endqml
-
- When integrating with C++, note that any QVariant value
- \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
- converted into a \c variant value, and vice-versa.
-
-
- \section1 Using Scarce Resources with the variant Type
-
- A \c variant type property can also hold an image or pixmap.
- A \c variant which contains a QPixmap or QImage is known as a
- "scarce resource" and the declarative engine will attempt to
- automatically release such resources after evaluation of any JavaScript
- expression which requires one to be copied has completed.
-
- Clients may explicitly release such a scarce resource by calling the
- "destroy" method on the \c variant property from within JavaScript. They
- may also explicitly preserve the scarce resource by calling the
- "preserve" method on the \c variant property from within JavaScript.
-
- \section1 Storing Arrays and Objects
-
- The \c variant type can also hold:
-
- \list
- \li An array of \l {QML Basic Types}{basic type} values
- \li A map of key-value pairs with \l {QML Basic Types}{basic-type} values
- \endlist
-
- For example, below is an \c items array and an \c attributes map. Their
- contents can be examined using JavaScript \c for loops. Individual array
- values are accessible by index, and individual map values are accessible
- by key:
-
- \qml
- Item {
- property variant items: [1, 2, 3, "four", "five"]
- property variant attributes: { 'color': 'red', 'width': 100 }
-
- Component.onCompleted: {
- for (var i = 0; i < items.length; i++)
- console.log(items[i])
-
- for (var prop in attributes)
- console.log(prop, "=", attributes[prop])
- }
- }
- \endqml
-
- While this is a convenient way to store array and map-type values, you
- must be aware that the \c items and \c attributes properties above are \e not
- QML objects (and certainly not JavaScript object either) and the key-value
- pairs in \c attributes are \e not QML properties. Rather, the \c items
- property holds an array of values, and \c attributes holds a set of key-value
- pairs.
-
- Additionally, since \c items and \c attributes are not QML objects, changing
- the values they contain does not trigger property change notifications. If
- the above example had \c onItemsChanged or \c onAttributesChanged signal
- handlers, they would not be called when assigning individual entries in
- either property. If, however, the \c items or \c attributes properties
- themselves were reassigned to different values, then such handlers would be
- called.
-
- JavaScript programmers should also note that when a JavaScript object is
- copied to an array or map property, the \e contents of the object (that is,
- its key-value properties) are copied, rather than the object itself. The
- property does not hold a reference to the original JavaScript object, and
- extra data such as the object's JavaScript prototype chain is also lost in
- the process.
-
- This basic type is provided by the QML language.
-
- \sa {QML Basic Types}
-*/
-
-/*!
\qmlbasictype enumeration
\ingroup qmlbasictypes
\brief a named enumeration value.
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: