aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-06-06 15:59:41 +0200
committerLars Knoll <lars.knoll@digia.com>2013-06-07 18:33:05 +0200
commit4591504267d4c0c0804592c812ed964ee783eceb (patch)
treeeb3194655d35672e98048d469b3a55e29ec27028
parentd05425fb074370ffd3a699a160b468faa2779586 (diff)
Simplify QObjectWrapper calls from within other type wrappers
... with the help of a getQmlProperty static function. Change-Id: Ia823ba9ac995cb1a0591081bf18418f48d60e04d Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp28
-rw-r--r--src/qml/qml/qqmltypewrapper.cpp12
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp2
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper.cpp23
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper_p.h1
5 files changed, 40 insertions, 26 deletions
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index dd7d28ce66..ddeaead6a8 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -228,14 +228,12 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo
// Search scope object
if (scopeObject) {
- if (QV4::QObjectWrapper *o = QV4::QObjectWrapper::wrap(ctx->engine, scopeObject).as<QV4::QObjectWrapper>()) {
- bool hasProp = false;
- QV4::Value result = o->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::CheckRevision, &hasProp);
- if (hasProp) {
- if (hasProperty)
- *hasProperty = true;
- return result;
- }
+ bool hasProp = false;
+ QV4::Value result = QV4::QObjectWrapper::getQmlProperty(ctx, context, scopeObject, name, QV4::QObjectWrapper::CheckRevision, &hasProp);
+ if (hasProp) {
+ if (hasProperty)
+ *hasProperty = true;
+ return result;
}
}
scopeObject = 0;
@@ -243,14 +241,12 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo
// Search context object
if (context->contextObject) {
- if (QV4::QObjectWrapper *o = QV4::QObjectWrapper::wrap(ctx->engine, context->contextObject).as<QV4::QObjectWrapper>()) {
- bool hasProp = false;
- QV4::Value result = o->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::CheckRevision, &hasProp);
- if (hasProp) {
- if (hasProperty)
- *hasProperty = true;
- return result;
- }
+ bool hasProp = false;
+ QV4::Value result = QV4::QObjectWrapper::getQmlProperty(ctx, context, context->contextObject, name, QV4::QObjectWrapper::CheckRevision, &hasProp);
+ if (hasProp) {
+ if (hasProperty)
+ *hasProperty = true;
+ return result;
}
}
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp
index e98117e440..b3b1dedf07 100644
--- a/src/qml/qml/qqmltypewrapper.cpp
+++ b/src/qml/qml/qqmltypewrapper.cpp
@@ -158,10 +158,7 @@ Value QmlTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool
}
// check for property.
- if (QV4::QObjectWrapper *o = QV4::QObjectWrapper::wrap(ctx->engine, qobjectSingleton).as<QV4::QObjectWrapper>())
- return o->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::IgnoreRevision);
- else
- return QV4::Value::undefinedValue();
+ return QV4::QObjectWrapper::getQmlProperty(ctx, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision);
} else if (!siinfo->scriptApi(e).isUndefined()) {
QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine);
// NOTE: if used in a binding, changes will not trigger re-evaluation since non-NOTIFYable.
@@ -184,11 +181,8 @@ Value QmlTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool
} else if (w->object) {
QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object);
- if (ao) {
- QV4::QObjectWrapper *wrapper = QV4::QObjectWrapper::wrap(ctx->engine, ao).as<QV4::QObjectWrapper>();
- if (wrapper)
- return wrapper->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::IgnoreRevision);
- }
+ if (ao)
+ return QV4::QObjectWrapper::getQmlProperty(ctx, context, ao, name, QV4::QObjectWrapper::IgnoreRevision);
// Fall through to base implementation
}
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index 955ea04298..ae3934fff6 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -285,7 +285,7 @@ Value QmlValueTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name,
if (result->isFunction()) {
// calling a Q_INVOKABLE function of a value type
QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(ctx->engine);
- return QV4::QObjectWrapper::wrap(ctx->engine, r->type).as<QV4::QObjectWrapper>()->getQmlProperty(ctx, qmlContext, name, QV4::QObjectWrapper::IgnoreRevision);
+ return QV4::QObjectWrapper::getQmlProperty(ctx, qmlContext, r->type, name, QV4::QObjectWrapper::IgnoreRevision);
}
#define VALUE_TYPE_LOAD(metatype, cpptype, constructor) \
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp
index 74cc998326..128fd25d96 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp
@@ -412,6 +412,29 @@ Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextData *qml
}
}
+Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextData *qmlContext, QObject *object, String *name, QObjectWrapper::RevisionMode revisionMode, bool *hasProperty)
+{
+ if (QQmlData::wasDeleted(object)) {
+ if (hasProperty)
+ *hasProperty = false;
+ return QV4::Value::nullValue();
+ }
+
+ if (!QQmlData::get(object, true)) {
+ if (hasProperty)
+ *hasProperty = false;
+ return QV4::Value::nullValue();
+ }
+
+ QObjectWrapper *wrapper = wrap(ctx->engine, object).as<QV4::QObjectWrapper>();
+ if (!wrapper) {
+ if (hasProperty)
+ *hasProperty = false;
+ return QV4::Value::nullValue();
+ }
+ return wrapper->getQmlProperty(ctx, qmlContext, name, revisionMode, hasProperty);
+}
+
Value QObjectWrapper::wrap(ExecutionEngine *engine, QObject *object)
{
if (QQmlData::wasDeleted(object))
diff --git a/src/qml/qml/v8/qv8qobjectwrapper_p.h b/src/qml/qml/v8/qv8qobjectwrapper_p.h
index d360bcb367..5c423b71cc 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper_p.h
+++ b/src/qml/qml/v8/qv8qobjectwrapper_p.h
@@ -93,6 +93,7 @@ struct Q_QML_EXPORT QObjectWrapper : public QV4::Object
void deleteQObject(bool deleteInstantly = false);
Value getQmlProperty(ExecutionContext *ctx, QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, bool *hasProperty = 0, bool includeImports = false);
+ static Value getQmlProperty(ExecutionContext *ctx, QQmlContextData *qmlContext, QObject *object, String *name, RevisionMode revisionMode, bool *hasProperty = 0);
static Value wrap(ExecutionEngine *engine, QObject *object);