diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-06-26 18:02:35 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-11 01:46:52 +0200 |
commit | f5cb65b35e076facbce45e896902a34da7036135 (patch) | |
tree | 7575065fde2d0c14c379a992bf8b3593e21f4881 /src/qml/qml/v8/qv8valuetypewrapper.cpp | |
parent | 5376906de58e1c25c77b7a61800365b6e542542f (diff) |
Fix broken value-type support by allowing property definition
In QtQuick 1.x the "variant" property type was supported, which could
be used to allow value type properties to be defined in QML. In
QtQuick 2.0, we have deprecated the "variant" property, but its
replacement ("var") is not suited for defining lightweight C++ type
values (such as QColor, QFont, QRectF, QVector3D etc).
This commit allows those QML basic types to be used in QML once more,
by supporting them in the property definition syntax.
Note that since some value types are provided by QtQuick and others
are provided by QtQml, if a client imports only QtQml they can define
but not use properties of certain types (eg, font).
Task-number: QTBUG-21034
Task-number: QTBUG-18217
Change-Id: Ia951a8522f223408d27293bb96c276281a710277
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'src/qml/qml/v8/qv8valuetypewrapper.cpp')
-rw-r--r-- | src/qml/qml/v8/qv8valuetypewrapper.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/qml/qml/v8/qv8valuetypewrapper.cpp b/src/qml/qml/v8/qv8valuetypewrapper.cpp index cf2c13fce9..cdee5a4771 100644 --- a/src/qml/qml/v8/qv8valuetypewrapper.cpp +++ b/src/qml/qml/v8/qv8valuetypewrapper.cpp @@ -44,6 +44,7 @@ #include <private/qqmlvaluetype_p.h> #include <private/qqmlbinding_p.h> +#include <private/qqmlglobal_p.h> QT_BEGIN_NAMESPACE @@ -148,6 +149,14 @@ v8::Local<v8::Object> QV8ValueTypeWrapper::newValueType(const QVariant &value, Q return rv; } +QVariant QV8ValueTypeWrapper::toVariant(v8::Handle<v8::Object> obj, int typeHint, bool *succeeded) +{ + // NOTE: obj must not be an external resource object (ie, wrapper object) + // instead, it is a normal js object which one of the value-type providers + // may know how to convert to the given type. + return QQml_valueTypeProvider()->createVariantFromJsObject(typeHint, QQmlV8Handle::fromHandle(obj), m_engine, succeeded); +} + QVariant QV8ValueTypeWrapper::toVariant(v8::Handle<v8::Object> obj) { QV8ValueTypeResource *r = v8_resource_cast<QV8ValueTypeResource>(obj); |