summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-10-21 05:38:00 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-10-21 05:38:00 (GMT)
commitb49f57e4a2071f3b825d3e60b05c5914f16bd297 (patch)
tree8f72869900a9750dcf2f9040b9ded7811f9b9489 /src
parentc5a13f58a24487c1240e5592a5c40e5420a5cc35 (diff)
downloadQt-b49f57e4a2071f3b825d3e60b05c5914f16bd297.zip
Qt-b49f57e4a2071f3b825d3e60b05c5914f16bd297.tar.gz
Qt-b49f57e4a2071f3b825d3e60b05c5914f16bd297.tar.bz2
Tweak scoping
qmlContext() now returns the outer, not the inner context. The VME MetaObject now saves the context used to run function bodies
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qmlengine.cpp33
-rw-r--r--src/declarative/qml/qmlengine_p.h1
-rw-r--r--src/declarative/qml/qmlvmemetaobject.cpp3
-rw-r--r--src/declarative/qml/qmlvmemetaobject_p.h1
4 files changed, 28 insertions, 10 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 1d98265..7c0edf7 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -404,7 +404,12 @@ QmlContext *QmlEngine::contextForObject(const QObject *object)
QmlDeclarativeData *data =
static_cast<QmlDeclarativeData *>(priv->declarativeData);
- return data?data->context:0;
+ if (!data)
+ return 0;
+ else if (data->outerContext)
+ return data->outerContext;
+ else
+ return data->context;
}
/*!
@@ -568,6 +573,17 @@ QScriptValue QmlEnginePrivate::qmlScriptObject(QObject* object,
}
/*!
+ Returns the QmlContext for the executing QScript \a ctxt.
+*/
+QmlContext *QmlEnginePrivate::getContext(QScriptContext *ctxt)
+{
+ QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3);
+ Q_ASSERT(scopeNode.isValid());
+ Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass);
+ return contextClass->contextFromValue(scopeNode);
+}
+
+/*!
This function is intended for use inside QML only. In C++ just create a
component object as usual.
@@ -629,7 +645,7 @@ QScriptValue QmlEnginePrivate::createComponent(QScriptContext *ctxt,
static_cast<QmlScriptEngine*>(engine)->p;
QmlEngine* activeEngine = activeEnginePriv->q_func();
- QmlContext* context = activeEnginePriv->currentExpression->context();
+ QmlContext* context = activeEnginePriv->getContext(ctxt);
if(ctxt->argumentCount() != 1) {
c = new QmlComponentJS(activeEngine);
}else{
@@ -682,7 +698,12 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi
url = QUrl(ctxt->argument(2).toString());
QObject *parentArg = activeEnginePriv->objectClass->toQObject(ctxt->argument(1));
QmlContext *qmlCtxt = qmlContext(parentArg);
- url = qmlCtxt->resolvedUrl(url);
+ if (url.isEmpty()) {
+ url = qmlCtxt->resolvedUrl(QUrl(QLatin1String("<Unknown File>")));
+ } else {
+ url = qmlCtxt->resolvedUrl(url);
+ }
+
QmlComponent component(activeEngine, qml.toUtf8(), url);
if(component.isError()) {
QList<QmlError> errors = component.errors();
@@ -848,11 +869,7 @@ QScriptValue QmlEnginePrivate::playSound(QScriptContext *ctxt, QScriptEngine *en
QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(engine);
if (url.isRelative()) {
- QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3);
- Q_ASSERT(scopeNode.isValid());
- Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == enginePriv->contextClass);
-
- QmlContext *context = enginePriv->contextClass->contextFromValue(scopeNode);
+ QmlContext *context = enginePriv->getContext(ctxt);
if (!context)
return engine->undefinedValue();
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 07ac928..a74854d 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -265,6 +265,7 @@ public:
static QmlEngine *getEngine(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p->q_func(); }
static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); }
static QmlEnginePrivate *get(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p; }
+ QmlContext *getContext(QScriptContext *);
};
diff --git a/src/declarative/qml/qmlvmemetaobject.cpp b/src/declarative/qml/qmlvmemetaobject.cpp
index e5acc51..62a2a6b 100644
--- a/src/declarative/qml/qmlvmemetaobject.cpp
+++ b/src/declarative/qml/qmlvmemetaobject.cpp
@@ -55,7 +55,7 @@ QmlVMEMetaObject::QmlVMEMetaObject(QObject *obj,
const QMetaObject *other,
const QmlVMEMetaData *meta,
QmlRefCount *rc)
-: object(obj), ref(rc), metaData(meta), parent(0)
+: object(obj), ref(rc), ctxt(qmlContext(obj)), metaData(meta), parent(0)
{
if (ref)
ref->addref();
@@ -251,7 +251,6 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
(const QChar *)(((const char*)metaData) + data->bodyOffset);
QString code = QString::fromRawData(body, data->bodyLength);
- QmlContext *ctxt = qmlContext(object);
if (0 == (metaData->methodData() + id)->parameterCount) {
QmlExpression expr(ctxt, code, object);
diff --git a/src/declarative/qml/qmlvmemetaobject_p.h b/src/declarative/qml/qmlvmemetaobject_p.h
index d376f4c..de46853 100644
--- a/src/declarative/qml/qmlvmemetaobject_p.h
+++ b/src/declarative/qml/qmlvmemetaobject_p.h
@@ -112,6 +112,7 @@ protected:
private:
QObject *object;
QmlRefCount *ref;
+ QGuard<QmlContext> ctxt;
const QmlVMEMetaData *metaData;
int propOffset;