aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2014-11-20 10:42:34 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2015-01-02 15:06:46 +0100
commit2b5fb185627f8adfb6c5b3d62990a58429bf4ea7 (patch)
tree63ae9357fbcb652b48b01a8a6de2da026fb93f40 /src/qml/jsapi
parent9a2701c1c3c7c805335fb2c1a1dfd1e712e4db6b (diff)
Enable gadget wrapping for custom value types
[ChangeLog][QtQml] Custom C++ value types annotated with Q_GADGET are now fully accessible in the QML and QJSEngine JavaScript environment. QJSEngine::toScriptValue can be used for injection and fromScriptValue to extraction. The QML "built-in" gadget wrappers for QPoint and the gui types are not exposed this way, toScriptValue(point) will still return an opaque QVariant wrapper. We could expose the core types right away, but then we would be lacking an API to enable use of the Gui types that are registered in QtQuick. It would be better to make the core types in qtbase gadgets and thus enable them without the need for hooks and init functions to be called by the user. Task-number: QTBUG-29769 Change-Id: I8179cd599bdc1209ff61cfdbdda419cb400296bb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r--src/qml/jsapi/qjsengine.cpp7
-rw-r--r--src/qml/jsapi/qjsengine_p.h5
2 files changed, 11 insertions, 1 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index 09891019c5..8525aedb6c 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -530,7 +530,7 @@ bool QJSEngine::convertV2(const QJSValue &value, int type, void *ptr)
Creates a QJSValue with the given \a value.
- \sa fromScriptValue()
+ \sa fromScriptValue(), newVariant()
*/
/*! \fn T QJSEngine::fromScriptValue(const QJSValue &value)
@@ -541,6 +541,11 @@ bool QJSEngine::convertV2(const QJSValue &value, int type, void *ptr)
*/
+QJSEnginePrivate *QJSEnginePrivate::get(QV4::ExecutionEngine *e)
+{
+ return e->v8Engine->publicEngine()->d_func();
+}
+
QJSEnginePrivate::~QJSEnginePrivate()
{
for (QHash<const QMetaObject *, QQmlPropertyCache *>::Iterator iter = propertyCache.begin(); iter != propertyCache.end(); ++iter)
diff --git a/src/qml/jsapi/qjsengine_p.h b/src/qml/jsapi/qjsengine_p.h
index eba8ffb4be..3f7e91bffe 100644
--- a/src/qml/jsapi/qjsengine_p.h
+++ b/src/qml/jsapi/qjsengine_p.h
@@ -54,6 +54,10 @@ QT_BEGIN_NAMESPACE
class QQmlPropertyCache;
+namespace QV4 {
+struct ExecutionEngine;
+}
+
class QJSEnginePrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QJSEngine)
@@ -61,6 +65,7 @@ class QJSEnginePrivate : public QObjectPrivate
public:
static QJSEnginePrivate* get(QJSEngine*e) { return e->d_func(); }
static const QJSEnginePrivate* get(const QJSEngine*e) { return e->d_func(); }
+ static QJSEnginePrivate* get(QV4::ExecutionEngine *e);
QJSEnginePrivate() : mutex(QMutex::Recursive) {}
~QJSEnginePrivate();