From 4591504267d4c0c0804592c812ed964ee783eceb Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 6 Jun 2013 15:59:41 +0200 Subject: [PATCH] Simplify QObjectWrapper calls from within other type wrappers ... with the help of a getQmlProperty static function. Change-Id: Ia823ba9ac995cb1a0591081bf18418f48d60e04d Reviewed-by: Lars Knoll --- src/qml/qml/qqmlcontextwrapper.cpp | 28 ++++++++++++---------------- src/qml/qml/qqmltypewrapper.cpp | 12 +++--------- src/qml/qml/qqmlvaluetypewrapper.cpp | 2 +- src/qml/qml/v8/qv8qobjectwrapper.cpp | 23 +++++++++++++++++++++++ src/qml/qml/v8/qv8qobjectwrapper_p.h | 1 + 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index dd7d28c..ddeaead 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()) { - 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()) { - 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 e98117e..b3b1ded 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()) - 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(); - 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 955ea04..ae3934f 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()->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 74cc998..128fd25 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(); + 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 d360bcb..5c423b7 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); -- 2.7.4