From 146b942d59cca446516652d42718197573d34e46 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 9 Sep 2011 11:12:06 +1000 Subject: [PATCH] Improve efficiency of qmlEngine() Also document qmlEngine() and qmlContext() Change-Id: I83eb092490160eee72d87473befdcea1492ded13 Reviewed-on: http://codereview.qt-project.org/4491 Reviewed-by: Qt Sanity Bot Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativeengine.cpp | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 789c9ed..9c7c0ab 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -948,8 +948,10 @@ QDeclarativeContext *qmlContext(const QObject *obj) QDeclarativeEngine *qmlEngine(const QObject *obj) { - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(obj); - return context?context->engine():0; + QDeclarativeData *data = QDeclarativeData::get(obj, false); + if (!data || !data->context) + return 0; + return data->context->engine; } QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool create) @@ -1681,4 +1683,20 @@ bool QDeclarative_isFileCaseCorrect(const QString &fileName) return true; } +/*! + \fn QDeclarativeEngine *qmlEngine(const QObject *object) + \relates QDeclarativeEngine + + Returns the QDeclarativeEngine associated with \a object, if any. This is equivalent to + QDeclarativeEngine::contextForObject(object)->engine(), but more efficient. +*/ + +/*! + \fn QDeclarativeContext *qmlContext(const QObject *object) + \relates QDeclarativeEngine + + Returns the QDeclarativeContext associated with \a object, if any. This is equivalent to + QDeclarativeEngine::contextForObject(object). +*/ + QT_END_NAMESPACE -- 1.7.2.5