From: Aaron Kennedy Date: Fri, 9 Sep 2011 01:12:06 +0000 (+1000) Subject: Improve efficiency of qmlEngine() X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=146b942d59cca446516652d42718197573d34e46;p=konrad%2Fqtdeclarative.git 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 --- 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